Skip to content

Commit ac04154

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 076745a commit ac04154

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
@@ -1024,12 +1024,22 @@ func SetupSeccomp(config *specs.LinuxSeccomp) (*configs.Seccomp, error) {
10241024
newConfig.Syscalls = []*configs.Syscall{}
10251025

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

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