diff --git a/seccomp/default.json b/seccomp/default.json index 648d00d..ea5a494 100644 --- a/seccomp/default.json +++ b/seccomp/default.json @@ -436,6 +436,32 @@ "minKernel": "4.8" } }, + { + "names": [ + "socket" + ], + "action": "SCMP_ACT_ALLOW", + "args": [ + { + "index": 0, + "value": 38, + "op": "SCMP_CMP_LT" + } + ] + }, + { + "names": [ + "socket" + ], + "action": "SCMP_ACT_ALLOW", + "args": [ + { + "index": 0, + "value": 39, + "op": "SCMP_CMP_EQ" + } + ] + }, { "names": [ "socket" @@ -445,7 +471,7 @@ { "index": 0, "value": 40, - "op": "SCMP_CMP_NE" + "op": "SCMP_CMP_GT" } ] }, diff --git a/seccomp/default_linux.go b/seccomp/default_linux.go index f481f08..75f392b 100644 --- a/seccomp/default_linux.go +++ b/seccomp/default_linux.go @@ -8,6 +8,14 @@ import ( "golang.org/x/sys/unix" ) +// The socket rules in DefaultProfile rely on AF_ALG and AF_VSOCK being +// exactly two apart (38 and 40), with a single family (39) between them. +var ( + _ [38]byte = [unix.AF_ALG]byte{} + _ [40]byte = [unix.AF_VSOCK]byte{} + _ [1]byte = [unix.AF_VSOCK - unix.AF_ALG - 1]byte{} +) + func arches() []Architecture { return []Architecture{ { @@ -434,6 +442,38 @@ func DefaultProfile() *Seccomp { MinKernel: &KernelVersion{4, 8}, }, }, + // Allow socket(2) for all address families except AF_VSOCK and AF_ALG. + // NOTE: on 32-bit x86, socket() goes through socketcall(2) which is + // allowed unconditionally above, so AF_VSOCK/AF_ALG is still reachable + // via the socketcall-based socket() path. These arg filters only apply + // to the direct socket syscall, and do not protect 32-bit x86 unless + // socketcall(2) is also addressed. + { + LinuxSyscall: specs.LinuxSyscall{ + Names: []string{"socket"}, + Action: specs.ActAllow, + Args: []specs.LinuxSeccompArg{ + { + Index: 0, + Value: unix.AF_ALG, + Op: specs.OpLessThan, + }, + }, + }, + }, + { + LinuxSyscall: specs.LinuxSyscall{ + Names: []string{"socket"}, + Action: specs.ActAllow, + Args: []specs.LinuxSeccompArg{ + { + Index: 0, + Value: unix.AF_ALG + 1, + Op: specs.OpEqualTo, + }, + }, + }, + }, { LinuxSyscall: specs.LinuxSyscall{ Names: []string{"socket"}, @@ -442,7 +482,7 @@ func DefaultProfile() *Seccomp { { Index: 0, Value: unix.AF_VSOCK, - Op: specs.OpNotEqual, + Op: specs.OpGreaterThan, }, }, },