@@ -1105,19 +1105,47 @@ int seccomp_load_syscall_filter_set(uint32_t default_action, const SyscallFilter
11051105 /* The one-stop solution: allocate a seccomp object, add the specified filter to it, and apply it. Once for
11061106 * each local arch. */
11071107
1108+ default_action_override = override_default_action (default_action );
1109+
11081110 SECCOMP_FOREACH_LOCAL_ARCH (arch ) {
11091111 _cleanup_ (seccomp_releasep ) scmp_filter_ctx seccomp = NULL ;
1112+ _cleanup_strv_free_ char * * added = NULL ;
11101113
11111114 log_trace ("Operating on architecture: %s" , seccomp_arch_to_string (arch ));
11121115
1113- r = seccomp_init_for_arch (& seccomp , arch , default_action );
1116+ r = seccomp_init_for_arch (& seccomp , arch , default_action_override );
11141117 if (r < 0 )
11151118 return r ;
11161119
1117- r = add_syscall_filter_set (seccomp , set , action , NULL , log_missing , NULL );
1120+ r = add_syscall_filter_set (seccomp , set , action , NULL , log_missing , & added );
11181121 if (r < 0 )
11191122 return log_debug_errno (r , "Failed to add filter set: %m" );
11201123
1124+ if (default_action != default_action_override )
1125+ NULSTR_FOREACH (name , syscall_filter_sets [SYSCALL_FILTER_SET_KNOWN ].value ) {
1126+ int id ;
1127+
1128+ id = seccomp_syscall_resolve_name (name );
1129+ if (id < 0 )
1130+ continue ;
1131+
1132+ /* Ignore the syscall if it was already handled above */
1133+ if (strv_contains (added , name ))
1134+ continue ;
1135+
1136+ r = seccomp_rule_add_exact (seccomp , default_action , id , 0 );
1137+ if (r < 0 && r != - EDOM ) /* EDOM means that the syscall is not available for arch */
1138+ return log_debug_errno (r , "Failed to add rule for system call %s() / %d: %m" ,
1139+ name , id );
1140+ }
1141+
1142+ #if (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR >= 5 ) || SCMP_VER_MAJOR > 2
1143+ /* We have a large filter here, so let's turn on the binary tree mode if possible. */
1144+ r = seccomp_attr_set (seccomp , SCMP_FLTATR_CTL_OPTIMIZE , 2 );
1145+ if (r < 0 )
1146+ log_warning_errno (r , "Failed to set SCMP_FLTATR_CTL_OPTIMIZE, ignoring: %m" );
1147+ #endif
1148+
11211149 r = seccomp_load (seccomp );
11221150 if (ERRNO_IS_NEG_SECCOMP_FATAL (r ))
11231151 return r ;
0 commit comments