Commit 93e35efb authored by Kees Cook's avatar Kees Cook

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
Suggested-by: default avatarAndy Lutomirski <>
Signed-off-by: default avatarKees Cook <>
Cc: Andy Lutomirski <>
parent ce6526e8
......@@ -73,6 +73,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
struct thread_info *ti = pt_regs_to_thread_info(regs);
unsigned long ret = 0;
bool emulated = false;
u32 work;
......@@ -80,11 +81,19 @@ static long syscall_trace_enter(struct pt_regs *regs)
if (unlikely(work & _TIF_SYSCALL_EMU))
emulated = true;
if ((emulated || (work & _TIF_SYSCALL_TRACE)) &&
return -1L;
if (emulated)
return -1L;
* Do seccomp first -- it should minimize exposure of other
* code, and keeping seccomp fast is probably more valuable
* than the rest of this.
* Do seccomp after ptrace, to catch any tracer changes.
if (work & _TIF_SECCOMP) {
struct seccomp_data sd;
......@@ -117,13 +126,6 @@ static long syscall_trace_enter(struct pt_regs *regs)
if (unlikely(work & _TIF_SYSCALL_EMU))
ret = -1L;
if ((ret || test_thread_flag(TIF_SYSCALL_TRACE)) &&
ret = -1L;
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
trace_sys_enter(regs, regs->orig_ax);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment