Skip to content

Commit 93e35ef

Browse files
committed
x86/ptrace: run seccomp after ptrace
This moves seccomp after ptrace on x86 to that seccomp can catch changes made by ptrace. Emulation should skip the rest of processing too. We can get rid of test_thread_flag because there's no longer any opportunity for seccomp to mess with ptrace state before invoking ptrace. Suggested-by: Andy Lutomirski <[email protected]> Signed-off-by: Kees Cook <[email protected]> Cc: [email protected] Cc: Andy Lutomirski <[email protected]>
1 parent ce6526e commit 93e35ef

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

arch/x86/entry/common.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,27 @@ static long syscall_trace_enter(struct pt_regs *regs)
7373

7474
struct thread_info *ti = pt_regs_to_thread_info(regs);
7575
unsigned long ret = 0;
76+
bool emulated = false;
7677
u32 work;
7778

7879
if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
7980
BUG_ON(regs != task_pt_regs(current));
8081

8182
work = ACCESS_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY;
8283

84+
if (unlikely(work & _TIF_SYSCALL_EMU))
85+
emulated = true;
86+
87+
if ((emulated || (work & _TIF_SYSCALL_TRACE)) &&
88+
tracehook_report_syscall_entry(regs))
89+
return -1L;
90+
91+
if (emulated)
92+
return -1L;
93+
8394
#ifdef CONFIG_SECCOMP
8495
/*
85-
* Do seccomp first -- it should minimize exposure of other
86-
* code, and keeping seccomp fast is probably more valuable
87-
* than the rest of this.
96+
* Do seccomp after ptrace, to catch any tracer changes.
8897
*/
8998
if (work & _TIF_SECCOMP) {
9099
struct seccomp_data sd;
@@ -117,13 +126,6 @@ static long syscall_trace_enter(struct pt_regs *regs)
117126
}
118127
#endif
119128

120-
if (unlikely(work & _TIF_SYSCALL_EMU))
121-
ret = -1L;
122-
123-
if ((ret || test_thread_flag(TIF_SYSCALL_TRACE)) &&
124-
tracehook_report_syscall_entry(regs))
125-
ret = -1L;
126-
127129
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
128130
trace_sys_enter(regs, regs->orig_ax);
129131

0 commit comments

Comments
 (0)