Skip to content

Commit 23d67a5

Browse files
krisman-at-collaboraKAGA-KOKO
authored andcommitted
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. Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Andy Lutomirski <luto@kernel.org> Link: https://lore.kernel.org/r/20201116174206.2639648-5-krisman@collabora.com
1 parent b86678c commit 23d67a5

7 files changed

Lines changed: 15 additions & 13 deletions

File tree

‎include/asm-generic/syscall.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
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‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
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 @@
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 @@
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct seccomp {
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‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ enum {
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall,
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‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ static void copy_seccomp(struct task_struct *p)
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‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ static inline void seccomp_assign_mode(struct task_struct *task,
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,
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

0 commit comments

Comments
 (0)