Skip to content

Commit e2cfd14

Browse files
committed
seccomp: set SPEC_ALLOW by default
If no seccomps flags are set in OCI runtime spec (not even the empty set), set SPEC_ALLOW as the default (if it's supported). Otherwise, use the flags as they are set (that includes no flags for empty seccomp.Flags array). This mimics the crun behavior, and makes runc seccomp performance on par with crun. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> (cherry picked from commit c162ecc3a1dc314ae78797c83b3adac7bb6f0374) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent ef125f0 commit e2cfd14

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

libcontainer/specconv/spec_linux.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,12 +1019,22 @@ func SetupSeccomp(config *specs.LinuxSeccomp) (*configs.Seccomp, error) {
10191019
newConfig.Syscalls = []*configs.Syscall{}
10201020

10211021
// The list of flags defined in runtime-spec is a subset of the flags
1022-
// in the seccomp() syscall
1023-
for _, flag := range config.Flags {
1024-
if err := seccomp.FlagSupported(flag); err != nil {
1025-
return nil, err
1022+
// in the seccomp() syscall.
1023+
if config.Flags == nil {
1024+
// No flags are set explicitly (not even the empty set);
1025+
// set the default of specs.LinuxSeccompFlagSpecAllow,
1026+
// if it is supported by the libseccomp and the kernel.
1027+
if err := seccomp.FlagSupported(specs.LinuxSeccompFlagSpecAllow); err == nil {
1028+
newConfig.Flags = []specs.LinuxSeccompFlag{specs.LinuxSeccompFlagSpecAllow}
1029+
}
1030+
} else {
1031+
// Fail early if some flags are unknown or unsupported.
1032+
for _, flag := range config.Flags {
1033+
if err := seccomp.FlagSupported(flag); err != nil {
1034+
return nil, err
1035+
}
1036+
newConfig.Flags = append(newConfig.Flags, flag)
10261037
}
1027-
newConfig.Flags = append(newConfig.Flags, flag)
10281038
}
10291039

10301040
if len(config.Architectures) > 0 {

tests/integration/seccomp.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function teardown() {
8080
}'
8181

8282
declare -A FLAGS=(
83-
['REMOVE']=0 # No setting, use built-in default.
83+
['REMOVE']=4 # No setting, use built-in default.
8484
['EMPTY']=0 # Empty set of flags.
8585
['"SECCOMP_FILTER_FLAG_LOG"']=2
8686
['"SECCOMP_FILTER_FLAG_SPEC_ALLOW"']=4

0 commit comments

Comments
 (0)