Skip to content

Commit c01a560

Browse files
committed
merge branch 'pr-2954'
Giuseppe Scrivano (1): libcontainer: honor seccomp defaultErrnoRet LGTMs: kolyshkin cyphar Closes #2954
2 parents 5c4ccc2 + c61f606 commit c01a560

File tree

7 files changed

+391
-4
lines changed

7 files changed

+391
-4
lines changed

libcontainer/configs/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type IDMap struct {
3131
// for syscalls. Additional architectures can be added by specifying them in
3232
// Architectures.
3333
type Seccomp struct {
34-
DefaultAction Action `json:"default_action"`
35-
Architectures []string `json:"architectures"`
36-
Syscalls []*Syscall `json:"syscalls"`
34+
DefaultAction Action `json:"default_action"`
35+
Architectures []string `json:"architectures"`
36+
Syscalls []*Syscall `json:"syscalls"`
37+
DefaultErrnoRet *uint `json:"default_errno_ret"`
3738
}
3839

3940
// Action is taken upon rule match in Seccomp

libcontainer/seccomp/patchbpf/enosys_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ func assemble(program []bpf.Instruction) ([]unix.SockFilter, error) {
523523
}
524524

525525
func generatePatch(config *configs.Seccomp) ([]bpf.Instruction, error) {
526+
// Patch the generated cBPF only when there is not a defaultErrnoRet set
527+
// and it is different from ENOSYS
528+
if config.DefaultErrnoRet != nil && *config.DefaultErrnoRet == uint(retErrnoEnosys) {
529+
return nil, nil
530+
}
526531
// We only add the stub if the default action is not permissive.
527532
if isAllowAction(config.DefaultAction) {
528533
logrus.Debugf("seccomp: skipping -ENOSYS stub filter generation")

libcontainer/seccomp/seccomp_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func InitSeccomp(config *configs.Seccomp) error {
3636
return errors.New("cannot initialize Seccomp - nil config passed")
3737
}
3838

39-
defaultAction, err := getAction(config.DefaultAction, nil)
39+
defaultAction, err := getAction(config.DefaultAction, config.DefaultErrnoRet)
4040
if err != nil {
4141
return errors.New("error initializing seccomp - invalid default action")
4242
}

libcontainer/specconv/spec_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ func SetupSeccomp(config *specs.LinuxSeccomp) (*configs.Seccomp, error) {
878878
return nil, err
879879
}
880880
newConfig.DefaultAction = newDefaultAction
881+
newConfig.DefaultErrnoRet = config.DefaultErrnoRet
881882

882883
// Loop through all syscall blocks and convert them to libcontainer format
883884
for _, call := range config.Syscalls {

tests/integration/seccomp.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ function teardown() {
2121
runc run test_busybox
2222
[ "$status" -eq 0 ]
2323
}
24+
25+
@test "runc run [seccomp defaultErrnoRet=ENXIO]" {
26+
TEST_NAME="seccomp_syscall_test2"
27+
28+
# Compile the test binary and update the config to run it.
29+
gcc -static -o rootfs/seccomp_test2 "${TESTDATA}/${TEST_NAME}.c"
30+
update_config ".linux.seccomp = $(<"${TESTDATA}/${TEST_NAME}.json")"
31+
update_config '.process.args = ["/seccomp_test2"]'
32+
33+
runc run test_busybox
34+
[ "$status" -eq 0 ]
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <unistd.h>
2+
#include <errno.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
int main()
7+
{
8+
if (chdir("/") < 0 && errno == ENXIO)
9+
exit(EXIT_SUCCESS);
10+
fprintf(stderr, "got errno=%m\n");
11+
exit(EXIT_FAILURE);
12+
}

0 commit comments

Comments
 (0)