carlos / platform Public

gvisor: syscall filter readback is a set contract, not one expansion

Both readbacks (instance control's and the demo build's) and
GVisorHardeningShown now hold SystemCallFilter to a contract: a
deny-list (leading ~) that denies every reviewed name (the systemd
257.13/libseccomp 2.6.0 expansion, less the stray
sys_debug_setcontext) and none of the calls runsc needs; extra denied
names are tolerated, so a systemd or libseccomp update that grows a
group no longer refuses every gVisor start. SystemCallErrorNumber stays
exactly 38. The templates drop kexec_load and kexec_file_load, already
in @reboot and still required by name. (Astra and Fable R1 P2.)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9f0ddbfd26e81d4f1f543d22a4a95512bc832260 parent c019f99
10 files changed, +145 −28
  • internal/demobuild/gvisor.go +3 −2
  • internal/demobuild/gvisor_test.go +20 −0
  • internal/execsandbox/hardening.go +69 −10
  • internal/execsandbox/hardening_test.go +22 −1
  • internal/host/gvisor_units_test.go +1 −1
  • internal/host/units/carlos-demo-build-gvisor@.service +1 −1
  • internal/host/units/carlos-instance-gvisor-probe.service +1 −1
  • internal/host/units/carlos-instance-gvisor@.service +1 −1
  • internal/instancectl/gvisorunit.go +3 −2
  • internal/instancectl/gvisorunit_seccomp_test.go +24 −9
diff --git a/internal/demobuild/gvisor.go b/internal/demobuild/gvisor.go
index f3b01b56d..56e6f9774 100644
--- a/internal/demobuild/gvisor.go
+++ b/internal/demobuild/gvisor.go
@@ -269,8 +269,9 @@ func gvisorBuildShown(out string, l buildLayout, toolchain string) error {
}
for key, want := range gvisorBuildProperties(l) {
value, ok := got[key]
- // systemd reads the IP deny back in either order.
- same := value == want || key == "IPAddressDeny" && execsandbox.GVisorHardeningShown(key, value)
+ // systemd reads the IP deny back in either order, and the syscall
+ // filter is held to its contract, not one expansion.
+ same := value == want || execsandbox.GVisorHardeningSet(key) && execsandbox.GVisorHardeningShown(key, value)
if !ok && want != "" || !same {
return fmt.Errorf("%w: %s got %q want %q present=%t", ErrBuild, key, value, want, ok)
}
diff --git a/internal/demobuild/gvisor_test.go b/internal/demobuild/gvisor_test.go
index 4ac888d2c..9ac9b4c84 100644
--- a/internal/demobuild/gvisor_test.go
+++ b/internal/demobuild/gvisor_test.go
@@ -627,6 +627,26 @@ func TestGVisorBuildRefusesUncontained(t *testing.T) {
t.Errorf("accepted an uncontained %s=%q", key, old)
}
}
+ // The syscall filter's contract (round 1): it may deny more, never less
+ // or what runsc needs, and stays a deny-list answering ENOSYS.
+ filter := gvisorBuildShownFixture(t, l)["SystemCallFilter"]
+ for value, ok := range map[string]bool{
+ filter + " a_future_obsolete_call": true,
+ strings.Replace(filter, " open_by_handle_at ", " ", 1): false,
+ strings.TrimPrefix(filter, "~"): false,
+ filter + " mount": false,
+ } {
+ p := gvisorBuildShownFixture(t, l)
+ p["SystemCallFilter"] = value
+ if err := gvisorBuildShownMap(p, l); (err == nil) != ok {
+ t.Errorf("SystemCallFilter=%.40s...: accepted %t, want %t (%v)", value, err == nil, ok, err)
+ }
+ }
+ p := gvisorBuildShownFixture(t, l)
+ p["SystemCallErrorNumber"] = "1"
+ if gvisorBuildShownMap(p, l) == nil {
+ t.Error("accepted SystemCallErrorNumber=1 (EPERM)")
+ }
}
func gvisorBuildShownMap(p map[string]string, l buildLayout) error {
diff --git a/internal/execsandbox/hardening.go b/internal/execsandbox/hardening.go
index 5cf29ca18..4a3b0a200 100644
--- a/internal/execsandbox/hardening.go
+++ b/internal/execsandbox/hardening.go
@@ -151,7 +151,9 @@ var gvisorHardening = []hardeningProperty{
// kernel module, reboot and kexec, swap, raw I/O, clock, CPU emulation,
// obsolete and keyring groups, eBPF, perf events, userfaultfd, io_uring,
// file handles and namespace joins. Not @debug or @mount.
-const gvisorSyscallDeny = "~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns"
+// kexec_load and kexec_file_load are in @reboot, and the readback
+// requires both by name.
+const gvisorSyscallDeny = "~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns"
// gvisorSyscallDenyShown is how systemd 257.13 with libseccomp 2.6.0
// shows gvisorSyscallDeny: the groups expanded, sorted, every name
@@ -159,6 +161,23 @@ const gvisorSyscallDeny = "~@module @reboot @swap @raw-io @clock @cpu-emulation
// same on amd64 (docs-t1) and arm64 (root-runner 20261129T200358-ff77a7).
const gvisorSyscallDenyShown = "~_sysctl add_key adjtimex afs_syscall bdflush bpf break clock_adjtime clock_adjtime64 clock_settime clock_settime64 create_module delete_module finit_module ftime get_kernel_syms getpmsg gtty idle init_module io_uring_enter io_uring_register io_uring_setup ioperm iopl kexec_file_load kexec_load keyctl lock modify_ldt mpx open_by_handle_at pciconfig_iobase pciconfig_read pciconfig_write perf_event_open prof profil putpmsg query_module reboot request_key s390_pci_mmio_read s390_pci_mmio_write security setns settimeofday sgetmask ssetmask stime stty subpage_prot swapoff swapon sys_debug_setcontext sysfs tuxcall ulimit uselib userfaultfd ustat vm86 vm86old vserver"
+// gvisorSyscallDenyRequired is what the readback requires the filter to
+// deny: every name gvisorSyscallDenyShown lists (the groups as reviewed,
+// expanded by systemd 257.13 and libseccomp 2.6.0), less
+// sys_debug_setcontext, a powerpc name that libseccomp's table puts in
+// the expansion though no group lists it.
+var gvisorSyscallDenyRequired = func() []string {
+ names := strings.Fields(strings.TrimPrefix(gvisorSyscallDenyShown, "~"))
+ return slices.DeleteFunc(names, func(name string) bool { return name == "sys_debug_setcontext" })
+}()
+
+// gvisorSyscallRunscNeeds are calls runsc, its gofer and sentry, and the
+// hooks make (root-runner F4_SYSCALLS) that a filter denying them would
+// break: ptrace and the mount calls (@debug, @mount), the namespace,
+// credential and seccomp setup, and openat2 for the exit hook. The
+// readback refuses a filter that denies any.
+var gvisorSyscallRunscNeeds = []string{"ptrace", "process_vm_readv", "mount", "umount2", "pivot_root", "chroot", "unshare", "clone", "clone3", "execve", "seccomp", "setuid", "setgid", "setresuid", "setresgid", "capset", "prctl", "openat", "openat2", "sendmsg", "recvmsg", "wait4", "kill", "tgkill"}
+
// gvisorCapabilities is the measured host bounding set, in kernel order
// (the order systemctl show prints them in).
var gvisorCapabilities = []string{"CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_SETGID", "CAP_SETUID", "CAP_SYS_ADMIN", "CAP_SETFCAP"}
@@ -203,19 +222,59 @@ func GVisorHardeningLines() string {
}
// GVisorHardeningShown says whether got is systemctl show's reading of the
-// pinned property name. Every property is compared exactly, except that the
-// IP deny's entries may come in either order: systemd keeps the list in a
-// hashed set, and its order changes from boot to boot.
+// pinned property name. Every property is compared exactly, except two
+// that are compared as sets (GVisorHardeningSet): the IP deny's entries
+// may come in either order, since systemd keeps the list in a hashed set
+// whose order changes from boot to boot; and the syscall filter is held
+// to its contract (gvisorSyscallFilterShown), not to one systemd's
+// expansion of its groups.
func GVisorHardeningShown(name, got string) bool {
want, ok := GVisorHardening()[name]
if !ok {
return false
}
- if name != "IPAddressDeny" {
- return got == want
+ switch name {
+ case "IPAddressDeny":
+ g, w := strings.Fields(got), strings.Fields(want)
+ slices.Sort(g)
+ slices.Sort(w)
+ return slices.Equal(g, w)
+ case "SystemCallFilter":
+ return gvisorSyscallFilterShown(got)
+ }
+ return got == want
+}
+
+// GVisorHardeningSet says whether the readback compares name as a set
+// (GVisorHardeningShown) rather than as the exact string. Both unit
+// readbacks, instance control's and the demo build's, ask it.
+func GVisorHardeningSet(name string) bool {
+ return name == "IPAddressDeny" || name == "SystemCallFilter"
+}
+
+// gvisorSyscallFilterShown is the syscall filter's readback contract
+// (gvisor follow-ups round 1): a deny-list (the leading ~) that denies
+// every name of gvisorSyscallDenyRequired and none of
+// gvisorSyscallRunscNeeds. Other denied names are tolerated: systemd
+// documents that its groups change between versions and builds, and
+// libseccomp's name table with them, so a later expansion that denies
+// more must not refuse every gVisor start; one that denies less, or
+// denies what runsc needs, still does.
+func gvisorSyscallFilterShown(got string) bool {
+ denied, ok := strings.CutPrefix(got, "~")
+ if !ok {
+ return false
+ }
+ names := strings.Fields(denied)
+ for _, name := range gvisorSyscallDenyRequired {
+ if !slices.Contains(names, name) {
+ return false
+ }
+ }
+ for _, name := range gvisorSyscallRunscNeeds {
+ if slices.Contains(names, name) {
+ return false
+ }
}
- g, w := strings.Fields(got), strings.Fields(want)
- slices.Sort(g)
- slices.Sort(w)
- return slices.Equal(g, w)
+ return true
}
diff --git a/internal/execsandbox/hardening_test.go b/internal/execsandbox/hardening_test.go
index 84c60266f..262995f32 100644
--- a/internal/execsandbox/hardening_test.go
+++ b/internal/execsandbox/hardening_test.go
@@ -40,7 +40,7 @@ func TestGVisorHardening(t *testing.T) {
t.Fatal("caller mutation changed the pinned contract")
}
const lines = "ProtectSystem=strict\nProtectHome=yes\nPrivateTmp=yes\nProtectKernelTunables=yes\nProtectKernelModules=yes\nProtectKernelLogs=yes\nProtectClock=yes\nProtectHostname=yes\nProtectControlGroups=strict\nLockPersonality=yes\nRestrictRealtime=yes\nSystemCallArchitectures=native\n" +
- "SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns\n" +
+ "SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns\n" +
"SystemCallErrorNumber=ENOSYS\n" +
"CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_SETGID CAP_SETUID CAP_SYS_ADMIN CAP_SETFCAP\n" +
"IPAddressDeny=any\n" +
@@ -92,6 +92,14 @@ func TestGVisorHostContainment(t *testing.T) {
t.Errorf("the deny-list lets %s through", refused)
}
}
+ for _, name := range gvisorSyscallDenyRequired {
+ if slices.Contains(gvisorSyscallRunscNeeds, name) {
+ t.Errorf("%s is both required denied and needed by runsc", name)
+ }
+ }
+ if !gvisorSyscallFilterShown(got["SystemCallFilter"]) {
+ t.Error("the pinned expansion does not meet its own contract")
+ }
if got["SystemCallErrorNumber"] != "38" {
t.Errorf("SystemCallErrorNumber=%q: a denied call must answer ENOSYS, not kill runsc", got["SystemCallErrorNumber"])
}
@@ -114,6 +122,19 @@ func TestGVisorHardeningShown(t *testing.T) {
{"IPAddressDeny", "0.0.0.0/0 0.0.0.0/0", false},
{"CapabilityBoundingSet", GVisorHardening()["CapabilityBoundingSet"], true},
{"CapabilityBoundingSet", "cap_setfcap cap_chown cap_dac_override cap_setgid cap_setuid cap_sys_admin", false},
+ // The syscall filter's contract (gvisor follow-ups round 1).
+ {"SystemCallFilter", GVisorHardening()["SystemCallFilter"], true},
+ {"SystemCallFilter", GVisorHardening()["SystemCallFilter"] + " a_future_obsolete_call", true},
+ {"SystemCallFilter", strings.Replace(GVisorHardening()["SystemCallFilter"], " setns ", " ", 1), false},
+ {"SystemCallFilter", strings.Replace(GVisorHardening()["SystemCallFilter"], " kexec_load ", " ", 1), false},
+ {"SystemCallFilter", strings.TrimPrefix(GVisorHardening()["SystemCallFilter"], "~"), false},
+ {"SystemCallFilter", GVisorHardening()["SystemCallFilter"] + " ptrace", false},
+ {"SystemCallFilter", GVisorHardening()["SystemCallFilter"] + " mount", false},
+ {"SystemCallFilter", "~", false},
+ {"SystemCallFilter", "", false},
+ {"SystemCallErrorNumber", "38", true},
+ {"SystemCallErrorNumber", "1", false},
+ {"SystemCallErrorNumber", "2147483646", false},
{"ProtectSystem", "strict", true},
{"ProtectSystem", "full", false},
{"Unpinned", "", false},
diff --git a/internal/host/gvisor_units_test.go b/internal/host/gvisor_units_test.go
index 6212fbc8d..65d68e3d0 100644
--- a/internal/host/gvisor_units_test.go
+++ b/internal/host/gvisor_units_test.go
@@ -23,7 +23,7 @@ ProtectControlGroups=strict
LockPersonality=yes
RestrictRealtime=yes
SystemCallArchitectures=native
-SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns
+SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns
SystemCallErrorNumber=ENOSYS
CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_SETGID CAP_SETUID CAP_SYS_ADMIN CAP_SETFCAP
IPAddressDeny=any
diff --git a/internal/host/units/carlos-demo-build-gvisor@.service b/internal/host/units/carlos-demo-build-gvisor@.service
index d70ff1ddc..d60ee6374 100644
--- a/internal/host/units/carlos-demo-build-gvisor@.service
+++ b/internal/host/units/carlos-demo-build-gvisor@.service
@@ -37,7 +37,7 @@ ProtectControlGroups=strict
LockPersonality=yes
RestrictRealtime=yes
SystemCallArchitectures=native
-SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns
+SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns
SystemCallErrorNumber=ENOSYS
CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_SETGID CAP_SETUID CAP_SYS_ADMIN CAP_SETFCAP
IPAddressDeny=any
diff --git a/internal/host/units/carlos-instance-gvisor-probe.service b/internal/host/units/carlos-instance-gvisor-probe.service
index 251b404e2..c1625d0ce 100644
--- a/internal/host/units/carlos-instance-gvisor-probe.service
+++ b/internal/host/units/carlos-instance-gvisor-probe.service
@@ -36,7 +36,7 @@ ProtectControlGroups=strict
LockPersonality=yes
RestrictRealtime=yes
SystemCallArchitectures=native
-SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns
+SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns
SystemCallErrorNumber=ENOSYS
CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_SETGID CAP_SETUID CAP_SYS_ADMIN CAP_SETFCAP
IPAddressDeny=any
diff --git a/internal/host/units/carlos-instance-gvisor@.service b/internal/host/units/carlos-instance-gvisor@.service
index 8261facae..e0c682aa3 100644
--- a/internal/host/units/carlos-instance-gvisor@.service
+++ b/internal/host/units/carlos-instance-gvisor@.service
@@ -35,7 +35,7 @@ ProtectControlGroups=strict
LockPersonality=yes
RestrictRealtime=yes
SystemCallArchitectures=native
-SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at kexec_load kexec_file_load setns
+SystemCallFilter=~@module @reboot @swap @raw-io @clock @cpu-emulation @obsolete @keyring bpf perf_event_open userfaultfd io_uring_setup io_uring_enter io_uring_register open_by_handle_at setns
SystemCallErrorNumber=ENOSYS
CapabilityBoundingSet=CAP_CHOWN CAP_DAC_OVERRIDE CAP_SETGID CAP_SETUID CAP_SYS_ADMIN CAP_SETFCAP
IPAddressDeny=any
diff --git a/internal/instancectl/gvisorunit.go b/internal/instancectl/gvisorunit.go
index 41b6a8f4d..392f793d9 100644
--- a/internal/instancectl/gvisorunit.go
+++ b/internal/instancectl/gvisorunit.go
@@ -231,8 +231,9 @@ func gvisorUnitShown(out, host string, role Role, pin execsandbox.RunscPin, layo
if want == "" && value != "" {
return fmt.Errorf("%w: %s", execsandbox.ErrRunsc, key)
}
- } else if value != want && !(key == "IPAddressDeny" && execsandbox.GVisorHardeningShown(key, value)) {
- // systemd reads the IP deny back in either order.
+ } else if value != want && !(execsandbox.GVisorHardeningSet(key) && execsandbox.GVisorHardeningShown(key, value)) {
+ // systemd reads the IP deny back in either order, and the
+ // syscall filter is held to its contract, not one expansion.
return fmt.Errorf("%w: %s", execsandbox.ErrRunsc, key)
}
}
diff --git a/internal/instancectl/gvisorunit_seccomp_test.go b/internal/instancectl/gvisorunit_seccomp_test.go
index f69a5825a..5c2c90c84 100644
--- a/internal/instancectl/gvisorunit_seccomp_test.go
+++ b/internal/instancectl/gvisorunit_seccomp_test.go
@@ -9,9 +9,10 @@ import (
)
// A run or probe unit without the syscall deny-list (gvisor follow-ups) is
-// refused at readback: as systemd 257 shows a unit with no filter, and
-// with the filter but its default action, which kills runsc on its first
-// denied call instead of answering ENOSYS.
+// refused at readback: as systemd 257 shows a unit with no filter, with
+// the default action (which kills runsc on its first denied call instead
+// of answering ENOSYS) or EPERM, missing a required name, as an
+// allow-list, or denying what runsc needs. One that denies more passes.
func TestGVisorUnitRefusesUnfiltered(t *testing.T) {
pin, _ := execsandbox.RunscFor(runtime.GOOS + "-" + runtime.GOARCH)
for _, role := range []Role{RoleRun, roleProbe} {
@@ -24,14 +25,28 @@ func TestGVisorUnitRefusesUnfiltered(t *testing.T) {
t.Fatal(err)
}
shown := parseShow(valid)
- for key, unfiltered := range map[string]string{"SystemCallFilter": "~", "SystemCallErrorNumber": "2147483646"} {
- bad := valid + "\n" + key + "=" + unfiltered
- if value, ok := shown[key]; ok {
- bad = strings.Replace(valid, key+"="+value, key+"="+unfiltered, 1)
+ filter := shown["SystemCallFilter"]
+ with := func(key, value string) string {
+ if old, ok := shown[key]; ok {
+ return strings.Replace(valid, key+"="+old, key+"="+value, 1)
}
- if gvisorUnitShown(bad, host, role, pin, gvisorTestLayout(t, host, role)) == nil {
- t.Errorf("%s: accepted %s=%s", role, key, unfiltered)
+ return valid + "\n" + key + "=" + value
+ }
+ for _, c := range []struct{ key, value string }{
+ {"SystemCallFilter", "~"},
+ {"SystemCallErrorNumber", "2147483646"},
+ {"SystemCallErrorNumber", "1"},
+ {"SystemCallFilter", strings.Replace(filter, " bpf ", " ", 1)},
+ {"SystemCallFilter", strings.TrimPrefix(filter, "~")},
+ {"SystemCallFilter", filter + " ptrace"},
+ } {
+ if gvisorUnitShown(with(c.key, c.value), host, role, pin, gvisorTestLayout(t, host, role)) == nil {
+ t.Errorf("%s: accepted %s=%.40s...", role, c.key, c.value)
}
}
+ // A later systemd that denies more is accepted (round 1).
+ if err := gvisorUnitShown(with("SystemCallFilter", filter+" a_future_obsolete_call"), host, role, pin, gvisorTestLayout(t, host, role)); err != nil {
+ t.Errorf("%s: refused a filter denying more: %v", role, err)
+ }
}
}