Skip to content

Commit 11c2b2e

Browse files
committed
Merge tag 'seccomp-v6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull seccomp updates from Kees Cook: - avoid the lock trip seccomp_filter_release in common case (Mateusz Guzik) - remove unused 'sd' argument through-out (Oleg Nesterov) - selftests/seccomp: Add hard-coded __NR_uretprobe for x86_64 * tag 'seccomp-v6.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: seccomp: avoid the lock trip seccomp_filter_release in common case seccomp: remove the 'sd' argument from __seccomp_filter() seccomp: remove the 'sd' argument from __secure_computing() seccomp: fix the __secure_computing() stub for !HAVE_ARCH_SECCOMP_FILTER seccomp/mips: change syscall_trace_enter() to use secure_computing() selftests/seccomp: Add hard-coded __NR_uretprobe for x86_64
2 parents fc13a78 + 8f19331 commit 11c2b2e

File tree

6 files changed

+43
-48
lines changed

6 files changed

+43
-48
lines changed

arch/mips/kernel/ptrace.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,24 +1326,8 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs)
13261326
return -1;
13271327
}
13281328

1329-
#ifdef CONFIG_SECCOMP
1330-
if (unlikely(test_thread_flag(TIF_SECCOMP))) {
1331-
int ret, i;
1332-
struct seccomp_data sd;
1333-
unsigned long args[6];
1334-
1335-
sd.nr = current_thread_info()->syscall;
1336-
sd.arch = syscall_get_arch(current);
1337-
syscall_get_arguments(current, regs, args);
1338-
for (i = 0; i < 6; i++)
1339-
sd.args[i] = args[i];
1340-
sd.instruction_pointer = KSTK_EIP(current);
1341-
1342-
ret = __secure_computing(&sd);
1343-
if (ret == -1)
1344-
return ret;
1345-
}
1346-
#endif
1329+
if (secure_computing())
1330+
return -1;
13471331

13481332
if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
13491333
trace_sys_enter(regs, regs->regs[2]);

arch/powerpc/kernel/ptrace/ptrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static int do_seccomp(struct pt_regs *regs)
215215
* have already loaded -ENOSYS into r3, or seccomp has put
216216
* something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
217217
*/
218-
if (__secure_computing(NULL))
218+
if (__secure_computing())
219219
return -1;
220220

221221
/*

include/linux/seccomp.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@
2222
#include <linux/atomic.h>
2323
#include <asm/seccomp.h>
2424

25+
extern int __secure_computing(void);
26+
2527
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
26-
extern int __secure_computing(const struct seccomp_data *sd);
2728
static inline int secure_computing(void)
2829
{
2930
if (unlikely(test_syscall_work(SECCOMP)))
30-
return __secure_computing(NULL);
31+
return __secure_computing();
3132
return 0;
3233
}
3334
#else
3435
extern void secure_computing_strict(int this_syscall);
35-
static inline int __secure_computing(const struct seccomp_data *sd)
36-
{
37-
secure_computing_strict(sd->nr);
38-
return 0;
39-
}
4036
#endif
4137

4238
extern long prctl_get_seccomp(void);
@@ -58,7 +54,7 @@ static inline int secure_computing(void) { return 0; }
5854
#else
5955
static inline void secure_computing_strict(int this_syscall) { return; }
6056
#endif
61-
static inline int __secure_computing(const struct seccomp_data *sd) { return 0; }
57+
static inline int __secure_computing(void) { return 0; }
6258

6359
static inline long prctl_get_seccomp(void)
6460
{

kernel/entry/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ long syscall_trace_enter(struct pt_regs *regs, long syscall,
4949

5050
/* Do seccomp after ptrace, to catch any tracer changes. */
5151
if (work & SYSCALL_WORK_SECCOMP) {
52-
ret = __secure_computing(NULL);
52+
ret = __secure_computing();
5353
if (ret == -1L)
5454
return ret;
5555
}

kernel/seccomp.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929
#include <linux/syscalls.h>
3030
#include <linux/sysctl.h>
3131

32+
#include <asm/syscall.h>
33+
3234
/* Not exposed in headers: strictly internal use only. */
3335
#define SECCOMP_MODE_DEAD (SECCOMP_MODE_FILTER + 1)
3436

35-
#ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
36-
#include <asm/syscall.h>
37-
#endif
38-
3937
#ifdef CONFIG_SECCOMP_FILTER
4038
#include <linux/file.h>
4139
#include <linux/filter.h>
@@ -576,6 +574,9 @@ void seccomp_filter_release(struct task_struct *tsk)
576574
if (WARN_ON((tsk->flags & PF_EXITING) == 0))
577575
return;
578576

577+
if (READ_ONCE(tsk->seccomp.filter) == NULL)
578+
return;
579+
579580
spin_lock_irq(&tsk->sighand->siglock);
580581
orig = tsk->seccomp.filter;
581582
/* Detach task from its filter tree. */
@@ -601,6 +602,13 @@ static inline void seccomp_sync_threads(unsigned long flags)
601602
BUG_ON(!mutex_is_locked(&current->signal->cred_guard_mutex));
602603
assert_spin_locked(&current->sighand->siglock);
603604

605+
/*
606+
* Don't touch any of the threads if the process is being killed.
607+
* This allows for a lockless check in seccomp_filter_release.
608+
*/
609+
if (current->signal->flags & SIGNAL_GROUP_EXIT)
610+
return;
611+
604612
/* Synchronize all threads. */
605613
caller = current;
606614
for_each_thread(caller, thread) {
@@ -1074,6 +1082,13 @@ void secure_computing_strict(int this_syscall)
10741082
else
10751083
BUG();
10761084
}
1085+
int __secure_computing(void)
1086+
{
1087+
int this_syscall = syscall_get_nr(current, current_pt_regs());
1088+
1089+
secure_computing_strict(this_syscall);
1090+
return 0;
1091+
}
10771092
#else
10781093

10791094
#ifdef CONFIG_SECCOMP_FILTER
@@ -1225,26 +1240,22 @@ static int seccomp_do_user_notification(int this_syscall,
12251240
return -1;
12261241
}
12271242

1228-
static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
1229-
const bool recheck_after_trace)
1243+
static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)
12301244
{
12311245
u32 filter_ret, action;
1246+
struct seccomp_data sd;
12321247
struct seccomp_filter *match = NULL;
12331248
int data;
1234-
struct seccomp_data sd_local;
12351249

12361250
/*
12371251
* Make sure that any changes to mode from another thread have
12381252
* been seen after SYSCALL_WORK_SECCOMP was seen.
12391253
*/
12401254
smp_rmb();
12411255

1242-
if (!sd) {
1243-
populate_seccomp_data(&sd_local);
1244-
sd = &sd_local;
1245-
}
1256+
populate_seccomp_data(&sd);
12461257

1247-
filter_ret = seccomp_run_filters(sd, &match);
1258+
filter_ret = seccomp_run_filters(&sd, &match);
12481259
data = filter_ret & SECCOMP_RET_DATA;
12491260
action = filter_ret & SECCOMP_RET_ACTION_FULL;
12501261

@@ -1302,13 +1313,13 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
13021313
* a reload of all registers. This does not goto skip since
13031314
* a skip would have already been reported.
13041315
*/
1305-
if (__seccomp_filter(this_syscall, NULL, true))
1316+
if (__seccomp_filter(this_syscall, true))
13061317
return -1;
13071318

13081319
return 0;
13091320

13101321
case SECCOMP_RET_USER_NOTIF:
1311-
if (seccomp_do_user_notification(this_syscall, match, sd))
1322+
if (seccomp_do_user_notification(this_syscall, match, &sd))
13121323
goto skip;
13131324

13141325
return 0;
@@ -1350,16 +1361,15 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
13501361
return -1;
13511362
}
13521363
#else
1353-
static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd,
1354-
const bool recheck_after_trace)
1364+
static int __seccomp_filter(int this_syscall, const bool recheck_after_trace)
13551365
{
13561366
BUG();
13571367

13581368
return -1;
13591369
}
13601370
#endif
13611371

1362-
int __secure_computing(const struct seccomp_data *sd)
1372+
int __secure_computing(void)
13631373
{
13641374
int mode = current->seccomp.mode;
13651375
int this_syscall;
@@ -1368,15 +1378,14 @@ int __secure_computing(const struct seccomp_data *sd)
13681378
unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
13691379
return 0;
13701380

1371-
this_syscall = sd ? sd->nr :
1372-
syscall_get_nr(current, current_pt_regs());
1381+
this_syscall = syscall_get_nr(current, current_pt_regs());
13731382

13741383
switch (mode) {
13751384
case SECCOMP_MODE_STRICT:
13761385
__secure_computing_strict(this_syscall); /* may call do_exit */
13771386
return 0;
13781387
case SECCOMP_MODE_FILTER:
1379-
return __seccomp_filter(this_syscall, sd, false);
1388+
return __seccomp_filter(this_syscall, false);
13801389
/* Surviving SECCOMP_RET_KILL_* must be proactively impossible. */
13811390
case SECCOMP_MODE_DEAD:
13821391
WARN_ON_ONCE(1);

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ struct seccomp_data {
155155
# endif
156156
#endif
157157

158+
#ifndef __NR_uretprobe
159+
# if defined(__x86_64__)
160+
# define __NR_uretprobe 335
161+
# endif
162+
#endif
163+
158164
#ifndef SECCOMP_SET_MODE_STRICT
159165
#define SECCOMP_SET_MODE_STRICT 0
160166
#endif

0 commit comments

Comments
 (0)