Here it is not obvious why we load pt_regs->cx to %esi etc.
Lets improve comments.
Explain that here we combine two things: first, we reload registers
since some of them are clobbered by the C function we just called;
and we also convert 32-bit syscall params to 64-bit C ABI,
because we are going to jump back to syscall dispatch code.
Move reloading of 6th argument into the macro instead of having it
after each of two macro invocations.
No actual code changes here.
Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[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]
CC: [email protected]
---
arch/x86/entry/entry_64_compat.S | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 744a3f7..411407a 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -185,12 +185,18 @@ sysexit_from_sys_call:
movl %ebx, %esi /* 2nd arg: 1st syscall arg */
movl %eax, %edi /* 1st arg: syscall number */
call __audit_syscall_entry
- movl ORIG_RAX(%rsp), %eax /* reload syscall number */
- movl %ebx, %edi /* reload 1st syscall arg */
- movl RCX(%rsp), %esi /* reload 2nd syscall arg */
- movl RDX(%rsp), %edx /* reload 3rd syscall arg */
- movl RSI(%rsp), %ecx /* reload 4th syscall arg */
- movl RDI(%rsp), %r8d /* reload 5th syscall arg */
+ /*
+ * We are going to jump back to syscall dispatch.
+ * Prepare syscall args as required by 64-bit C ABI.
+ * Clobbered registers are loaded from pt_regs on stack.
+ */
+ movl ORIG_RAX(%rsp), %eax /* syscall number */
+ movl %ebx, %edi /* arg1 */
+ movl RCX(%rsp), %esi /* arg2 */
+ movl RDX(%rsp), %edx /* arg3 */
+ movl RSI(%rsp), %ecx /* arg4 */
+ movl RDI(%rsp), %r8d /* arg5 */
+ movl %ebp, %r9d /* arg6 */
.endm
.macro auditsys_exit exit
@@ -221,7 +227,6 @@ sysexit_from_sys_call:
sysenter_auditsys:
auditsys_entry_common
- movl %ebp, %r9d /* reload 6th syscall arg */
jmp sysenter_dispatch
sysexit_audit:
@@ -379,7 +384,6 @@ sysretl_from_sys_call:
#ifdef CONFIG_AUDITSYSCALL
cstar_auditsys:
auditsys_entry_common
- movl %ebp, %r9d /* reload 6th syscall arg */
jmp cstar_dispatch
sysretl_audit:
--
1.8.1.4
We use three MOVs to swap edx and ecx. We can use one XCHG instead.
Expand the comments. It's difficult to keep track which arg# every register
corresponds to, so spell it out.
Signed-off-by: Denys Vlasenko <[email protected]>
CC: Linus Torvalds <[email protected]>
CC: Steven Rostedt <[email protected]>
CC: Ingo Molnar <[email protected]>
CC: Borislav Petkov <[email protected]>
CC: "H. Peter Anvin" <[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]
CC: [email protected]
---
arch/x86/entry/entry_64_compat.S | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 411407a..d0b6494 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -178,12 +178,16 @@ sysexit_from_sys_call:
#ifdef CONFIG_AUDITSYSCALL
.macro auditsys_entry_common
- movl %esi, %r8d /* 5th arg: 4th syscall arg */
- movl %ecx, %r9d /* swap with edx */
- movl %edx, %ecx /* 4th arg: 3rd syscall arg */
- movl %r9d, %edx /* 3rd arg: 2nd syscall arg */
- movl %ebx, %esi /* 2nd arg: 1st syscall arg */
- movl %eax, %edi /* 1st arg: syscall number */
+ /*
+ * At this point, registers hold syscall args in 32-bit ABI:
+ * eax is syscall#, args are in ebx,ecx,edx,esi,edi,ebp.
+ * Shuffle them to match what __audit_syscall_entry() wants.
+ */
+ movl %esi, %r8d /* arg5 (r8): 4th syscall arg */
+ xchg %ecx, %edx /* arg4 (rcx): 3rd syscall arg (edx) */
+ /* arg3 (rdx): 2nd syscall arg (ecx) */
+ movl %ebx, %esi /* arg2 (rsi): 1st syscall arg */
+ movl %eax, %edi /* arg1 (rdi): syscall number */
call __audit_syscall_entry
/*
* We are going to jump back to syscall dispatch.
--
1.8.1.4