History

seccomp: Migrate to use SYSCALL_WORK flag

On architectures using the generic syscall entry code the architecture independent syscall work is moved to flags in thread_info::syscall_work. This removes architecture dependencies and frees up TIF bits. Define SYSCALL_WORK_SECCOMP, use it in the generic entry code and convert the code which uses the TIF specific helper functions to use the new *_syscall_work() helpers which either resolve to the new mode for users of the generic entry code or to the TIF based functions for the other architectures.

Gabriel Krisman Bertazi committed 5 years ago

Commit 23d67a51 parent b86678c7 files · +15 −13Browse files

Unified · Split

7 files
  1. include/asm-generic/syscall.h +1 −1
  2. include/linux/entry-common.h +2 −6
  3. include/linux/seccomp.h +1 −1
  4. include/linux/thread_info.h +6 −0
  5. kernel/entry/common.c +1 −1
  6. kernel/fork.c +1 −1
  7. kernel/seccomp.c +3 −3
include/asm-generic/syscall.h+1−1
@@ -135,7 +135,7 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs, · 134 unmodified lines
135135 * Returns the AUDIT_ARCH_* based on the system call convention in use.
136136 *
137137 * It's only valid to call this when @task is stopped on entry to a system
138− * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %TIF_SECCOMP.
138+ * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %SYSCALL_WORK_SECCOMP.
139139 *
140140 * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
141141 * provide an implementation of this.
include/linux/entry-common.h+2−6
@@ -21,10 +21,6 @@ · 20 unmodified lines
2121 # define _TIF_SYSCALL_TRACEPOINT (0)
2222 #endif
2323
24−#ifndef _TIF_SECCOMP
25−# define _TIF_SECCOMP (0)
26−#endif
27−
2824 #ifndef _TIF_SYSCALL_AUDIT
2925 # define _TIF_SYSCALL_AUDIT (0)
3026 #endif
@@ -49,7 +45,7 @@ · 18 unmodified lines
4945 #endif
5046
5147 #define SYSCALL_ENTER_WORK \
52− (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
48+ (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5349 _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU | \
5450 ARCH_SYSCALL_ENTER_WORK)
5551
@@ -64,7 +60,7 @@ · 8 unmodified lines
6460 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6561 _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)
6662
67−#define SYSCALL_WORK_ENTER (0)
63+#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP)
6864 #define SYSCALL_WORK_EXIT (0)
6965
7066 /*
include/linux/seccomp.h+1−1
@@ -42,7 +42,7 @@ struct seccomp { · 41 unmodified lines
4242 extern int __secure_computing(const struct seccomp_data *sd);
4343 static inline int secure_computing(void)
4444 {
45− if (unlikely(test_thread_flag(TIF_SECCOMP)))
45+ if (unlikely(test_syscall_work(SECCOMP)))
4646 return __secure_computing(NULL);
4747 return 0;
4848 }
include/linux/thread_info.h+6−0
@@ -35,6 +35,12 @@ enum { · 34 unmodified lines
3535 GOOD_STACK,
3636 };
3737
38+enum syscall_work_bit {
39+ SYSCALL_WORK_BIT_SECCOMP,
40+};
41+
42+#define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP)
43+
3844 #include <asm/thread_info.h>
3945
4046 #ifdef __KERNEL__
kernel/entry/common.c+1−1
@@ -54,7 +54,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall, · 53 unmodified lines
5454 }
5555
5656 /* Do seccomp after ptrace, to catch any tracer changes. */
57− if (ti_work & _TIF_SECCOMP) {
57+ if (work & SYSCALL_WORK_SECCOMP) {
5858 ret = __secure_computing(NULL);
5959 if (ret == -1L)
6060 return ret;
kernel/fork.c+1−1
@@ -1625,7 +1625,7 @@ static void copy_seccomp(struct task_struct *p) · 1624 unmodified lines
16251625 * to manually enable the seccomp thread flag here.
16261626 */
16271627 if (p->seccomp.mode != SECCOMP_MODE_DISABLED)
1628− set_tsk_thread_flag(p, TIF_SECCOMP);
1628+ set_task_syscall_work(p, SECCOMP);
16291629 #endif
16301630 }
16311631
kernel/seccomp.c+3−3
@@ -356,14 +356,14 @@ static inline void seccomp_assign_mode(struct task_struct *task, · 355 unmodified lines
356356
357357 task->seccomp.mode = seccomp_mode;
358358 /*
359− * Make sure TIF_SECCOMP cannot be set before the mode (and
359+ * Make sure SYSCALL_WORK_SECCOMP cannot be set before the mode (and
360360 * filter) is set.
361361 */
362362 smp_mb__before_atomic();
363363 /* Assume default seccomp processes want spec flaw mitigation. */
364364 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
365365 arch_seccomp_spec_mitigate(task);
366− set_tsk_thread_flag(task, TIF_SECCOMP);
366+ set_task_syscall_work(task, SECCOMP);
367367 }
368368
369369 #ifdef CONFIG_SECCOMP_FILTER
@@ -929,7 +929,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · 559 unmodified lines
929929
930930 /*
931931 * Make sure that any changes to mode from another thread have
932− * been seen after TIF_SECCOMP was seen.
932+ * been seen after SYSCALL_WORK_SECCOMP was seen.
933933 */
934934 rmb();
935935

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t