execve discards file capabilities under no_new_privs even when they add nothing (stricter than Linux since 4886c6690 / release-20260727.0)
Description
Since commit 4886c6690 ("Implement ambient capabilities", 2026-06-09, first in release-20260727.0), ComputeCredsForExec in pkg/sentry/kernel/auth/capability_set.go does:
if noNewPrivs {
f.HasCaps = false
f.Effective = false
}
so a binary's file capabilities are discarded outright whenever NO_NEW_PRIVS is set. Linux does not do that: security/commoncap.c cap_bprm_creds_from_file still reads the file caps and, under LSM_UNSAFE_NO_NEW_PRIVS, only applies the downgrade new->cap_permitted = cap_intersect(new->cap_permitted, old->cap_permitted) — and only when the exec would gain capabilities or change IDs (id_changed || __cap_gained(permitted, new, old)). File caps that are already in the process's permitted set survive.
gVisor's own code before 4886c6690 had the Linux rule (P'(permitted) = (P(inh) & F(inh)) | (F(perm) & P(bnd)), then PermittedCaps &= c.PermittedCaps under noNewPrivs when gainedCaps), so this is a behaviour change, not a long-standing divergence.
This matters for the common Kubernetes pattern "non-root container + capabilities.add + allowPrivilegeEscalation: false + setcap on the binary": containerd puts the added caps in the init process's Permitted/Effective (oci.WithCapabilities), the OCI spec sets noNewPrivileges: true, and the entrypoint's file caps are equal to (a subset of) what the process already holds. On runc the entrypoint keeps them; on gVisor ≥ 20260727 it starts with CapPrm/CapEff = 0.
Steps to reproduce
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends libcap2-bin \
&& cp /bin/cat /usr/local/bin/cat-fcaps && setcap cap_net_bind_service=+ep /usr/local/bin/cat-fcaps
USER 1000
CMD ["/usr/local/bin/cat-fcaps", "/proc/self/status"]
docker build -t fcaps-nnp .
docker run --rm --runtime=runc --cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges fcaps-nnp | grep -E '^(Cap|NoNewPrivs)'
docker run --rm --runtime=runsc --cap-drop ALL --cap-add NET_BIND_SERVICE --security-opt no-new-privileges fcaps-nnp | grep -E '^(Cap|NoNewPrivs)'
runc (Docker 29.8.0) — expected, matches Linux:
CapInh: 0000000000000000
CapPrm: 0000000000000400
CapEff: 0000000000000400
CapBnd: 0000000000000400
CapAmb: 0000000000000000
NoNewPrivs: 1
runsc ≥ release-20260727.0 (observed on GKE Sandbox 1.36.4, gVisor component 20260727.0_RC04; same container image, getcap inside still lists the file caps):
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 00000000000004c0
CapAmb: 0000000000000000
NoNewPrivs: 1
(The GKE pod also had SETUID/SETGID added; the point is Prm/Eff are empty while Bnd holds the caps.) The same image and pod spec had the caps in Prm/Eff on the previous GKE gVisor component (1.36.19).
Expected behaviour
Match Linux: under NO_NEW_PRIVS, keep file capabilities and only intersect the resulting permitted set with the pre-exec permitted set when the exec would otherwise gain capabilities or change IDs, i.e. drop the f.HasCaps = false short-circuit and rely on the existing gainedCaps && noNewPrivs → PermittedCaps &= c.PermittedCaps downgrade (and the matching ambient handling).
Impact / workaround
Broke every subprocess that relied on CAP_SETUID from file caps in our sidecar on GKE Sandbox after the 1.36.4 node upgrade. Workaround we shipped: start the container as root and setpriv --reuid … --ambient-caps … into the real process (ambient caps, which the same commit added, survive execve). That works, but the Kubernetes-native non-root pattern no longer does on gVisor while it still does on runc.
runsc version
GKE Sandbox on GKE 1.36.4-gke.1082000 / 1.36.4-gke.1247000 (gVisor component "1.36.23", "20260727.0_RC04" per the GKE 1.36 changelog). Code reference is release-20260727.0 and later master.
docker version / runsc -version
Docker 29.8.0 for the runc reference run. runsc: GKE-managed (see above).
uname
Linux 4.19.0-gvisor inside the sandbox; GKE node kernel 6.12.105+ (COS).
repo state
Not applicable (no local runsc build).
hi, is this open to be taken? I'm relatively new here. @splebel