Documentation
¶
Overview ¶
Package gvisorpids caps how many tasks (processes and threads) a gVisor sandbox may run, inside the sandbox's own kernel (the runsc sentry).
Why it exists. runsc applies the OCI linux.resources.pids.limit only to the HOST cgroup that holds the sentry and its helpers (runsc/cgroup, pids.set); the sentry's own cgroupfs pids controller starts at "max" and runsc/boot never seeds it from the spec. Under the default systrap platform every sandbox process with its own address space is backed by a host stub process plus a sysmsg thread, so a fork bomb uses about two host tasks per sandbox task and reaches the host pids.max at roughly half of it. The next stub clone fails with EAGAIN, mm.Fork returns that as a plain Go error, and kernel.ExtractErrno panics on it ("Unknown syscall 220 error: createStub: failed to get clone" on arm64; 220 is clone there, 56 on amd64): the whole sentry dies, toolboxd with it (UC-320).
A pids.max inside the sentry is checked by Task.Clone before the new task starts, so the bomb gets EAGAIN from fork, as on runc, and the sandbox stays up. The driver passes the cap to toolboxd (PID 1) in EnvVar, toolboxd writes it with Apply before it reports ready, and the host cgroup is sized by Limits so the sentry's own cap always trips first.
Index ¶
Constants ¶
const EnvVar = "SB_GVISOR_PIDS_MAX"
EnvVar carries the sentry task cap from the driver to toolboxd.
Variables ¶
var ErrNoPidsController = errors.New("no pids.max under /sys/fs/cgroup")
ErrNoPidsController means no pids.max was found under root: the sandbox has no cgroup mount, or the runtime is not gVisor.
Functions ¶
func Apply ¶
Apply sets the container's pids.max under root to limit and returns the file it set. It never raises a limit that is already at or below limit.
func ForRuntime ¶
ForRuntime returns the pids limit for a sandbox's host cgroup and the env that has toolboxd cap the sandbox inside gVisor, for the OCI runtime binary a driver resolved ("runsc" is gVisor; "" and "runc" are runc). runc enforces the node's limit itself, so it gets that limit and no env. runsc applies the spec's limit only to the host cgroup, so the cap moves into the sentry and the host cgroup is sized to hold it (Limits).
func Limits ¶
Limits returns the task cap for the sentry and the pids limit for the sandbox's host cgroup. pidsLimit is the node's SB_SANDBOX_PIDS_LIMIT and caps the sentry, as it caps a runc sandbox; memoryMB lowers it so a full bomb fits in the sandbox's memory. The host limit is what the sentry needs at that cap, so the host cgroup never refuses a clone first. Both are zero when pidsLimit is zero (unlimited).
Types ¶
This section is empty.