@@ -1129,7 +1129,9 @@ int seccomp_load_syscall_filter_set_raw(uint32_t default_action, Hashmap* filter
11291129
11301130 log_trace ("Operating on architecture: %s" , seccomp_arch_to_string (arch ));
11311131
1132- r = seccomp_init_for_arch (& seccomp , arch , default_action );
1132+ /* We install ENOSYS as the default action, but it will only apply to syscalls which are not
1133+ * in the @known set. */
1134+ r = seccomp_init_for_arch (& seccomp , arch , SCMP_ACT_ERRNO (ENOSYS ));
11331135 if (r < 0 )
11341136 return r ;
11351137
@@ -1164,6 +1166,30 @@ int seccomp_load_syscall_filter_set_raw(uint32_t default_action, Hashmap* filter
11641166 }
11651167 }
11661168
1169+ NULSTR_FOREACH (name , syscall_filter_sets [SYSCALL_FILTER_SET_KNOWN ].value ) {
1170+ int id ;
1171+
1172+ id = seccomp_syscall_resolve_name (name );
1173+ if (id < 0 )
1174+ continue ;
1175+
1176+ /* Ignore the syscall if it was already handled above */
1177+ if (hashmap_contains (filter , INT_TO_PTR (id + 1 )))
1178+ continue ;
1179+
1180+ r = seccomp_rule_add_exact (seccomp , default_action , id , 0 );
1181+ if (r < 0 && r != - EDOM ) /* EDOM means that the syscall is not available for arch */
1182+ return log_debug_errno (r , "Failed to add rule for system call %s() / %d: %m" ,
1183+ name , id );
1184+ }
1185+
1186+ #if (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR >= 5 ) || SCMP_VER_MAJOR > 2
1187+ /* We have a large filter here, so let's turn on the binary tree mode if possible. */
1188+ r = seccomp_attr_set (seccomp , SCMP_FLTATR_CTL_OPTIMIZE , 2 );
1189+ if (r < 0 )
1190+ log_warning_errno (r , "Failed to set SCMP_FLTATR_CTL_OPTIMIZE, ignoring: %m" );
1191+ #endif
1192+
11671193 r = seccomp_load (seccomp );
11681194 if (ERRNO_IS_NEG_SECCOMP_FATAL (r ))
11691195 return r ;
@@ -1223,7 +1249,7 @@ int seccomp_parse_syscall_filter(
12231249 return - EINVAL ;
12241250
12251251 log_syntax (unit , FLAGS_SET (flags , SECCOMP_PARSE_LOG ) ? LOG_WARNING : LOG_DEBUG , filename , line , 0 ,
1226- "Failed to parse system call , ignoring: %s " , name );
1252+ "System call %s is not known , ignoring. " , name );
12271253 return 0 ;
12281254 }
12291255
@@ -1981,7 +2007,7 @@ int seccomp_filter_set_add(Hashmap *filter, bool add, const SyscallFilterSet *se
19812007
19822008 id = seccomp_syscall_resolve_name (i );
19832009 if (id == __NR_SCMP_ERROR ) {
1984- log_debug ("Couldn't resolve system call , ignoring: %s " , i );
2010+ log_debug ("System call %s is not known , ignoring. " , i );
19852011 continue ;
19862012 }
19872013
0 commit comments