Skip to content

Commit c0c3322

Browse files
dvlasenkKAGA-KOKO
authored andcommitted
x86/asm/entry/32: Revert 'Do not use R9 in SYSCALL32' commit
This change reverts most of commit 53e9acc 'Do not use R9 in SYSCALL32'. I don't yet understand how, but code in that commit sometimes fails to preserve EBP. See https://bugzilla.kernel.org/show_bug.cgi?id=101061 "Problems while executing 32-bit code on AMD64" Reported-and-tested-by: Krzysztof A. Sobiecki <[email protected]> Signed-off-by: Denys Vlasenko <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Will Drewry <[email protected]> Cc: Kees Cook <[email protected]> CC: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 8a0a5da commit c0c3322

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

arch/x86/entry/entry_64_compat.S

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ sysexit_from_sys_call:
205205
movl RDX(%rsp), %edx /* arg3 */
206206
movl RSI(%rsp), %ecx /* arg4 */
207207
movl RDI(%rsp), %r8d /* arg5 */
208-
movl %ebp, %r9d /* arg6 */
209208
.endm
210209

211210
.macro auditsys_exit exit
@@ -236,6 +235,7 @@ sysexit_from_sys_call:
236235

237236
sysenter_auditsys:
238237
auditsys_entry_common
238+
movl %ebp, %r9d /* reload 6th syscall arg */
239239
jmp sysenter_dispatch
240240

241241
sysexit_audit:
@@ -336,7 +336,7 @@ ENTRY(entry_SYSCALL_compat)
336336
* 32-bit zero extended:
337337
*/
338338
ASM_STAC
339-
1: movl (%r8), %ebp
339+
1: movl (%r8), %r9d
340340
_ASM_EXTABLE(1b, ia32_badarg)
341341
ASM_CLAC
342342
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -346,7 +346,7 @@ ENTRY(entry_SYSCALL_compat)
346346
cstar_do_call:
347347
/* 32-bit syscall -> 64-bit C ABI argument conversion */
348348
movl %edi, %r8d /* arg5 */
349-
movl %ebp, %r9d /* arg6 */
349+
/* r9 already loaded */ /* arg6 */
350350
xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */
351351
movl %ebx, %edi /* arg1 */
352352
movl %edx, %edx /* arg3 (zero extension) */
@@ -358,7 +358,6 @@ cstar_dispatch:
358358
call *ia32_sys_call_table(, %rax, 8)
359359
movq %rax, RAX(%rsp)
360360
1:
361-
movl RCX(%rsp), %ebp
362361
DISABLE_INTERRUPTS(CLBR_NONE)
363362
TRACE_IRQS_OFF
364363
testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
@@ -392,7 +391,9 @@ sysretl_from_sys_call:
392391

393392
#ifdef CONFIG_AUDITSYSCALL
394393
cstar_auditsys:
394+
movl %r9d, R9(%rsp) /* register to be clobbered by call */
395395
auditsys_entry_common
396+
movl R9(%rsp), %r9d /* reload 6th syscall arg */
396397
jmp cstar_dispatch
397398

398399
sysretl_audit:
@@ -404,14 +405,16 @@ cstar_tracesys:
404405
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
405406
jz cstar_auditsys
406407
#endif
408+
xchgl %r9d, %ebp
407409
SAVE_EXTRA_REGS
408410
xorl %eax, %eax /* Do not leak kernel information */
409411
movq %rax, R11(%rsp)
410412
movq %rax, R10(%rsp)
411-
movq %rax, R9(%rsp)
413+
movq %r9, R9(%rsp)
412414
movq %rax, R8(%rsp)
413415
movq %rsp, %rdi /* &pt_regs -> arg1 */
414416
call syscall_trace_enter
417+
movl R9(%rsp), %r9d
415418

416419
/* Reload arg registers from stack. (see sysenter_tracesys) */
417420
movl RCX(%rsp), %ecx
@@ -421,6 +424,7 @@ cstar_tracesys:
421424
movl %eax, %eax /* zero extension */
422425

423426
RESTORE_EXTRA_REGS
427+
xchgl %ebp, %r9d
424428
jmp cstar_do_call
425429
END(entry_SYSCALL_compat)
426430

0 commit comments

Comments
 (0)