gvisorpids

package
v0.6.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
const EnvVar = "SB_GVISOR_PIDS_MAX"

EnvVar carries the sentry task cap from the driver to toolboxd.

Variables

View Source
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

func Apply(root string, limit int64) (string, error)

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

func ForRuntime(ociRuntime string, pidsLimit int64, memoryMB int) (host int64, env []string)

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

func Limits(pidsLimit int64, memoryMB int) (sentry, host int64)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL