instances: tenant syscall filter (#527 Q5)
SystemCallFilter=@system-service less io_uring, the keyring and userfaultfd, answering ENOSYS, on every tenant unit; both probes check it from inside behind a unit-advertised env var.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 files changed,
+525
−2
docs/superpowers/plans/2026-11-08-instance-syscall-filter.md+24 −0docs/superpowers/specs/2026-11-08-instance-syscall-filter-design.md+96 −0internal/host/claimunit_template.go+3 −0internal/host/demo_snapshot_test.go+11 −0internal/host/units/carlos-demo-build@.service+4 −0internal/host/units/carlos-demo-snapshot@.service+4 −0internal/host/units/carlos-instance-cmd@.service+12 −0internal/host/units/carlos-instance-gen@.service+12 −0internal/host/units/carlos-instance-probe.service+17 −0internal/host/units/carlos-instance-rootfs-cmd@.service+12 −0internal/host/units/carlos-instance-rootfs-gen@.service+12 −0internal/host/units/carlos-instance-rootfs-probe.service+17 −0internal/host/units/carlos-instance-rootfs-tty@.service+12 −0internal/host/units/carlos-instance-rootfs-worker@.service+12 −0internal/host/units/carlos-instance-rootfs@.service+12 −0internal/host/units/carlos-instance-seed@.service+12 −0internal/host/units/carlos-instance-sidecar@.service+12 −0internal/host/units/carlos-instance-tty@.service+12 −0internal/host/units/carlos-instance@.service+12 −0internal/host/units_hardening_test.go+58 −0internal/host/units_isolation_test.go+30 −0internal/instancectl/names.go+7 −0internal/instanceexec/probe.go+11 −0internal/instanceexec/probe_hardening.go+29 −0internal/instanceexec/probe_hardening_linux.go+27 −0internal/instanceexec/probe_hardening_other.go+4 −0internal/instanceexec/probe_rootfs_test.go+1 −1internal/instanceexec/probe_test.go+50 −1
diff --git a/docs/superpowers/plans/2026-11-08-instance-syscall-filter.md b/docs/superpowers/plans/2026-11-08-instance-syscall-filter.md| new file mode 100644 |
| index 000000000..04d15fbcc |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-08-instance-syscall-filter.md |
| @@ -0,0 +1,24 @@ |
| +# Plan: instance syscall filter (#527 Q5) |
| + |
| +Spec: `docs/superpowers/specs/2026-11-08-instance-syscall-filter-design.md`. |
| +Branch `instance-syscall-filter` from origin/main 1751f78f. |
| + |
| +1. Unit test `TestTenantUnitsCarryTheSyscallFilter` (internal/host): the |
| + three lines on the 15 tenant unit files and `claimBoundTemplate`, no |
| + other syscall-shaping line. Then the lines, in the shared binary block, |
| + the shared rootfs block, both demo units and the claim template. The |
| + snapshot unit contract test learns that `SystemCallFilter` is the one |
| + list-valued key. |
| +2. Probe line `syscall-filter` (internal/instanceexec): seams |
| + `ioUringSetup`, `keyctl`, gated on `ProbeSyscallFilterEnv`; both probe |
| + units set it outside their shared blocks |
| + (`TestBothProbesAdvertiseTheSyscallFilter`). Table test |
| + `TestProbeSyscallFilterLine`. |
| +3. Root-runner witness `TestRootSyscallFilterRuntimes` |
| + (internal/host, `linux && rootrunner`): the embedded template's |
| + hardening on transient units running Go, Node (UV_USE_IO_URING=1), |
| + Python, Ruby and PHP, each serving over a unix socket; io_uring_setup |
| + and keyctl ENOSYS, openat2 and the Landlock ABI query working inside. |
| +4. Census: `make census-card`, CLAIMS, `make census-propose |
| + NAME=instance-syscall-filter`, Astra cross-family verdict on #280. |
| +5. Astra review (max three rounds), CI green on the tip, squash merge. |
diff --git a/docs/superpowers/specs/2026-11-08-instance-syscall-filter-design.md b/docs/superpowers/specs/2026-11-08-instance-syscall-filter-design.md| new file mode 100644 |
| index 000000000..f8546f53c |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-08-instance-syscall-filter-design.md |
| @@ -0,0 +1,96 @@ |
| +# Instance syscall filter (#527 Q5) |
| + |
| +Status: rev 1, 2026-11-08. Pre-launch hardening for the /start demo; Paul |
| +ruled it must land before anonymous demo code runs on flagship. |
| + |
| +## Problem |
| + |
| +The gVisor spike (2026-11-07, #527) found that no tenant unit the platform |
| +writes carries `SystemCallFilter=`. A tenant reaches every syscall the host |
| +kernel offers that its capabilities (none) and namespaces do not already |
| +refuse. The native probe got `io_uring_setup: ok`. io_uring is the largest |
| +single piece of that surface and a repeat source of local privilege |
| +escalations; the kernel keyring and userfaultfd are smaller but have the |
| +same history. None of our supported runtimes needs any of them. |
| + |
| +## Change |
| + |
| +Every tenant unit gets one syscall block, placed after |
| +`SystemCallArchitectures=native` (already on all of them): |
| + |
| +``` |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| +``` |
| + |
| +- `@system-service` is systemd's own baseline allow-list for ordinary |
| + services; the edge, dbread and devbox units already run under it. It |
| + leaves out what needs capabilities an instance does not have (mount, |
| + bpf, module and clock calls, chroot, pivot_root), plus ptrace, |
| + perf_event_open, fanotify and similar. |
| +- The `~` line takes io_uring, the keyring calls (`add_key`, `keyctl`, |
| + `request_key`) and userfaultfd back out of the allow-list. Legacy AIO |
| + (`io_setup`, `io_submit`) stays: some databases use it, and it has none |
| + of io_uring's history. |
| +- `ENOSYS`, not `EPERM` and not the default SIGSYS kill: a refused call |
| + looks like a kernel without it, which is the fallback path every runtime |
| + already has (libuv falls back from io_uring to its thread pool, glibc |
| + falls back on ENOSYS). A kill would take a tenant down for probing. |
| +- openat2 stays allowed: `@system-service` includes `@file-system`, which |
| + lists it, and an allow-list does not inspect arguments. The 2026-11-06 |
| + lesson was `RestrictSUIDSGID=`, which filters on `open_how` contents and |
| + so refuses openat2 outright. The block adds no such argument filter. |
| +- The trampoline's own needs are in the list: Landlock |
| + (`landlock_*`), `seccomp` (the claim generation filter), `prctl`, |
| + `pidfd_*` except `pidfd_getfd`, `clone3`, `openat2`. |
| + |
| +Units covered (all units that run tenant or anonymous code): |
| + |
| +- the seven binary templates and the binary probe (one namespace block, |
| + byte-identical, so the line goes in the shared block); |
| +- the six rootfs units (one restated rootfs block, byte-identical); |
| +- `carlos-demo-build@` and `carlos-demo-snapshot@` (anonymous source and |
| + its data); |
| +- `claimBoundTemplate` (claim generation units already add their own |
| + narrower filter in the trampoline; this makes the unit match). |
| + |
| +Not covered: `carlos-app@` (the legacy DynamicUser template for |
| +operator-run, single-process tenants; out of scope for the demo and a |
| +behaviour change for self-hosters), the platform's own services, and |
| +capability units rendered by `internal/caps`. |
| + |
| +The JIT drop-in (rootfs `jit` manifests) lifts `MemoryDenyWriteExecute` |
| +only; it does not touch the filter. |
| + |
| +## Proof |
| + |
| +1. Unit tests pin the three lines on every covered unit, and refuse a |
| + second `SystemCallFilter=` allow-list or any argument-inspecting |
| + setting (`RestrictSUIDSGID=`) in the shared blocks. |
| +2. Both probes (binary and rootfs) gain a `syscall-filter` line: it fails |
| + unless `io_uring_setup` and `keyctl` both answer ENOSYS inside the |
| + unit. `keyctl` is the presence check: it succeeds for an |
| + unprivileged process on any kernel with keys, so a refusal proves the |
| + filter is in force, while io_uring alone could be refused by |
| + `kernel.io_uring_disabled`. A box whose probe fails this line refuses |
| + readiness like any other failed probe line, so the property is |
| + re-checked on every box at every probe run. A roll replaces the binary |
| + before the units, so the line is enforced only under a probe unit that |
| + says `Environment=CARLOS_PROBE_SYSCALL_FILTER=1` and is `unverified` |
| + otherwise, the pattern the pts-private line set. |
| +3. Root-runner witness (dev, throwaway arm64): the embedded |
| + `carlos-instance@.service` hardening, filter included, applied to a |
| + transient unit running each supported runtime (Go, Node with libuv's |
| + io_uring forced on, Python, Ruby, PHP) serving HTTP on a unix socket; |
| + each must serve, and inside the unit `io_uring_setup` and `keyctl` must |
| + answer ENOSYS while `openat2` and Landlock's ABI query work. Static |
| + sites are served by the edge and run no instance unit, so they are out |
| + of the witness. |
| + |
| +## Rollout |
| + |
| +The units ship embedded in the binary and are installed by the roll, so |
| +the probe and the filter arrive together. No flag: the filter is on for |
| +every instance at the first start after the roll. The rollback is the |
| +previous release. |
diff --git a/internal/host/claimunit_template.go b/internal/host/claimunit_template.go| index 62de03963..ed39bd6fe 100644 |
| --- a/internal/host/claimunit_template.go |
| +++ b/internal/host/claimunit_template.go |
| @@ -57,6 +57,9 @@ LockPersonality=yes |
| RestrictRealtime=yes |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| TasksMax=256 |
| OOMScoreAdjust=500 |
diff --git a/internal/host/demo_snapshot_test.go b/internal/host/demo_snapshot_test.go| index db431ab2f..afd189353 100644 |
| --- a/internal/host/demo_snapshot_test.go |
| +++ b/internal/host/demo_snapshot_test.go |
| @@ -17,6 +17,7 @@ func TestDemoClaimSnapshotUnitContract(t *testing.T) { |
| t.Fatal(err) |
| } |
| props := map[string]string{} |
| + var filters []string |
| section := "" |
| for _, line := range strings.Split(string(b), "\n") { |
| line = strings.TrimSpace(line) |
| @@ -32,6 +33,12 @@ func TestDemoClaimSnapshotUnitContract(t *testing.T) { |
| t.Fatalf("bad unit line %q", line) |
| } |
| key := section + "/" + k |
| + // The one list-valued key: an allow-list, then what it takes back |
| + // out (#527 Q5). Checked in order below. |
| + if key == "[Service]/SystemCallFilter" { |
| + filters = append(filters, v) |
| + continue |
| + } |
| if _, exists := props[key]; exists { |
| t.Fatalf("duplicate %s", key) |
| } |
| @@ -54,6 +61,10 @@ func TestDemoClaimSnapshotUnitContract(t *testing.T) { |
| "ProtectControlGroups": "yes", "ProtectProc": "invisible", "ProcSubset": "pid", |
| "ProtectKernelTunables": "yes", "ProtectKernelModules": "yes", "ProtectKernelLogs": "yes", "ProtectClock": "yes", "ProtectHostname": "yes", |
| "RemoveIPC": "yes", "LockPersonality": "yes", "RestrictRealtime": "yes", "MemoryDenyWriteExecute": "yes", "SystemCallArchitectures": "native", |
| + "SystemCallErrorNumber": "ENOSYS", |
| + } |
| + if strings.Join(filters, "\n") != "@system-service\n~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd" { |
| + t.Errorf("SystemCallFilter lines = %q", filters) |
| } |
| for key := range props { |
| if name, ok := strings.CutPrefix(key, "[Service]/"); ok { |
diff --git a/internal/host/units/carlos-demo-build@.service b/internal/host/units/carlos-demo-build@.service| index 112afcc2f..65ff1ab85 100644 |
| --- a/internal/host/units/carlos-demo-build@.service |
| +++ b/internal/host/units/carlos-demo-build@.service |
| @@ -61,3 +61,7 @@ LockPersonality=yes |
| RestrictRealtime=yes |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant syscall surface (#527 Q5; see carlos-instance@.service). |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
diff --git a/internal/host/units/carlos-demo-snapshot@.service b/internal/host/units/carlos-demo-snapshot@.service| index a9a63d6ea..95c81d3fc 100644 |
| --- a/internal/host/units/carlos-demo-snapshot@.service |
| +++ b/internal/host/units/carlos-demo-snapshot@.service |
| @@ -59,3 +59,7 @@ LockPersonality=yes |
| RestrictRealtime=yes |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant syscall surface (#527 Q5; see carlos-instance@.service). |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
diff --git a/internal/host/units/carlos-instance-cmd@.service b/internal/host/units/carlos-instance-cmd@.service| index 040660163..364976f52 100644 |
| --- a/internal/host/units/carlos-instance-cmd@.service |
| +++ b/internal/host/units/carlos-instance-cmd@.service |
| @@ -164,6 +164,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-gen@.service b/internal/host/units/carlos-instance-gen@.service| index a0b3a263e..cb8707654 100644 |
| --- a/internal/host/units/carlos-instance-gen@.service |
| +++ b/internal/host/units/carlos-instance-gen@.service |
| @@ -146,6 +146,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-probe.service b/internal/host/units/carlos-instance-probe.service| index 540dad33e..efe56e7f5 100644 |
| --- a/internal/host/units/carlos-instance-probe.service |
| +++ b/internal/host/units/carlos-instance-probe.service |
| @@ -39,6 +39,11 @@ BindReadOnlyPaths=/run/carlos-control/exe/_probe/box-addrs:/opt/carlos/box-addrs |
| # a new probe can run under an old probe unit, and it enforces its |
| # pts-private line only when this is set (instancectl.ProbePtsPrivateEnv). |
| Environment=CARLOS_PROBE_PTS_PRIVATE=1 |
| +# This unit carries the tenant syscall filter (below) and says so: a roll |
| +# replaces the binary before it installs the units, so a new probe can run |
| +# under an old probe unit, and it enforces its syscall-filter line only |
| +# when this is set (instancectl.ProbeSyscallFilterEnv, #527 Q5). |
| +Environment=CARLOS_PROBE_SYSCALL_FILTER=1 |
| # --- the namespace (titogo@.service, 2026-07-31 design, on systemd 257) --- |
| ProtectSystem=strict |
| @@ -145,6 +150,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=64 |
diff --git a/internal/host/units/carlos-instance-rootfs-cmd@.service b/internal/host/units/carlos-instance-rootfs-cmd@.service| index a85ff7570..205ed6eb1 100644 |
| --- a/internal/host/units/carlos-instance-rootfs-cmd@.service |
| +++ b/internal/host/units/carlos-instance-rootfs-cmd@.service |
| @@ -253,6 +253,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-rootfs-gen@.service b/internal/host/units/carlos-instance-rootfs-gen@.service| index 540b519fe..61f43a960 100644 |
| --- a/internal/host/units/carlos-instance-rootfs-gen@.service |
| +++ b/internal/host/units/carlos-instance-rootfs-gen@.service |
| @@ -233,6 +233,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-rootfs-probe.service b/internal/host/units/carlos-instance-rootfs-probe.service| index 81e54e784..5f0291152 100644 |
| --- a/internal/host/units/carlos-instance-rootfs-probe.service |
| +++ b/internal/host/units/carlos-instance-rootfs-probe.service |
| @@ -24,6 +24,11 @@ Slice=carlos-instances.slice |
| StandardOutput=truncate:/run/carlos-control/rootfs-probe.out |
| StandardError=journal |
| TimeoutStartSec=30 |
| +# This unit carries the tenant syscall filter (below) and says so: a roll |
| +# replaces the binary before it installs the units, so a new probe can run |
| +# under an old probe unit, and it enforces its syscall-filter line only |
| +# when this is set (instancectl.ProbeSyscallFilterEnv, #527 Q5). |
| +Environment=CARLOS_PROBE_SYSCALL_FILTER=1 |
| # The instance's own two directories, the only writable data paths. |
| BindPaths=/data/instances/_probe /run/carlos/instances/_probe |
| ReadWritePaths=/data/instances/_probe /run/carlos/instances/_probe |
| @@ -225,6 +230,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=64 |
diff --git a/internal/host/units/carlos-instance-rootfs-tty@.service b/internal/host/units/carlos-instance-rootfs-tty@.service| index f2d048cd3..06232d086 100644 |
| --- a/internal/host/units/carlos-instance-rootfs-tty@.service |
| +++ b/internal/host/units/carlos-instance-rootfs-tty@.service |
| @@ -257,6 +257,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-rootfs-worker@.service b/internal/host/units/carlos-instance-rootfs-worker@.service| index 270142e6a..1ef4735ae 100644 |
| --- a/internal/host/units/carlos-instance-rootfs-worker@.service |
| +++ b/internal/host/units/carlos-instance-rootfs-worker@.service |
| @@ -245,6 +245,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-rootfs@.service b/internal/host/units/carlos-instance-rootfs@.service| index 3cb29f5b0..088bd51ae 100644 |
| --- a/internal/host/units/carlos-instance-rootfs@.service |
| +++ b/internal/host/units/carlos-instance-rootfs@.service |
| @@ -275,6 +275,18 @@ RestrictRealtime=yes |
| # seccomp fallback). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-seed@.service b/internal/host/units/carlos-instance-seed@.service| index 72f162fd8..11152d49a 100644 |
| --- a/internal/host/units/carlos-instance-seed@.service |
| +++ b/internal/host/units/carlos-instance-seed@.service |
| @@ -174,6 +174,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-sidecar@.service b/internal/host/units/carlos-instance-sidecar@.service| index befa84c4a..24046330a 100644 |
| --- a/internal/host/units/carlos-instance-sidecar@.service |
| +++ b/internal/host/units/carlos-instance-sidecar@.service |
| @@ -173,6 +173,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance-tty@.service b/internal/host/units/carlos-instance-tty@.service| index 168f4e195..094ca5cb8 100644 |
| --- a/internal/host/units/carlos-instance-tty@.service |
| +++ b/internal/host/units/carlos-instance-tty@.service |
| @@ -168,6 +168,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units/carlos-instance@.service b/internal/host/units/carlos-instance@.service| index 750d06d33..1e093f647 100644 |
| --- a/internal/host/units/carlos-instance@.service |
| +++ b/internal/host/units/carlos-instance@.service |
| @@ -173,6 +173,18 @@ RestrictRealtime=yes |
| # directory). |
| MemoryDenyWriteExecute=yes |
| SystemCallArchitectures=native |
| +# The tenant's syscall surface (#527 Q5): systemd's baseline for an |
| +# ordinary service, less io_uring, the kernel keyring and userfaultfd, |
| +# which no supported runtime needs and which carry most of the recent |
| +# local privilege escalations. A refused call answers ENOSYS, as a kernel |
| +# without it would, so runtimes take the fallback they already have |
| +# (libuv's thread pool for io_uring) rather than being killed. openat2 is |
| +# in @system-service and an allow-list never reads arguments, so instancefs |
| +# is untouched (unlike RestrictSUIDSGID=, above). The probes' syscall-filter |
| +# line checks it from inside. |
| +SystemCallFilter=@system-service |
| +SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd |
| +SystemCallErrorNumber=ENOSYS |
| # --- per-service resources; the tier lives on the host slice (§4.3) --- |
| TasksMax=256 |
diff --git a/internal/host/units_hardening_test.go b/internal/host/units_hardening_test.go| index 338f07ab9..6b28cd9b9 100644 |
| --- a/internal/host/units_hardening_test.go |
| +++ b/internal/host/units_hardening_test.go |
| @@ -212,3 +212,61 @@ func TestAppTemplateSeesOnlyItsOwnBuild(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// syscallBlock is the tenant syscall surface (#527 Q5): systemd's service |
| +// baseline, less io_uring, the kernel keyring and userfaultfd, refused as |
| +// a kernel without them would refuse them. |
| +var syscallBlock = []string{ |
| + "SystemCallFilter=@system-service", |
| + "SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd", |
| + "SystemCallErrorNumber=ENOSYS", |
| + "SystemCallArchitectures=native", |
| +} |
| + |
| +// Every unit that runs tenant or anonymous code carries the block, and |
| +// nothing else that shapes the filter: a second allow-list would replace |
| +// the first, and RestrictSUIDSGID= filters on openat2's open_how, which |
| +// breaks every instancefs open (#126). |
| +func TestTenantUnitsCarryTheSyscallFilter(t *testing.T) { |
| + units := map[string]string{"claimBoundTemplate": claimBoundTemplate} |
| + for _, name := range []string{ |
| + "carlos-instance@.service", "carlos-instance-gen@.service", "carlos-instance-seed@.service", "carlos-instance-sidecar@.service", |
| + "carlos-instance-cmd@.service", "carlos-instance-tty@.service", "carlos-instance-probe.service", |
| + "carlos-instance-rootfs@.service", "carlos-instance-rootfs-cmd@.service", "carlos-instance-rootfs-gen@.service", |
| + "carlos-instance-rootfs-probe.service", "carlos-instance-rootfs-tty@.service", "carlos-instance-rootfs-worker@.service", |
| + "carlos-demo-build@.service", "carlos-demo-snapshot@.service", |
| + } { |
| + units[name] = readUnit(t, name) |
| + } |
| + allowed := map[string]bool{} |
| + for _, d := range syscallBlock { |
| + allowed[d] = true |
| + } |
| + for name, u := range units { |
| + for _, want := range syscallBlock { |
| + if !hasDirective(u, want) { |
| + t.Errorf("%s lacks %q", name, want) |
| + } |
| + } |
| + for _, d := range directives(u) { |
| + key, _, _ := strings.Cut(d, "=") |
| + switch key { |
| + case "SystemCallFilter", "SystemCallErrorNumber", "SystemCallArchitectures", "SystemCallLog": |
| + if !allowed[d] { |
| + t.Errorf("%s carries %q beside the tenant syscall block", name, d) |
| + } |
| + } |
| + } |
| + } |
| + // The demo build and snapshot units are DynamicUser, which implies |
| + // RestrictSUIDSGID=; they open no instancefs path. Everywhere else it |
| + // is refused (TestInstanceTemplatesShareOneNamespace pins the binary |
| + // block; this pins the rest). |
| + for _, name := range []string{"claimBoundTemplate", "carlos-instance-rootfs@.service", "carlos-instance-rootfs-probe.service"} { |
| + for _, d := range directives(units[name]) { |
| + if strings.HasPrefix(d, "RestrictSUIDSGID=") { |
| + t.Errorf("%s carries %q, which breaks openat2", name, d) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/host/units_isolation_test.go b/internal/host/units_isolation_test.go| index 867706119..9b7d8b114 100644 |
| --- a/internal/host/units_isolation_test.go |
| +++ b/internal/host/units_isolation_test.go |
| @@ -512,6 +512,36 @@ func TestOnlyTheBinaryProbeAdvertisesPtsPrivate(t *testing.T) { |
| } |
| } |
| +// Both probes advertise the tenant syscall filter (#527 Q5), outside their |
| +// shared blocks, and carry it; no tenant unit advertises anything. |
| +func TestBothProbesAdvertiseTheSyscallFilter(t *testing.T) { |
| + want := "Environment=" + instancectl.ProbeSyscallFilterEnv + "=1" |
| + for name, marks := range map[string][2]string{ |
| + "carlos-instance-probe.service": {"# --- the namespace", "# --- per-service resources"}, |
| + "carlos-instance-rootfs-probe.service": {rootfsBlockStart, "# --- per-service resources"}, |
| + } { |
| + u := readUnit(t, name) |
| + if n := strings.Count("\n"+u, "\n"+want+"\n"); n != 1 { |
| + t.Errorf("%s carries %q %d times, want 1", name, want, n) |
| + } |
| + start, end := strings.Index(u, marks[0]), strings.Index(u, marks[1]) |
| + if i := strings.Index(u, want); start < 0 || end < 0 || (i > start && i < end) { |
| + t.Errorf("%s: the advertisement is inside the shared block", name) |
| + } |
| + for _, d := range syscallBlock { |
| + if !hasDirective(u, d) { |
| + t.Errorf("%s advertises the syscall filter and lacks %q", name, d) |
| + } |
| + } |
| + } |
| + for _, name := range []string{"carlos-instance@.service", "carlos-instance-gen@.service", "carlos-instance-seed@.service", "carlos-instance-sidecar@.service", "carlos-instance-cmd@.service", "carlos-instance-tty@.service", |
| + "carlos-instance-rootfs@.service", "carlos-instance-rootfs-gen@.service", "carlos-instance-rootfs-worker@.service", "carlos-instance-rootfs-cmd@.service", "carlos-instance-rootfs-tty@.service"} { |
| + if strings.Contains(readUnit(t, name), instancectl.ProbeSyscallFilterEnv) { |
| + t.Errorf("%s carries %s; only the probes advertise it", name, instancectl.ProbeSyscallFilterEnv) |
| + } |
| + } |
| +} |
| + |
| // unitDirectives is a unit's directives in order: comments and blank lines |
| // dropped, each line trimmed. |
| func unitDirectives(t *testing.T, name string) []string { |
diff --git a/internal/instancectl/names.go b/internal/instancectl/names.go| index 5ca31391b..9c0403bb2 100644 |
| --- a/internal/instancectl/names.go |
| +++ b/internal/instancectl/names.go |
| @@ -571,6 +571,13 @@ const ( |
| // (rootfs Plan 6, Task 5 fix round 1). The rootfs probe always enforces. |
| const ProbePtsPrivateEnv = "CARLOS_PROBE_PTS_PRIVATE" |
| +// ProbeSyscallFilterEnv is both probe units' advertisement that they carry |
| +// the tenant syscall filter (#527 Q5): Environment=CARLOS_PROBE_SYSCALL_FILTER=1, |
| +// outside the shared blocks. As with ProbePtsPrivateEnv, a roll can run a |
| +// new probe under an old unit, so the syscall-filter line is enforced only |
| +// when the unit says "1" and is unverified otherwise. |
| +const ProbeSyscallFilterEnv = "CARLOS_PROBE_SYSCALL_FILTER" |
| + |
| // RootfsProbeMarker is the file at the root of the probe image |
| // (BuildProbeImage): the rootfs probe's root-image line finds it there |
| // when its root is that image and not the host's or another's. |
diff --git a/internal/instanceexec/probe.go b/internal/instanceexec/probe.go| index 6ff4134cb..7e6644b6e 100644 |
| --- a/internal/instanceexec/probe.go |
| +++ b/internal/instanceexec/probe.go |
| @@ -90,6 +90,13 @@ type probeEnv struct { |
| // once (R11): MemoryDenyWriteExecute=yes must refuse it, in both |
| // probes, which never get the jit drop-in. |
| mmapWX func() error |
| + // syscallFilterEnforced is the probe unit's advertisement that it |
| + // carries the tenant syscall filter (instancectl.ProbeSyscallFilterEnv, |
| + // #527 Q5); ioUringSetup and keyctl make the two calls the |
| + // syscall-filter line asks about, each returning the bare errno. |
| + syscallFilterEnforced bool |
| + ioUringSetup func() error |
| + keyctl func() error |
| } |
| // cgroupMountpoint is the fixed system path the cgroup-ro-mount check |
| @@ -157,6 +164,10 @@ func productionProbeEnv() probeEnv { |
| boxAddrs: instancectl.BoxAddrsPath, |
| mmapWX: realMmapWX, |
| + |
| + syscallFilterEnforced: os.Getenv(instancectl.ProbeSyscallFilterEnv) == "1", |
| + ioUringSetup: realIOUringSetup, |
| + keyctl: realKeyctl, |
| } |
| } |
diff --git a/internal/instanceexec/probe_hardening.go b/internal/instanceexec/probe_hardening.go| index 0dabf5f39..16ab95f04 100644 |
| --- a/internal/instanceexec/probe_hardening.go |
| +++ b/internal/instanceexec/probe_hardening.go |
| @@ -147,6 +147,14 @@ func networkAndIPCChecks(e probeEnv, add func(check, verdict, detail string), pa |
| md, mok := mdweHeld(e) |
| pass("mdwe", md, mok) |
| + // #527 Q5: the tenant syscall filter is in force. |
| + if e.syscallFilterEnforced { |
| + sd, sok := syscallFilterHeld(e) |
| + pass("syscall-filter", sd, sok) |
| + } else { |
| + add("syscall-filter", "unverified", "the probe unit does not set "+instancectl.ProbeSyscallFilterEnv+"=1 (installed before the syscall filter); not checked") |
| + } |
| + |
| // #367: the box's own addresses are closed, as the private ranges are. |
| bv, bd := boxAddrClosed(e) |
| add("box-addr", bv, bd) |
| @@ -203,6 +211,27 @@ func mdweHeld(e probeEnv) (detail string, ok bool) { |
| return fmt.Sprintf("mmap(PROT_WRITE|PROT_EXEC) = %v", err), false |
| } |
| +// syscallFilterHeld is the syscall-filter line (#527 Q5): io_uring_setup |
| +// and keyctl both answer ENOSYS, the units' SystemCallErrorNumber=, so the |
| +// filter is in force. keyctl is the presence check: it reaches the kernel |
| +// for any unprivileged process on a kernel with keys, so an io_uring |
| +// refused only by kernel.io_uring_disabled (EPERM) does not pass. Any |
| +// other answer, success included, names the call and fails. |
| +func syscallFilterHeld(e probeEnv) (detail string, ok bool) { |
| + ok = true |
| + var bad []string |
| + for _, c := range []struct { |
| + name string |
| + call func() error |
| + }{{"io_uring_setup", e.ioUringSetup}, {"keyctl", e.keyctl}} { |
| + if err := c.call(); !errors.Is(err, syscall.ENOSYS) { |
| + ok = false |
| + bad = append(bad, fmt.Sprintf("%s = %v, want ENOSYS", c.name, err)) |
| + } |
| + } |
| + return strings.Join(bad, "; "), ok |
| +} |
| + |
| // ptsPrivate is the pts-private line (Plan 2 deviation 8): the private |
| // /dev carries no terminal of the host's. /dev/pts lists nothing and |
| // /dev/ptmx cannot be opened, so no pty can be made or reached from in |
diff --git a/internal/instanceexec/probe_hardening_linux.go b/internal/instanceexec/probe_hardening_linux.go| index 458c38a1d..98f614e96 100644 |
| --- a/internal/instanceexec/probe_hardening_linux.go |
| +++ b/internal/instanceexec/probe_hardening_linux.go |
| @@ -4,6 +4,7 @@ package instanceexec |
| import ( |
| "os" |
| + "unsafe" |
| "golang.org/x/sys/unix" |
| ) |
| @@ -20,3 +21,29 @@ func realMmapWX() error { |
| } |
| return unix.Munmap(b) |
| } |
| + |
| +// realIOUringSetup asks for a ring of zero entries: a kernel that receives |
| +// the call refuses it (EINVAL or EFAULT) without making a ring, and the |
| +// tenant syscall filter answers ENOSYS before it gets there. Should a |
| +// kernel ever return a ring fd, it is closed at once. |
| +func realIOUringSetup() error { |
| + var params [120]byte // struct io_uring_params |
| + fd, _, errno := unix.Syscall(unix.SYS_IO_URING_SETUP, 0, uintptr(unsafe.Pointer(¶ms)), 0) |
| + if errno != 0 { |
| + return errno |
| + } |
| + _ = unix.Close(int(fd)) |
| + return nil |
| +} |
| + |
| +// realKeyctl asks for this process's own keyring id without creating it |
| +// (KEYCTL_GET_KEYRING_ID, KEY_SPEC_PROCESS_KEYRING, create 0): it reaches |
| +// the kernel for any process, answering an id or ENOKEY, unless the |
| +// tenant syscall filter refuses it with ENOSYS. |
| +func realKeyctl() error { |
| + _, _, errno := unix.Syscall(unix.SYS_KEYCTL, unix.KEYCTL_GET_KEYRING_ID, uintptr(^uint(1)), 0) // -2 |
| + if errno != 0 { |
| + return errno |
| + } |
| + return nil |
| +} |
diff --git a/internal/instanceexec/probe_hardening_other.go b/internal/instanceexec/probe_hardening_other.go| index 53f37a833..ba7a503eb 100644 |
| --- a/internal/instanceexec/probe_hardening_other.go |
| +++ b/internal/instanceexec/probe_hardening_other.go |
| @@ -5,3 +5,7 @@ package instanceexec |
| import "errors" |
| func realMmapWX() error { return errors.ErrUnsupported } |
| + |
| +func realIOUringSetup() error { return errors.ErrUnsupported } |
| + |
| +func realKeyctl() error { return errors.ErrUnsupported } |
diff --git a/internal/instanceexec/probe_rootfs_test.go b/internal/instanceexec/probe_rootfs_test.go| index b816de6b8..864b84c4b 100644 |
| --- a/internal/instanceexec/probe_rootfs_test.go |
| +++ b/internal/instanceexec/probe_rootfs_test.go |
| @@ -193,7 +193,7 @@ func TestRootfsProbePassesInsideAnImageRoot(t *testing.T) { |
| if !r.Ready { |
| t.Fatalf("not ready: %+v", r.Lines) |
| } |
| - for _, c := range []string{"root-image", "mounts-allowlisted", "data-tree", "run-tree", "opt-own-image", "launch-root-owned", "root-read-only", "tmp-private", "etc-carlos", "control-unreachable", "pid1", "shm-private", "symlink-eloop", "nosymfollow", "imds-v4", "imds-tcp", "cgroup-strict", "pts-private", "dns", "loopback-v4", "private-v4", "box-addr", "mdwe", |
| + for _, c := range []string{"root-image", "mounts-allowlisted", "data-tree", "run-tree", "opt-own-image", "launch-root-owned", "root-read-only", "tmp-private", "etc-carlos", "control-unreachable", "pid1", "shm-private", "symlink-eloop", "nosymfollow", "imds-v4", "imds-tcp", "cgroup-strict", "pts-private", "dns", "loopback-v4", "private-v4", "box-addr", "mdwe", "syscall-filter", |
| "imds-v6", "resolver-ports", "loopback-v6", "private-v6", "ipc-private", "abstract-unix", "cpu-limits", "io-weight"} { |
| if v := verdict(r, c); v != "ok" { |
| t.Errorf("%s = %s: %s", c, v, detail(r, c)) |
diff --git a/internal/instanceexec/probe_test.go b/internal/instanceexec/probe_test.go| index 88f90241e..2868140cc 100644 |
| --- a/internal/instanceexec/probe_test.go |
| +++ b/internal/instanceexec/probe_test.go |
| @@ -103,6 +103,11 @@ func goodEnv(t *testing.T) probeEnv { |
| // MemoryDenyWriteExecute=yes as systemd 257 sets it on a 6.3+ |
| // kernel (PR_SET_MDWE). |
| mmapWX: func() error { return syscall.EACCES }, |
| + // The tenant syscall filter (#527 Q5), advertised by the unit and |
| + // answering ENOSYS for io_uring and the keyring. |
| + syscallFilterEnforced: true, |
| + ioUringSetup: func() error { return syscall.ENOSYS }, |
| + keyctl: func() error { return syscall.ENOSYS }, |
| } |
| } |
| @@ -131,7 +136,7 @@ func TestProbePassesOnAnIsolatedNamespace(t *testing.T) { |
| t.Fatalf("not ready: %+v", r.Lines) |
| } |
| for _, c := range []string{"data-tree", "run-tree", "var-empty", "pid1", "cgroup-ro", "cgroup-ro-mount", "control-unreachable", "etc-carlos", "shm-private", "symlink-eloop", "nosymfollow", "imds-v4", "imds-v6", "imds-tcp", |
| - "opt-own-build", "dns", "resolver-ports", "loopback-v4", "loopback-v6", "private-v4", "private-v6", "box-addr", "mdwe", "ipc-private", "abstract-unix", "cpu-limits", "io-weight", "pts-private"} { |
| + "opt-own-build", "dns", "resolver-ports", "loopback-v4", "loopback-v6", "private-v4", "private-v6", "box-addr", "mdwe", "ipc-private", "abstract-unix", "cpu-limits", "io-weight", "pts-private", "syscall-filter"} { |
| if v := verdict(r, c); v != "ok" { |
| t.Errorf("%s = %s", c, v) |
| } |
| @@ -531,3 +536,47 @@ func TestProductionProbeEnvReadsThePtsAdvertisement(t *testing.T) { |
| t.Errorf("ProbePtsPrivateEnv = %q", instancectl.ProbePtsPrivateEnv) |
| } |
| } |
| + |
| +// The syscall-filter line (#527 Q5): io_uring_setup and keyctl both answer |
| +// ENOSYS inside the unit. keyctl is the presence check (it works for any |
| +// unprivileged process on a kernel with keys), so io_uring refused by |
| +// kernel.io_uring_disabled alone, a call that reaches the kernel, or any |
| +// other errno fails. A unit that does not advertise the filter, an old one |
| +// mid-roll, is unverified, never a pass. |
| +func TestProbeSyscallFilterLine(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + enforced bool |
| + ioUring, keys error |
| + want string |
| + }{ |
| + {"held", true, syscall.ENOSYS, syscall.ENOSYS, "ok"}, |
| + {"io_uring reached the kernel", true, syscall.EINVAL, syscall.ENOSYS, "fail"}, |
| + {"io_uring only sysctl-disabled", true, syscall.EPERM, nil, "fail"}, |
| + {"keyring open", true, syscall.ENOSYS, nil, "fail"}, |
| + {"keyring other errno", true, syscall.ENOSYS, syscall.ENOKEY, "fail"}, |
| + {"unsupported platform", true, errors.ErrUnsupported, errors.ErrUnsupported, "fail"}, |
| + {"old unit mid-roll", false, syscall.EINVAL, nil, "unverified"}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + e := goodEnv(t) |
| + e.syscallFilterEnforced = tc.enforced |
| + e.ioUringSetup = func() error { return tc.ioUring } |
| + e.keyctl = func() error { return tc.keys } |
| + r := runChecks(e) |
| + if got := verdict(r, "syscall-filter"); got != tc.want { |
| + t.Fatalf("binary probe syscall-filter = %s (%s), want %s", got, detail(r, "syscall-filter"), tc.want) |
| + } |
| + if tc.want == "fail" && r.Ready { |
| + t.Fatal("a failed syscall-filter line left the probe ready") |
| + } |
| + re := goodRootfsEnv(t) |
| + re.syscallFilterEnforced = tc.enforced |
| + re.ioUringSetup = e.ioUringSetup |
| + re.keyctl = e.keyctl |
| + if got := verdict(runRootfsChecks(re), "syscall-filter"); got != tc.want { |
| + t.Fatalf("rootfs probe syscall-filter = %s, want %s", got, tc.want) |
| + } |
| + }) |
| + } |
| +} |