Skip to content

Commit 40d8286

Browse files
committed
seccomp: add support for SECCOMP_FILTER_FLAG_LOG
Signed-off-by: Alban Crequy <albancrequy@microsoft.com>
1 parent 2436322 commit 40d8286

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

libcontainer/configs/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type IDMap struct {
3333
type Seccomp struct {
3434
DefaultAction Action `json:"default_action"`
3535
Architectures []string `json:"architectures"`
36+
Flags []string `json:"flags"`
3637
Syscalls []*Syscall `json:"syscalls"`
3738
DefaultErrnoRet *uint `json:"default_errno_ret"`
3839
ListenerPath string `json:"listener_path,omitempty"`

libcontainer/seccomp/seccomp_linux.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ func InitSeccomp(config *configs.Seccomp) (int, error) {
8686
}
8787
}
8888

89+
// Add extra flags
90+
for _, flag := range config.Flags {
91+
switch flag {
92+
case "SECCOMP_FILTER_FLAG_LOG":
93+
if err := filter.SetLogBit(true); err != nil {
94+
return -1, fmt.Errorf("error adding log flag to seccomp filter: %w", err)
95+
}
96+
default:
97+
return -1, fmt.Errorf("seccomp flags %q not yet supported by runc", flag)
98+
}
99+
}
100+
89101
// Unset no new privs bit
90102
if err := filter.SetNoNewPrivsBit(false); err != nil {
91103
return -1, fmt.Errorf("error setting no new privileges: %w", err)

libcontainer/specconv/spec_linux.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,19 @@ func SetupSeccomp(config *specs.LinuxSeccomp) (*configs.Seccomp, error) {
10161016
return nil, nil
10171017
}
10181018

1019-
// We don't currently support seccomp flags.
1020-
if len(config.Flags) != 0 {
1021-
return nil, errors.New("seccomp flags are not yet supported by runc")
1022-
}
1023-
10241019
newConfig := new(configs.Seccomp)
10251020
newConfig.Syscalls = []*configs.Syscall{}
10261021

1022+
// We don't currently support all seccomp flags.
1023+
for _, flag := range config.Flags {
1024+
switch flag {
1025+
case "SECCOMP_FILTER_FLAG_LOG":
1026+
newConfig.Flags = append(newConfig.Flags, "SECCOMP_FILTER_FLAG_LOG")
1027+
default:
1028+
return nil, fmt.Errorf("seccomp flags %q not yet supported by runc", flag)
1029+
}
1030+
}
1031+
10271032
if len(config.Architectures) > 0 {
10281033
newConfig.Architectures = []string{}
10291034
for _, arch := range config.Architectures {

tests/integration/seccomp.bats

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ function teardown() {
6666
[[ "$output" == *"Network is down"* ]]
6767
}
6868

69+
@test "runc run [seccomp] (SECCOMP_FILTER_FLAG_LOG)" {
70+
requires_kernel 4.14 # SECCOMP_FILTER_FLAG_LOG appeared in Linux 4.14
71+
update_config ' .process.args = ["/bin/sh", "-c", "mkdir /dev/shm/foo"]
72+
| .process.noNewPrivileges = false
73+
| .linux.seccomp = {
74+
"defaultAction":"SCMP_ACT_ALLOW",
75+
"architectures":["SCMP_ARCH_X86","SCMP_ARCH_X32"],
76+
"flags":["SECCOMP_FILTER_FLAG_LOG"],
77+
"syscalls":[{"names":["mkdir"], "action":"SCMP_ACT_ERRNO"}]
78+
}'
79+
80+
# This test checks that the log flag is accepted but does not check the
81+
# audit log
82+
runc run test_busybox
83+
[ "$status" -ne 0 ]
84+
[[ "$output" == *"mkdir:"*"/dev/shm/foo"*"Operation not permitted"* ]]
85+
}
86+
6987
@test "runc run [seccomp] (SCMP_ACT_KILL)" {
7088
update_config ' .process.args = ["/bin/sh", "-c", "mkdir /dev/shm/foo"]
7189
| .process.noNewPrivileges = false

0 commit comments

Comments
 (0)