aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/entry/common.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2016-06-09 15:36:50 -0400
committerKees Cook <keescook@chromium.org>2016-06-14 13:54:41 -0400
commit93e35efb8de45393cf61ed07f7b407629bf698ea (patch)
tree862d7e65445f7c7a53025fbfc097eb9e4f363715 /arch/x86/entry/common.c
parentce6526e8afa4b6ad0ab134a4cc50c9c863319637 (diff)
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 <luto@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Cc: x86@kernel.org Cc: Andy Lutomirski <luto@kernel.org>
Diffstat (limited to 'arch/x86/entry/common.c')
-rw-r--r--arch/x86/entry/common.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index df56ca394877..81c0e12d831c 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -73,6 +73,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
73 73
74 struct thread_info *ti = pt_regs_to_thread_info(regs); 74 struct thread_info *ti = pt_regs_to_thread_info(regs);
75 unsigned long ret = 0; 75 unsigned long ret = 0;
76 bool emulated = false;
76 u32 work; 77 u32 work;
77 78
78 if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) 79 if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
@@ -80,11 +81,19 @@ static long syscall_trace_enter(struct pt_regs *regs)
80 81
81 work = ACCESS_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY; 82 work = ACCESS_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY;
82 83
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
83#ifdef CONFIG_SECCOMP 94#ifdef CONFIG_SECCOMP
84 /* 95 /*
85 * Do seccomp first -- it should minimize exposure of other 96 * Do seccomp after ptrace, to catch any tracer changes.
86 * code, and keeping seccomp fast is probably more valuable
87 * than the rest of this.
88 */ 97 */
89 if (work & _TIF_SECCOMP) { 98 if (work & _TIF_SECCOMP) {
90 struct seccomp_data sd; 99 struct seccomp_data sd;
@@ -117,13 +126,6 @@ static long syscall_trace_enter(struct pt_regs *regs)
117 } 126 }
118#endif 127#endif
119 128
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
127 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) 129 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
128 trace_sys_enter(regs, regs->orig_ax); 130 trace_sys_enter(regs, regs->orig_ax);
129 131