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 );
0 commit comments