@@ -173,21 +173,24 @@ static int seccomp_check_filter(struct sock_filter *filter, unsigned int flen)
173173 */
174174static u32 seccomp_run_filters (int syscall )
175175{
176- struct seccomp_filter * f ;
176+ struct seccomp_filter * f = ACCESS_ONCE ( current -> seccomp . filter ) ;
177177 struct seccomp_data sd ;
178178 u32 ret = SECCOMP_RET_ALLOW ;
179179
180180 /* Ensure unexpected behavior doesn't result in failing open. */
181- if (WARN_ON (current -> seccomp . filter == NULL ))
181+ if (unlikely ( WARN_ON (f == NULL ) ))
182182 return SECCOMP_RET_KILL ;
183183
184+ /* Make sure cross-thread synced filter points somewhere sane. */
185+ smp_read_barrier_depends ();
186+
184187 populate_seccomp_data (& sd );
185188
186189 /*
187190 * All filters in the list are evaluated and the lowest BPF return
188191 * value always takes priority (ignoring the DATA).
189192 */
190- for (f = current -> seccomp . filter ; f ; f = f -> prev ) {
193+ for (; f ; f = f -> prev ) {
191194 u32 cur_ret = SK_RUN_FILTER (f -> prog , (void * )& sd );
192195
193196 if ((cur_ret & SECCOMP_RET_ACTION ) < (ret & SECCOMP_RET_ACTION ))
@@ -207,12 +210,18 @@ static inline bool seccomp_may_assign_mode(unsigned long seccomp_mode)
207210 return true;
208211}
209212
210- static inline void seccomp_assign_mode (unsigned long seccomp_mode )
213+ static inline void seccomp_assign_mode (struct task_struct * task ,
214+ unsigned long seccomp_mode )
211215{
212- BUG_ON (!spin_is_locked (& current -> sighand -> siglock ));
216+ BUG_ON (!spin_is_locked (& task -> sighand -> siglock ));
213217
214- current -> seccomp .mode = seccomp_mode ;
215- set_tsk_thread_flag (current , TIF_SECCOMP );
218+ task -> seccomp .mode = seccomp_mode ;
219+ /*
220+ * Make sure TIF_SECCOMP cannot be set before the mode (and
221+ * filter) is set.
222+ */
223+ smp_mb__before_atomic ();
224+ set_tsk_thread_flag (task , TIF_SECCOMP );
216225}
217226
218227#ifdef CONFIG_SECCOMP_FILTER
@@ -435,12 +444,17 @@ static int mode1_syscalls_32[] = {
435444
436445int __secure_computing (int this_syscall )
437446{
438- int mode = current -> seccomp .mode ;
439447 int exit_sig = 0 ;
440448 int * syscall ;
441449 u32 ret ;
442450
443- switch (mode ) {
451+ /*
452+ * Make sure that any changes to mode from another thread have
453+ * been seen after TIF_SECCOMP was seen.
454+ */
455+ rmb ();
456+
457+ switch (current -> seccomp .mode ) {
444458 case SECCOMP_MODE_STRICT :
445459 syscall = mode1_syscalls ;
446460#ifdef CONFIG_COMPAT
@@ -545,7 +559,7 @@ static long seccomp_set_mode_strict(void)
545559#ifdef TIF_NOTSC
546560 disable_TSC ();
547561#endif
548- seccomp_assign_mode (seccomp_mode );
562+ seccomp_assign_mode (current , seccomp_mode );
549563 ret = 0 ;
550564
551565out :
@@ -595,7 +609,7 @@ static long seccomp_set_mode_filter(unsigned int flags,
595609 /* Do not free the successfully attached filter. */
596610 prepared = NULL ;
597611
598- seccomp_assign_mode (seccomp_mode );
612+ seccomp_assign_mode (current , seccomp_mode );
599613out :
600614 spin_unlock_irq (& current -> sighand -> siglock );
601615 seccomp_filter_free (prepared );
0 commit comments