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
135 * Returns the AUDIT_ARCH_* based on the system call convention in use.135 * Returns the AUDIT_ARCH_* based on the system call convention in use.
136 *136 *
137 * It's only valid to call this when @task is stopped on entry to a system137 * 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.
139 *139 *
140 * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must140 * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
141 * provide an implementation of this.141 * provide an implementation of this.
include/linux/entry-common.h+2−6
@@ -21,10 +21,6 @@ · 20 unmodified lines
21# define _TIF_SYSCALL_TRACEPOINT (0)21# define _TIF_SYSCALL_TRACEPOINT (0)
22#endif22#endif
23 23
24#ifndef _TIF_SECCOMP
25# define _TIF_SECCOMP (0)
26#endif
27
28#ifndef _TIF_SYSCALL_AUDIT24#ifndef _TIF_SYSCALL_AUDIT
29# define _TIF_SYSCALL_AUDIT (0)25# define _TIF_SYSCALL_AUDIT (0)
30#endif26#endif
@@ -49,7 +45,7 @@ · 18 unmodified lines
49#endif45#endif
50 46
51#define SYSCALL_ENTER_WORK \47#define SYSCALL_ENTER_WORK \
52 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \48 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
53 _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU | \49 _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU | \
54 ARCH_SYSCALL_ENTER_WORK)50 ARCH_SYSCALL_ENTER_WORK)
55 51
@@ -64,7 +60,7 @@ · 8 unmodified lines
64 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \60 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
65 _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)61 _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)
66 62
67#define SYSCALL_WORK_ENTER (0)63#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP)
68#define SYSCALL_WORK_EXIT (0)64#define SYSCALL_WORK_EXIT (0)
69 65
70/*66/*
include/linux/seccomp.h+1−1
@@ -42,7 +42,7 @@ struct seccomp { · 41 unmodified lines
42extern int __secure_computing(const struct seccomp_data *sd);42extern int __secure_computing(const struct seccomp_data *sd);
43static inline int secure_computing(void)43static inline int secure_computing(void)
44{44{
45 if (unlikely(test_thread_flag(TIF_SECCOMP)))45 if (unlikely(test_syscall_work(SECCOMP)))
46 return __secure_computing(NULL);46 return __secure_computing(NULL);
47 return 0;47 return 0;
48}48}
include/linux/thread_info.h+6−0
@@ -35,6 +35,12 @@ enum { · 34 unmodified lines
35 GOOD_STACK,35 GOOD_STACK,
36};36};
37 37
38enum syscall_work_bit {
39 SYSCALL_WORK_BIT_SECCOMP,
40};
41
42#define SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_BIT_SECCOMP)
43
38#include <asm/thread_info.h>44#include <asm/thread_info.h>
39 45
40#ifdef __KERNEL__46#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
54 }54 }
55 55
56 /* Do seccomp after ptrace, to catch any tracer changes. */56 /* Do seccomp after ptrace, to catch any tracer changes. */
57 if (ti_work & _TIF_SECCOMP) {57 if (work & SYSCALL_WORK_SECCOMP) {
58 ret = __secure_computing(NULL);58 ret = __secure_computing(NULL);
59 if (ret == -1L)59 if (ret == -1L)
60 return ret;60 return ret;
kernel/fork.c+1−1
@@ -1625,7 +1625,7 @@ static void copy_seccomp(struct task_struct *p) · 1624 unmodified lines
1625 * to manually enable the seccomp thread flag here.1625 * to manually enable the seccomp thread flag here.
1626 */1626 */
1627 if (p->seccomp.mode != SECCOMP_MODE_DISABLED)1627 if (p->seccomp.mode != SECCOMP_MODE_DISABLED)
1628 set_tsk_thread_flag(p, TIF_SECCOMP);1628 set_task_syscall_work(p, SECCOMP);
1629#endif1629#endif
1630}1630}
1631 1631
kernel/seccomp.c+3−3
@@ -356,14 +356,14 @@ static inline void seccomp_assign_mode(struct task_struct *task, · 355 unmodified lines
356 356
357 task->seccomp.mode = seccomp_mode;357 task->seccomp.mode = seccomp_mode;
358 /*358 /*
359 * Make sure TIF_SECCOMP cannot be set before the mode (and359 * Make sure SYSCALL_WORK_SECCOMP cannot be set before the mode (and
360 * filter) is set.360 * filter) is set.
361 */361 */
362 smp_mb__before_atomic();362 smp_mb__before_atomic();
363 /* Assume default seccomp processes want spec flaw mitigation. */363 /* Assume default seccomp processes want spec flaw mitigation. */
364 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)364 if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0)
365 arch_seccomp_spec_mitigate(task);365 arch_seccomp_spec_mitigate(task);
366 set_tsk_thread_flag(task, TIF_SECCOMP);366 set_task_syscall_work(task, SECCOMP);
367}367}
368 368
369#ifdef CONFIG_SECCOMP_FILTER369#ifdef CONFIG_SECCOMP_FILTER
@@ -929,7 +929,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · 559 unmodified lines
929 929
930 /*930 /*
931 * Make sure that any changes to mode from another thread have931 * 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.
933 */933 */
934 rmb();934 rmb();
935 935

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