Skip to content

Commit 9d01b2f

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 <[email protected]>
1 parent 546a228 commit 9d01b2f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

libcontainer/specconv/spec_linux.go

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

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

10321042
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)