947 Commits
Author SHA1 Message Date
zeekayandHanzo Dev f42ae7beb2 Carry urpc payloads as ZAP, not JSON
encoding/json walked every payload on every call. ZAP reads a field at a
constant offset out of the buffer that arrived, and //tools/zap has
already stated those offsets for every payload, so the transport now asks
the payload for its own bytes and the parse step is gone.

The envelope collapses with it. clientCall and serverCall existed only
because JSON needed one type to hold an any and another to hold a
RawMessage; bytes are bytes, so one Call serves both ends. Framing comes
from the ZAP header, which declares its own length.

A payload that is nothing -- the *struct{} a method takes when it has no
argument or no result -- carries nothing. Anything else without a layout
fails the call naming the type, so a payload that would have arrived
silently empty does not arrive at all.

The methods that took a bare string or returned a bare int now take and
return named payloads, because a scalar has no layout to state and the
rest of the API was already shaped this way.


Co-authored-by: Hanzo Dev <[email protected]>
2026-09-22 23:10:33 -07:00
zeekayandHanzo Dev e1280967b6 Give the last two payloads a wire to state
A prometheus Data held its labels in a map, and control.ExecArgs held the
live kernel objects an exec runs against -- a mount namespace, an fd
table, a limit set. Neither has offsets, so neither payload could state
a layout.

Labels become a list, which also retires the O(n^2) walk that existed to
read a map in sorted order. The kernel objects move to control.Env, which
is what the sentry supplies and what a call arriving on the wire cannot:
a namespace is a reference, not a value.

Every urpc payload now states its own wire.


Co-authored-by: Hanzo Dev <[email protected]>
2026-09-22 23:10:33 -07:00
zeekayandHanzo Dev f4a6d50921 Report -visor so the guest names its own build
A sandbox that answers "-gvisor" is upstream's binary. Telling the two apart
by config is a guess — the RuntimeClass, the containerd entry and the shim
options can all name our binary while the pod runs something else, which is
exactly what happened when an inline BinaryName was accepted by containerd and
never read by the shim. The guest's own uname is the one answer that cannot be
wrong about which kernel is running it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-09 01:48:04 -07:00
Shailend ChandandgVisor bot 46e35291a0 Support writing to cgroup v2 control files without an open file descriptor
Fix a panic when writing to cgroup v2 control files from outside the sandbox
(e.g., via Cgroups.WriteControlFiles / WriteControl), where writes occur
without an open in-sandbox VFS file descriptor (fd == nil). cgroup.procs now
safely falls back to context credentials with unconfined namespace migration,
and checkNSDelegateWrite skips namespace delegation checks. Add an integration
test for runsc cgroup v2 control file writes.

Also:
- Export cgroup2fs.InitHierarchy to initialize sandbox-wide cgroup2 state
  and root controller enablement.
- Plumb CgroupNamespace through sentry lifecycle and task context to derive
  initial container cgroup2 placements.
PiperOrigin-RevId: 978087817
2026-09-08 13:36:37 -07:00
Konstantin Bogomolov 30fe0be955 Fix setsid deadlock when orphaning a shared-sighand process group
Scope the signal mutex to just the tg.tty clear in CreateSession, matching how
CreateProcessGroup, JoinProcessGroup, and the exit path already call
handleOrphan without holding a signal mutex.

CreateSession held tg.signalHandlers.mu across the entire process group
manipulation, but it only needs that mutex to clear tg.tty. When setsid(2)
orphans the caller's old process group, decRefWithParent calls handleOrphan,
which locks the signal mutex of every thread group remaining in the group. If
the caller itself, or a sibling thread group that shares the caller's
SignalHandlers (created via clone(CLONE_VM|CLONE_SIGHAND) without CLONE_THREAD),
is still a member, handleOrphan re-locks the already-held, non-reentrant mutex
and the sentry deadlocks while holding TaskSet.mu, freezing the whole sandbox.

Regression test hangs prior to the fix.
2026-08-31 14:29:57 -07:00
Xin ZhongandgVisor bot 503af4f276 seccheck: Add benchmark for seccheck overhead during syscall execution.
PiperOrigin-RevId: 972025672
2026-08-27 10:25:43 -07:00
Parth SarthiandgVisor bot 9f2bfa55cc timekeeper: Make the timer pausable.
Added pausing support for the timer(syntheticTimer)
  the `AfterFunc` now won't trigger
  when the kernel is paused.

The timer waits for all the AfterFunc functions
  to complete during Pause. As of right now, all the
  AfterFunc callbacks are not heavy, so it's okay.

When a new afterFunc is created:
 - The event is added to the synthetic timer queue.
 - AfterFuncScheduler sleeps until the next event in the queue.
 - Triggers the expired events and repeats the cycle.

PiperOrigin-RevId: 971771243
2026-08-27 00:24:34 -07:00
Yuhang Wei 214bcc4b2a sentry: Use raw exit fields for raw syscall exit events.
Raw syscall exit events incorrectly fetched the field set registered for the corresponding raw enter point. Use SyscallRawExit so exit-specific context field selections are honored.

Signed-off-by: Yuhang Wei <[email protected]>
2026-08-25 17:21:42 +08:00
gVisor bot 9ac3aa6e26 Merge pull request #13882 from ayushr2:rdma-efa
PiperOrigin-RevId: 970185578
2026-08-24 17:31:24 -07:00
gVisor bot 0a922eea81 Merge pull request #14002 from luiscape:luis/allign-clocks-in-capprofiling
PiperOrigin-RevId: 968200399
2026-08-20 19:33:48 -07:00
Nayana BidariandgVisor bot 690c579cdc Automated rollback of changelist 964380388
PiperOrigin-RevId: 967439753
2026-08-19 15:37:46 -07:00
Nayana BidariandgVisor bot 021a58b69d Automated rollback of changelist 964518735
PiperOrigin-RevId: 966690028
2026-08-18 11:04:14 -07:00
Ayush RanjanandAlessio Ricci Toniolo be94182107 Add AWS EFA support to rdmaproxy
Add an efaproxy driver plug-in for AWS Elastic Fabric Adapter (EFA) devices
bound to the host `efa` driver. EFA's driver-private uverbs ABI carries no
userspace buffer pointers on CQ/QP CREATE: queue memory is kernel-allocated
and handed back via mmap keys in the CREATE response, which the core already
forwards to the host FD verbatim. PrepareCreateDMA is therefore a no-op; the
plug-in exists to register the "efa" driver name and to model EFA's MR_QUERY
driver-namespace method (used by libfabric to fetch RDMA read/write
interconnect IDs).

Model the standard AH object's destroy method (UVERBS_OBJECT_AH): EFA (SRD)
creates address handles via the legacy write path and destroys them through
the modern object, which the core must allow.

Extend the virtual RDMA sysfs for libfabric/hwloc topology discovery:
  - device/driver symlink and /sys/bus/pci/drivers/<driver> tree, which
    libfabric's EFA provider resolves during device discovery.
  - Mirror each PCI node's raw config space ("config" file). hwloc (used by
    aws-ofi-nccl to build the NCCL topology) reads it to recover the PCI
    bridge bus-number registers; without it hwloc cannot reconstruct the
    bridge hierarchy and aws-ofi-nccl aborts its topology write.
  - Serve the per-port lid_mask_count attribute alongside the other port
    attributes libibverbs reads from sysfs; ib_core creates it on every
    port.
The sysfs integration tests cover the new driver tree and config mirroring.

Advertise a >= 5.12 kernel release in RDMA-enabled sandboxes so aws-ofi-nccl
enables dmabuf-based GPU memory registration (ibv_reg_dmabuf_mr), which the
proxy handles via the existing REG_DMABUF_MR path. Sandboxes without RDMA
keep the current 4.19 release to limit the bump's blast radius; a later
change can make the newer release the default.

Co-authored-by: Alessio Ricci Toniolo <[email protected]>
2026-08-15 01:24:30 +00:00
Luis Capelo aa9030c7fe nvproxy: expose CLOCK_MONOTONIC_RAW as a distinct clock for capProfiling
GPU profilers (Nsight Systems/CUPTI) build their trace timeline from
CLOCK_MONOTONIC_RAW. gVisor serves CLOCK_MONOTONIC_RAW as an alias of
CLOCK_MONOTONIC, this will drift from CLOCK_MONOTONIC_RAW breaking profiling.

When nvproxy is enabled with `capProfiling`, this change exposes
CLOCK_MONOTONIC_RAW as a clock distinct from CLOCK_MONOTONIC that tracks the
host's CLOCK_MONOTONIC_RAW (absolute, unadjusted). CLOCK_MONOTONIC is
unchanged. When profiling is disabled, CLOCK_MONOTONIC_RAW continues to alias
CLOCK_MONOTONIC as before.
2026-08-14 19:42:03 +00:00
Xin ZhongandgVisor bot 488d530e97 seccheck: Trace sibling pipe processes in a client lib
PiperOrigin-RevId: 964771164
2026-08-14 10:39:17 -07:00
Nayana BidariandgVisor bot 0890b4de46 Support combined restore of full snapshot and filesystem snapshot.
This change extends the split filesystem checkpoint/restore feature to support
saving and restoring only a subset of filesystems (specified by paths). This
supports a "combined restore" mechanism where some memory files (tmpfs backings)
are restored from the filesystem checkpoint, while others are restored from the
main sentry checkpoint.
- Added `SplitFSCheckpointPaths` to `SaveOpts` to allow specifying paths for
  partial FS checkpoints.
- Updated `createPrivateMemoryFile` to return whether it successfully loaded
  state from the filesystem checkpoint.
- Track which memory files were loaded from the FS checkpoint during restore
  (`fsCheckpointedMfs`) and pass this information to the kernel via context
  (`CtxFSCheckpointedMemoryFiles`).
- In `loadPrivateMemoryFiles` (during sentry restore), only load memory files
  from the sentry checkpoint if they were not already loaded from the FS
  checkpoint.
- Added validation to ensure each memory file is restored from exactly one
  source (no duplicates, and none are missed).

PiperOrigin-RevId: 964518735
2026-08-13 23:52:38 -07:00
Nayana BidariandgVisor bot 57a26ce22a Support checkpoint and restore to have separate pages for filesystem.
This change implements split filesystem checkpoint and restore, allowing the
filesystem state to be saved and restored separately from the sentry state.
- Added `--split-fscheckpoint` flag to the `checkpoint` command to trigger
saving filesystem state separately. Added `--split-fsrestore` and
`--fs-restore-image-path` flags to `restore` and `create` commands to support
restoring from split files.
- Added `FSSave` and restore code for split filesystems.
- Implemented saving/restoring tmpfs state (MemoryFile pages and directory
structure) to/from a tar-like format.
- Refactored tar read/write path to support merging filesystem state in tar.go
- Implemented donating filesystem checkpoint FDs to the sandbox during
creation/restore.
- Added test to verify split checkpoint and restore.

PiperOrigin-RevId: 964380388
2026-08-13 17:24:44 -07:00
gVisor bot 42260d5be1 Merge pull request #14038 from EtiennePerot:runsc-boot-timer
PiperOrigin-RevId: 963790799
2026-08-12 19:20:56 -07:00
Shailend ChandandgVisor bot b943164ed6 Make every user of a tty also refcount
A tty inode was kept alive by a single ownership chain: the stdio file
description's reference on the import-time dentry. Everything else that used
the inode referred to it uncounted: a file description opened via /dev/tty
pins only the devtmpfs dentry, and the controlling-terminal association
(ThreadGroup.tty) is a bare pointer.

PiperOrigin-RevId: 962479941
2026-08-10 18:19:56 -07:00
Konstantin BogomolovandgVisor bot b81e5fd5df Move fscheckpoint manifest from json to proto.
The idea is to make fscheckpoints be forward compatible (newer runsc versions
will successfully read fscheckpoints generated by an older runsc).

The exact details of how this plays out will obviously depend on ongoing runsc
runsc development (for how long to keep work-arounds for breaking changes, etc).
While this CL does enable forward compatible fscheckpoints by eliminating the
hard-matching requirement on runsc-version, please don't rely on it just yet.

PiperOrigin-RevId: 962306264
2026-08-10 12:39:54 -07:00
Etienne Perot 0cd10e4a36 runsc boot: Add startup timer instrumentation.
Example output:

```
I0807 10:27:23.158030       1 timing.go:866] ---- runsc boot timing information ----
[10:27:22.991938]                               ╭─ runsc boot
[10:27:22.995285]        +3 346µs ▋             ├─ Go code running: 3 346µs
[10:27:22.996191]          +906µs ▏             ├─ boot subcommand dispatched: 906µs
[10:27:22.996643]          +451µs               ├─ CPUID initialized: 451µs
[10:27:22.996645]            +2µs               ├─ ring0 initialized: 2µs
[10:27:22.997012]          +367µs               ├─ host info read: 367µs
[10:27:22.998024]        +1 011µs ▏             ├─ spec read: 1 011µs
[10:27:22.998555]          +530µs               ├─ chroot base mounted: 530µs
[10:27:22.998822]          +267µs               ├─ chroot proc mounted: 267µs
[10:27:23.000271]        +1 449µs ▎             ├─ chroot procfs set up: 1 449µs
[10:27:23.000369]           +97µs               ├─ chroot sealed read-only: 97µs
[10:27:23.002635]        +2 266µs ▍             ├─ chroot set up: 2 266µs
[10:27:23.003523]          +887µs ▏             ├─ sandbox capabilities computed: 887µs
[10:27:23.003693]          +170µs               ├─ current capabilities read: 170µs
[10:27:23.012905]        +9 211µs ▉▊            ├─ bounding set trimmed on all threads: 9 211µs
[10:27:23.013139]          +233µs               ├─ capset applied on all threads: 233µs
[10:27:23.013449]          +310µs               ├─ capabilities applied: 310µs
[10:27:23.024366]       +10 916µs ▉▉            ├─ resolved mounts read: 10 916µs
[10:27:23.029416]        +5 049µs ▉             ├─ seccheck initialized: 5 049µs
[10:27:23.029419]            +3µs               ├─ RNG initialized: 3µs
[10:27:23.029571]          +152µs               ├─ memory usage initialized: 152µs
[10:27:23.029619]           +47µs               ├─ GOMAXPROCS set: 47µs
[10:27:23.057560]       +27 941µs ▉▉▉▉▉▍        ├─ stdio FDs remapped: 27 941µs
[10:27:23.057563]            +2µs               ├─ donated FDs ingested: 2µs
[10:27:23.057889]          +326µs               ├─ systrap memory file created: 326µs
[10:27:23.058714]          +825µs ▏             ├─ systrap stub initialized: 825µs
[10:27:23.063232]        +4 517µs █             ├─ systrap source process created: 4 517µs
[10:27:23.063244]           +12µs               ├─ waiting for membarrier: 12µs
[10:27:23.063246]            +1µs               ├─ host membarrier probed: 1µs
[10:27:23.063251]            +4µs               ├─ platform created: 4µs
[10:27:23.063390]          +138µs               ├─ memory file created: 138µs
[10:27:23.063438]           +48µs               ├─ VDSO prepared: 48µs
[10:27:23.063473]           +34µs               ├─ timekeeper configured: 34µs
[10:27:23.063675]          +201µs               ├─ network stack created: 201µs
[10:27:23.063854]          +179µs               ├─ kernel initialized: 179µs
[10:27:23.063859]            +4µs               ├─ filesystems registered: 4µs
[10:27:23.063943]           +84µs               ├─ process args created: 84µs
[10:27:23.063947]            +3µs               ├─ compat logs initialized: 3µs
[10:27:23.063948]            +0µs               ├─ mount hints parsed: 0µs
[10:27:23.063949]            +1µs               ├─ host FS mount created: 1µs
[10:27:23.064142]          +192µs               ├─ control server started: 192µs
[10:27:23.064142]            +0µs               ├─ loader created: 0µs
[10:27:23.064152]            +9µs               ├─ metrics initialized: 9µs
[10:27:23.064152]            +0µs               ├─ notifying parent: 0µs
[10:27:23.126745]       +62 592µs ▉▉▉▉▉▉▉▉▉▉▉▉  ├─ network args received: 62 592µs
[10:27:23.126972]          +227µs               ├─ start RPC received: 227µs
[10:27:23.126982]           +10µs               ├─ start signal received: 10µs
[10:27:23.127852]          +869µs ▏             ├─ network configured: 869µs
[10:27:23.128646]          +794µs ▏             ├─ open FDs validated: 794µs
[10:27:23.131274]        +2 628µs ▌             ├─ pre-seccomp callback done: 2 628µs
[10:27:23.132513]        +1 238µs ▎             ├─ seccomp rules computed: 1 238µs
[10:27:23.146898]       +14 384µs ▉▉▊           ├─ seccomp program compiled: 14 384µs
[10:27:23.148596]        +1 698µs ▎             ├─ seccomp program installed: 1 698µs
[10:27:23.148655]           +58µs               ├─ seccomp filters installed: 58µs
[10:27:23.148655]            +0µs               ├─ forked: 0µs                          ╭─ root container
[10:27:23.148876]          +220µs               │ ... 220µs ...                         ├─ FD table created: 220µs
[10:27:23.149125]          +249µs               │ ... 469µs ...                         ├─ cgroups mounted: 249µs
[10:27:23.149798]          +673µs ▏             │ ... 1 143µs ...                       ├─ rootfs mounted: 673µs
[10:27:23.149804]            +5µs               │ ... 1 148µs ...                       ├─ submounts prepared: 5µs
[10:27:23.150009]          +205µs               │ ... 1 353µs ...                       ├─ mounted "/dev": 205µs
[10:27:23.150362]          +352µs               │ ... 1 706µs ...                       ├─ mounted "/sys": 352µs
[10:27:23.150822]          +459µs               │ ... 2 166µs ...                       ├─ mounted "/proc": 459µs
[10:27:23.150886]           +63µs               │ ... 2 230µs ...                       ├─ mounted "/dev/pts": 63µs
[10:27:23.150915]           +29µs               │ ... 2 259µs ...                       ├─ mounted "/dev/shm": 29µs
[10:27:23.151200]          +285µs               │ ... 2 544µs ...                       ├─ mounted "/etc/hosts": 285µs
[10:27:23.151212]           +12µs               │ ... 2 557µs ...                       ├─ mounted "/dev/mqueue": 12µs
[10:27:23.151539]          +326µs               │ ... 2 883µs ...                       ├─ mounted "/etc/hostname": 326µs
[10:27:23.151660]          +121µs               │ ... 3 004µs ...                       ├─ mounted "/sys/fs/cgroup": 121µs
[10:27:23.151846]          +186µs               │ ... 3 190µs ...                       ├─ mounted "/etc/resolv.conf": 186µs
[10:27:23.151974]          +128µs               │ ... 3 319µs ...                       ├─ submounts mounted: 128µs
[10:27:23.151981]            +6µs               │ ... 3 325µs ...                       ├─ device files created: 6µs
[10:27:23.151981]            +0µs               │ ... 3 326µs ...                       ├─ executable path resolved: 0µs
[10:27:23.152057]           +75µs               │ ... 3 401µs ...                       ├─ exec user home resolved: 75µs
[10:27:23.152085]           +28µs               │ ... 3 429µs ...                       ├─ FS context created: 28µs
[10:27:23.153742]        +1 656µs ▎             │ ... 5 086µs ...                       ├─ memory manager created: 1 656µs
[10:27:23.156409]        +2 667µs ▌             │ ... 7 753µs ...                       ├─ executable loaded: 2 667µs
[10:27:23.156419]           +10µs               │ ... 7 763µs ...                       ├─ VDSO mapped: 10µs
[10:27:23.156425]            +5µs               │ ... 7 769µs ...                       ├─ stack allocated: 5µs
[10:27:23.156491]           +65µs               │ ... 7 835µs ...                       ├─ stack contents loaded: 65µs
[10:27:23.156497]            +5µs               │ ... 7 841µs ...                       ├─ task image loaded: 5µs
[10:27:23.156543]           +46µs               │ ... 7 887µs ...                       ├─ init task created: 46µs
[10:27:23.156599]           +56µs               ├─ root container created: 7 943µs      │ ... 56µs ...
[10:27:23.157146]          +547µs               ├─ signal forwarding started: 547µs     │ ... 603µs ...
[10:27:23.157575]          +428µs               ├─ kernel started: 428µs                │ ... 1 031µs ...
[10:27:23.157575]            +0µs               │ ... 0µs ...                           ╰─ END 1 032µs, total 8 919µs
[10:27:23.157576]            +1µs               ╰─ END 1µs, total 165 638µs
---- End of runsc boot timing information ----
```
2026-08-07 10:26:34 -07:00
Shailend ChandandgVisor bot 0abaf5c855 Fix data race on t.tg.exitStatus in runExitMain
Acquire the t.tg.signalHandlers.mu lock before reading
t.tg.exitStatus for the seccheck.PointTaskExit event to prevent
a data race with prepareGroupExitLocked.

PiperOrigin-RevId: 960540807
2026-08-06 15:41:04 -07:00
Shailend ChandandgVisor bot 0e33c409f1 Create per-container cgroup2 dirs and honor spec cgroupns
When --mount-cgroup-v2 is enabled, a container whose spec includes a
cgroup mount is now given its own cgroup "/<cid>" in the cgroup2
hierarchy, with its init process placed there.

Cgroup namespaces from the spec are now honored, mirroring PID
namespace policy: no entry means the root namespace, an entry with a
path joins the container that declared the same path, and an entry
without a path gets a new namespace rooted at the container's cgroup.
Since a fresh cgroup2 mount is rooted at the mounting namespace's
root, a private-namespace container's /sys/fs/cgroup shows only its
own subtree, as on Linux, with no need for bind mounts.

At boot the sentry now enables nsdelegate and delegates controllers
to per-container cgroups via the root cgroup.subtree_control. Exec
sessions join the container's cgroup and cgroup namespace, like
runc exec. Per-container "runsc events" and read-control queries
now resolve for any container with a cgroup mount.

Note two differences from the existing v1 support. In v1 we bind mount:
the per-container dir "/$cid" of each controller hierarchy appears as
/sys/fs/cgroup/<controller>. With v2 no bind mounts are needed: a fresh
cgroup2 mount is rooted at the mounting namespace's root, so honoring
the spec's cgroupns request yields the scoped view naturally. (Binding
a subtree a la v1 was not an option anyway: systemd explicitly rejects
a sub-hierarchy mounted without a matching cgroup namespace.) Second,
on container destroy we now make a best-effort, recursive attempt to
remove the container's cgroup subtree; v1 leaves its per-container
dirs behind.

The root container is not special-cased. As with v1, where even the
root container gets container-id-stamped cgroup dirs and the stats
queries they enable, it gets its own "/$root_cid", and its cgroup
namespace comes from the spec like everyone else's. Docker and
Kubernetes both request a private cgroup namespace for every container
on cgroup2 hosts, so in practice the root container sees its cgroup as
a pleasing "/" rather than "/$root_cid"; a spec with no cgroupns entry
(e.g. docker run --cgroupns=host) instead sees the full sandbox
hierarchy, as on Linux. One consequence of the private default: in a
multi-container sandbox the root container cannot see the other
containers' cgroups (namespace roots are not hierarchical). I don't
expect that to be problematic, and a spec without a cgroupns entry
regains the full view if ever needed.

PiperOrigin-RevId: 960153510
2026-08-06 01:57:42 -07:00
gVisor bot 85b6140ccc Merge pull request #13850 from relkochta:relkochta/cgroup-device-ebpf
PiperOrigin-RevId: 957442241
2026-07-31 19:14:59 -07:00
Ryan El Kochta 00d76e630f Add stub for the bpf(2) syscall and cgroup eBPF programs.
Adds initial scaffolding for eBPF in gVisor. It implements the bpf(2) syscall
with support for BPF_PROG_LOAD, BPF_PROG_QUERY, and BPF_PROG_ATTACH.

Necessary for the cgroups v2 flag to be enabled by default, as this fixes
Docker-in-gVisor with cgroups v2.
2026-07-31 15:55:57 -07:00
Ryan El Kochta f9d533b8ce SO_PEERCRED: fix race against thread-group reap
NewSCMCredentials previously resolved the specified PID into a thread group with separate calls to ThreadGroupWithID() and PIDNamespacedIDs().
Both of these functions separately take and release the TaskSet lock.

This causes a race condition where between the two function calls, the thread group might get reaped, leading to the panic() being reached.

This commit addresses this issue by moving the thread group resolution/PID namespace map creation into a single critical section.
A regression syscall test is also included.

Reported-by: [email protected]
2026-07-31 09:31:46 -07:00
gVisor bot fd71a6781f Merge pull request #13603 from EtiennePerot:fscontext-refcount-leak-fix
PiperOrigin-RevId: 956229439
2026-07-29 20:02:31 -07:00
Etienne Perot c24dfd6df5 Fix FSContext refcount leak in unshare(CLONE_NEWUSER) error case. 2026-07-29 15:50:13 -07:00
Nayana BidariandgVisor bot 94f26e7725 Support multi path filesystem checkpoint.
This change extends the filesystem checkpointing to support configuring
multiple independent paths to snapshot.
- Updated `runsc fscheckpoint` to support a repeatable `--path` flag, allowing
users to specify multiple `<container_id>:<path>` pairs.
- Annotations: Introduced `dev.gvisor.internal.fscheckpoint.paths` annotation
supporting a comma-separated list of paths.
- Refactored the sentry matching logic to support multiple paths with fallback
for "all-tmpfs" or global paths.
- Verified that checkpoint and restore work correctly for shared volumes
("share=pod") when sharing container paths are specified.
- Added container tests covering multi-path checkpoint and shared volumes.

PiperOrigin-RevId: 956120278
2026-07-29 15:30:33 -07:00
Shailend ChandandgVisor bot c8a8d4a815 cgroup2: Support the nsdelegate mount option
This mount option turns cgroup namespaces into delegation boundaries,
which results in the following two behaviors:

First, resource control. A cgroup's resource-control files carve out
the parent's resources, so they belong to the delegater, not to the
subtree's occupants. Accordingly, tasks in a non-init cgroup namespace
may no longer write to interface files of their own namespace root.
The delegatable files (cgroup.procs, cgroup.subtree_control) are exempt.
Subtree tasks cannot change what share of resources the subtree receives,
but remain free to organize processes and distribute that share within it.

Second, containment. Migration (including via CLONE_INTO_CGROUP) now
requires that both the source and destination cgroups be descendants of
the cgroupns root of the task performing the migration, failing with
ENOENT otherwise (actually it is the cgroupns of the task that opened the
fd for the migration file: this detail forces me to snapshot the cgroupns
against the fd, increasing the size of this patch).

PiperOrigin-RevId: 954892289
2026-07-27 16:30:46 -07:00
AnilAltinayandgVisor bot 86c9195031 Restrict MaxPerms to not include Write access if the segment was attached as read-only
PiperOrigin-RevId: 953614870
2026-07-24 16:51:45 -07:00
Xin ZhongandgVisor bot 1f06584417 seccheck: add binary_in_memfd to ExecveInfo
PiperOrigin-RevId: 953601428
2026-07-24 16:22:41 -07:00
Xin ZhongandgVisor bot 58866a1823 Add binary size and nlink to exec security check points.
PiperOrigin-RevId: 952306838
2026-07-22 13:45:36 -07:00
Xin ZhongandgVisor bot 8547939d22 seccheck: Add an LRU cache for execve binary SHA-256 and SHA-1 hashes.
This change introduces an LRU cache (ExecveHashCache) and multi-algorithm
calculation engine (file_hash.go) to store and resolve SHA-256 and SHA-1
digests of executables during execve syscalls.

PiperOrigin-RevId: 952257971
2026-07-22 12:11:46 -07:00
Xin ZhongandgVisor bot 1efbdb842d seccheck: Add execfn to ExecveInfo seccheck point
This change adds the execfn field to the ExecveInfo seccheck point.
This field preserves the original, unresolved pathname passed to
execve(2) (used for AT_EXECFN), distinguishing it from BinaryPath,
which contains the fully resolved filesystem path after symlink and
interpreter resolution.

Tests have been updated to verify the distinction between
BinaryPath, Execfn, and Argv[0].

PiperOrigin-RevId: 952211288
2026-07-22 10:50:32 -07:00
Shailend ChandandgVisor bot 8d0941cd22 Support cgroup2 queries from outside the sandbox
Much like how cgroup v1 control files are already queryable. "runsc events"
now consults cgroup2 control files when --mount-cgroup-v2 is true, for cpu
and memory usage stats.

Currently runsc does not place each in-sandbox container is its own cgroup2
node like it does with cgroup v1, hence we just test queries against the root
cgroup2 node for now.

PiperOrigin-RevId: 950984770
2026-07-20 12:24:23 -07:00
Xin ZhongandgVisor bot 937d896c97 Add seccheck field to indicate if a file is on an overlayfs lower layer.
This change introduces a new field `binary_overlayfs_lower` in the
`ExecveBinaryInfo` seccheck point. This field is set to true if the executed
binary is found on one of the lower layers of an overlay filesystem. A helper
function `overlay.IsOnLower` is added to determine this. The existing
`binary_overlayfs_upper` field is also clarified to represent any file on
the upper layer.

PiperOrigin-RevId: 949711533
2026-07-17 12:50:20 -07:00
Jing ChenandgVisor bot b6e233b071 Fix ptrace dumpability bypass check on exit.
Fix #13226

PiperOrigin-RevId: 949272248
2026-07-16 17:48:25 -07:00
Shailend ChandandgVisor bot e3b85191b4 Support cgroup namespaces
cgroup namespaces are non hierarchical and they are defined primarily by a
"root" cgroup node. The init cgroup namespaces's root node is the true root of
the (only) cgroup2fs tree. The root node of other cgroup namespaces is the
cgroup node of the task at the time of namespace creation.

Residing in a cgroup namespace affects tasks this way:

1) The views into /proc/[pid]/cgroup and the "root" field under
   /proc/[pid]/mountinfo are virtualized: they are rendered relative to the
   reading task's cgroupns.

2) mount()ing a cgroup2 fs furnishes only a subtree of the full cgroup2fs
   tree, rooted at the "root" cgroup of the hosting cgroupns.

Fixes #11989

PiperOrigin-RevId: 948882249
2026-07-16 04:04:38 -07:00
Xin ZhongandgVisor bot 1366eb443a Add seccheck support for collecting stdin/stdout/stderr info on execve.
This change introduces a new seccheck field, FieldSentryExecveFdInfo, for the
Execve trace point. When enabled, this field collects information about file
descriptors 0, 1, and 2 (stdin, stdout, stderr) and populates the new stdin,
stdout, and stderr fields in the ExecveInfo proto. The collected FdInfo
includes the file path, mode, inode, whether it's on an overlayfs upper
layer, and socket details (local/remote addresses) if the FD is a socket.

PiperOrigin-RevId: 948482163
2026-07-15 12:33:22 -07:00
Xin ZhongandgVisor bot a8bd23b455 Add executable ctime to ExecveInfo and MmapInfo.
This change includes the creation time (ctime) of the executable binary in the
seccheck ExecveInfo and MmapInfo.

The Timespec proto message is moved to common.proto for reuse.

PiperOrigin-RevId: 948385290
2026-07-15 09:42:22 -07:00
gVisor bot 5f7c5ecdfb Merge of 44eb3cf04f
PiperOrigin-RevId: 948149800
2026-07-15 00:20:14 -07:00
Xin ZhongandgVisor bot afbbe57504 seccheck: Add is_exec_session to context
This change adds a new field `is_exec_session` to the seccheck Context. This
field is set to true if the task originated from an exec session, such as
those created by `runsc exec` or `kubectl exec`.

PiperOrigin-RevId: 948071517
2026-07-14 21:00:26 -07:00
Nayana BidariandgVisor bot 3846731234 Refactor network configuration during restore and defer link creation in runsc
This change refactors the network configuration flow during sandbox restore
and defers the creation of network links and routes in runsc to run after
seccomp filters are installed.

- Replaced ReplaceConfig with ResetConfig in inet.Stack. Introduced
inet.NetworkArgs to configure the stack during restore, updating k.LoadFrom
to use it.
- Renamed CreateLinksAndRoutes URPC to SetNetworkArgs, which now configures
host sockets before seccomp is installed, deferring link/route creation to run
after seccomp.
- Fixed S/R support by saving and restoring limit/burst state.
- Minor seccomp filter adjustments and test updates.

PiperOrigin-RevId: 945995430
2026-07-10 18:52:31 -07:00
Xin ZhongandgVisor bot dd438bd876 Add executable inode number to seccheck ExecveBinaryInfo.
PiperOrigin-RevId: 945774987
2026-07-10 10:23:38 -07:00
Xin ZhongandgVisor bot 5b0c4003be Add seccheck field to indicate if executed binary is on overlayfs upper layer.
This change introduces a new field `binary_overlayfs_upper` to the
`ExecveBinaryInfo` seccheck point. This field is set to true if the executable
being run is located on the upper layer of an overlay filesystem. A new helper
function `overlay.IsCopiedUp` is added to check this condition.

PiperOrigin-RevId: 944568906
2026-07-08 10:23:45 -07:00
Ryan El KochtaandgVisor bot 2b543c1db5 Stub support for /proc/[pid]/coredump_filter
The value has no effect, but it is stored and inherited across fork().
Unlike Linux, our default value is 0.

Elasticsearch >=v9.3.0 requires this.

PiperOrigin-RevId: 944228419
2026-07-07 19:54:23 -07:00
Nayana BidariandgVisor bot 7e09cf7be6 Automated rollback of changelist 941330876
PiperOrigin-RevId: 944161934
2026-07-07 16:47:40 -07:00
Shailend ChandandgVisor bot 7fb7618082 clone: Deliver pidfd only after child init
Reported-by: [email protected]
PiperOrigin-RevId: 943571638
2026-07-06 17:17:54 -07:00
Shailend ChandandgVisor bot dde347d9fc Add initial cgroup2 support.
The cgroup v2 fs is initialized early in the boot process, so that every task
in the sandbox resides in at least the root v2 cgroup. A new runsc flag
--mount-cgroup-v2 has been added: this controls whether runsc mounts a
cgroupv2 filesystem at /sys/fs/cgroup automatically (currently it always
mounts a v1 hierarchy at this path). This flag also gates whether userspace
can mount a cgroup2 fs. When this flag is false, which is the default, all
tasks in the sandbox reside forever in the root cgroup.

Like in Linux, the v2 hierarchy is deemed the default owner of a controller,
that is, until the corresponding v1 hierarchy is mounted: then, the v1 tree
steals ownership of that controller and it remains this way till as long as
a v1 mount exists. In other words, hybrid mode is supported, even if such
workloads are rare these days.

The pids controller is the only controller implemented in full: it serves
as validation for the unified hierarchy. The memory controller can be used
to learn the usage stats of a subtree: but like the current v1 implementation,
and unlike Linux, it doesn't achieve this through charging up the hierarchy
during allocation, instead it queries pgalloc for every active controller's
id. And it does no enforcing. The cpu and cpuset controllers are mere stubs,
like in the current v1 implementation.

The following are supported:
* General matters of topology: cgroup.subtree_control, cgroup.controllers,
                               cgroup.procs etc
* CLONE_INTO_CGROUP
* cgroup.kill
* cgroup.events
* A working pids controller and its events files
* A minimal memory controller that just reports mem usage
* Stubbed cpu and cpuset controllers

The following are NOT supported:
* threaded cgroups
* cgroup namespaces
* BPF_PROG_TYPE_CGROUP_DEVICE
* cgroup.freeze

Updates #13007

PiperOrigin-RevId: 943519748
2026-07-06 15:17:54 -07:00