Skip to content

Commit b10bca0

Browse files
wildea01Russell King
authored andcommitted
ARM: 7595/1: syscall: rework ordering in syscall_trace_exit
syscall_trace_exit is currently doing things back-to-front; invoking the audit hook *after* signalling the debugger, which presents an opportunity for the registers to be re-written by userspace in order to bypass auditing constaints. This patch fixes the ordering by moving the audit code first and the tracehook code last. On the face of it, it looks like current_thread_info()->syscall may be incorrect for the sys_exit tracepoint, but that's actually not an issue because it will have been set during syscall entry and cannot have changed since then. Reported-by: Andrew Gabbasov <Andrew_Gabbasov@mentor.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 39b175a commit b10bca0

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎arch/arm/kernel/entry-common.S‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ __sys_trace:
455455

456456
__sys_trace_return:
457457
str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
458-
mov r1, scno
459458
mov r0, sp
460459
bl syscall_trace_exit
461460
b ret_slow_syscall

‎arch/arm/kernel/ptrace.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -957,17 +957,23 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
957957
return scno;
958958
}
959959

960-
asmlinkage int syscall_trace_exit(struct pt_regs *regs, int scno)
960+
asmlinkage void syscall_trace_exit(struct pt_regs *regs)
961961
{
962-
current_thread_info()->syscall = scno;
963-
964-
if (test_thread_flag(TIF_SYSCALL_TRACE))
965-
scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
962+
/*
963+
* Audit the syscall before anything else, as a debugger may
964+
* come in and change the current registers.
965+
*/
966+
audit_syscall_exit(regs);
966967

968+
/*
969+
* Note that we haven't updated the ->syscall field for the
970+
* current thread. This isn't a problem because it will have
971+
* been set on syscall entry and there hasn't been an opportunity
972+
* for a PTRACE_SET_SYSCALL since then.
973+
*/
967974
if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
968-
trace_sys_exit(regs, scno);
969-
970-
audit_syscall_exit(regs);
975+
trace_sys_exit(regs, regs_return_value(regs));
971976

972-
return scno;
977+
if (test_thread_flag(TIF_SYSCALL_TRACE))
978+
tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
973979
}

0 commit comments

Comments
 (0)