103 Commits
Author SHA1 Message Date
Shailend ChandandgVisor bot f30d796f52 Show NoNewPrivs in /proc/[pid]/status.
Linux prints the per-thread no_new_privs bit right before the seccomp
line, gVisor tracks the bit but did not surface it.

PiperOrigin-RevId: 969969482
2026-08-24 11:28:28 -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
gVisor bot fac4d1b61d Merge pull request #13454 from relkochta:relkochta/prochostnameepoll3
PiperOrigin-RevId: 937485156
2026-06-24 12:14:04 -07:00
Ryan El Kochta 1653b017f5 Make /proc/sys/kernel/hostname and /proc/sys/kernel/domainname pollable
Adds the infrastructure for a DynamicBytesFile to become pollable
(perhaps with select, poll, or epoll). Simply arrange for a
DynamicBytesPoller to be notified whenever the relevant file is updated
and implement PollableDynamicBytesSource on the DynamicBytesSource.

EPOLLPRI and EPOLLERR are triggered for these files, which seems to
match Linux's implementation for /proc/sys files.

The first two files to support this are hostname and domainname in
/proc/sys/kernel. This is used by systemd-journald to monitor for
hostname changes.
2026-06-24 10:39:07 -07:00
Luis CapeloandHanzo Dev 1a2c3e0fd8 /proc/stat previously reported all-zero CPU stats, so tools like top and htop always showed 0% CPU usage inside a sandbox.
This change fixes the issue by surfacing the CPU accounting gVisor already tracks, read as plain atomics, closish to how Linux serves `/proc/stat`:

- **`cpu` aggregate line:** served from kernel-wide cumulative user/system CPU accumulators advanced by the existing CPU-clock ticker (analogous to Linux's `kcpustat`), read as two atomics. Idle time is approximated from uptime, giving monitoring tools meaningful deltas between samples.
- **Per-CPU lines (`cpu0`..`cpuN`):** since gVisor has no per-core accounting, the aggregate is distributed evenly across application cores (remainder assigned to `cpu0`), so the per-CPU lines sum back to the aggregate.
- **`procs_running` / `procs_blocked`:** O(1) reads of kernel atomic counters maintained on task scheduling-state transitions, analogous to Linux's `nr_running`/`nr_iowait`, instead of being hardcoded to zero.

`intr`, `ctxt`, `processes`, and `softirq` remain stubbed -- a global fork counter would be needed for `processes`?

Verified end-to-end with a `runsc` build: `top` and `htop` now report live CPU usage under load.

Fixes #9967.

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-23 14:17:17 +00:00
Ryan El Kochta 261ef4faed Implement /proc/sys/kernel/domainname
Similar implementation to /proc/sys/kernel/hostname.

Needed for systemd.
2026-06-12 11:08:37 -07:00
gVisor bot 930c8ba600 Merge pull request #13417 from relkochta:relkochta/procuuid
PiperOrigin-RevId: 930851512
2026-06-11 18:33:50 -07:00
Ryan El Kochta 9603bda5f3 Implement /proc/sys/kernel/random/uuid
For some reason, bash complains about it missing when run under machinectl.
2026-06-11 10:07:51 -07:00
gVisor bot ccf4a28489 Internal change.
PiperOrigin-RevId: 921955467
2026-05-27 01:04:27 -07:00
Tan Yifeng 566338bcd5 proc: Add /proc/sys/kernel/randomize_va_space
Expose randomize_va_space in procfs with a static value of 2
(full randomization), matching gVisor's actual ASLR behavior.

gVisor always applies full ASLR for user memory mappings, so we
report the value 2 to match the actual behavior.

This fixes programs(e.g. https://github.com/psf/pyperf) that
read this file to collect ASLR metadata and fail with ENOENT
when the file is missing.

Signed-off-by: Tan Yifeng <[email protected]>
2026-04-03 10:43:32 +08:00
Jamie LiuandgVisor bot 134f74b24b Add support for nvidia-imex.
- Add /proc/devices.

- Provide /proc/driver/nvidia/params when nvproxy is enabled. CUDA-using
  applications already try to open this file, but silently tolerate its
  non-existence. However, both the IMEX daemon and IMEX-using applications are
  believed to require this file for ImexChannelCount. (libnvidia-container
  additionally provides /proc/driver/nvidia/{registry,version}, but we have yet
  to see any application use these.)

- Add new capability nvconf.CapFabricIMEXManagement. When enabled, provide
  /proc/driver/nvidia/capabilities/fabric-imex-mgmt and the corresponding
  /dev/nvidia-caps/nvidia-cap#.

- Add support for /dev/nvidia-caps-imex-channels/ (irrespective of the new
  capability, since IMEX-using applications need this directory as well).

- Allow devutil.GoferClient.OpenAt() to take a relative path (i.e. containing
  more than one path component) rather than only a basename, since this is
  needed to open /dev/nvidia-caps/*.

- Add nvproxy support for all known-required controls, and all allocation
  classes to which those controls correspond.

This CL is specifically for nvidia-imex, the "NVIDIA IMEX Service for NVLink
Networks" (or "IMEX daemon"); applications using IMEX haven't been tested yet,
and may require additional allocation classes / control commands, or some
existing ones marked as requiring CapFabricIMEXManagement as being enabled more
broadly.

PiperOrigin-RevId: 859286209
2026-01-21 15:25:28 -08:00
Andrei VaginandgVisor bot b3e6b3770c proc: fix security checks on /proc/pid files
This change updates the security checks to align with Linux kernel behavior:
* Add ptrace_may_access-style checks (kernel.ContextCanTrace) when accessing
  /proc/[pid]/maps and /proc/[pid]/smaps.
* Change the permissions of the /proc/[pid]/fd directory to 0500 (read/execute
  for owner only).
* Add a similar kernel.ContextCanTrace check for /proc/[pid]/{environ,auxv}.

PiperOrigin-RevId: 842001353
2025-12-08 18:59:40 -08:00
Jing ChenandgVisor bot 5475b737dd Implement /proc/sys/kernel/keys/maxkeys.
PiperOrigin-RevId: 836764402
2025-11-25 12:13:43 -08:00
Andrei VaginandgVisor bot 5747a3fe8f proc: Allow to write into /proc/pid/mem
GDB uses /proc/pid/mem to access memory of the target process.

PiperOrigin-RevId: 757862341
2025-05-12 12:16:11 -07:00
gVisor bot 2504c29b77 Merge pull request #11473 from Champ-Goblem:shim-add-cgroup-v2-metrics-support
PiperOrigin-RevId: 730560110
2025-02-25 14:52:09 -08:00
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
Jamie LiuandgVisor bot f75d4f262e mm: implement prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME)
PiperOrigin-RevId: 696727156
2024-11-14 19:06:07 -08:00
gVisor bot e445d30343 Merge pull request #10721 from p12tic:expose-fake-cpuinfo-cache
PiperOrigin-RevId: 660077238
2024-08-06 13:33:39 -07:00
Povilas Kanapickas 08be71c697 procfs: add cache size x86 cpuinfo field
Linux prints this field when cache information is available. This field
is conditional (see arch/x86/kernel/cpu/proc.c:x86_cache_size()). It a
different meaning and implementation on each vendor. For example, as of
Linux 6.1.0 it returns LLC size on Intel and L2 size on AMD CPUs.

Even though usefullness of this field in its current implementation
debatable, some relatively popular software such as PyPy (as of 7.3.11)
relies on it and prints a warning if it is not available.
2024-08-06 11:18:52 +03:00
gVisor bot bb7e50e335 Merge pull request #10722 from p12tic:fix-cpuinfo-comment
PiperOrigin-RevId: 659596152
2024-08-05 10:24:36 -07:00
Povilas Kanapickas a8525916f6 test/syscalls/proc: Update comment about required_fields on x86
The previous comment has been no longer correct at least since
cd57268c04, as conditional cpuinfo fields
are now checked too.
2024-08-04 17:17:19 +03:00
Jamie LiuandgVisor bot cd57268c04 procfs: add topology-related x86 cpuinfo fields
Linux prints these fields when the kernel is built with support for multiple
processors/cores (CONFIG_SMP), in
arch/x86/kernel/cpu/proc.c:show_cpuinfo_core().

Fixes #10205

PiperOrigin-RevId: 632621375
2024-05-10 15:46:45 -07:00
Jamie LiuandgVisor bot 0bc2dd9af6 kernfs: invalidate descendants of dentries failing revalidation
Adapted from cl/630063475.

This causes FUSE tests involving submounts to fail, because fuse.inode.Valid()
just returns false (fails revalidation) after the entry time expires, causing
all submounts to be unmounted; change it to perform revalidation instead, a la
Linux's fs/fuse/dir.c:fuse_dentry_revalidate(). This in turn requires that we
plumb the dentry's parent and name through kernfs.Inode.Valid().

PiperOrigin-RevId: 630476483
2024-05-03 13:13:36 -07:00
Jonathon Belotti 409b5e385c provide (read only) /proc/sys/kernel/overflowuid and overflowgid 2023-11-09 16:15:17 +00:00
Andrei VaginandgVisor bot 2cd8fda9d5 proc: limit a comm len to TASK_COMM_LEN
PiperOrigin-RevId: 580532321
2023-11-08 07:50:23 -08:00
gVisor bot 74b2c5a62b Internal change.
PiperOrigin-RevId: 568695436
2023-09-26 17:35:33 -07:00
Andrei VaginandgVisor bot e2fc34862a proc: add /proc/sys/kernel/cap_last_cap
PiperOrigin-RevId: 559932636
2023-08-24 18:29:31 -07:00
Shambhavi SrivastavaandgVisor bot 76b2713c08 Adding /proc/[pid]/task/[tid]/children
PiperOrigin-RevId: 557888186
2023-08-17 11:41:48 -07:00
gVisor bot d716a5246f Internal change.
PiperOrigin-RevId: 540338096
2023-06-14 11:56:16 -07:00
gVisor bot 014a6b223a Internal change.
PiperOrigin-RevId: 540319250
2023-06-14 10:56:23 -07:00
Andrei Vagin 3445db339d Fix all c++ compile time warnings 2023-03-09 19:01:00 -08:00
gVisor bot 869d2312ec Fix /proc/*/stat parsing in GVisor
The code in GVisor relied on the process name not containing whitespace when
parsing /proc/*/stat. This CL fixes that by moving parsing to its own function,
implemented properly.

PiperOrigin-RevId: 511616209
2023-02-22 15:43:14 -08:00
Nicolas LacasseandgVisor bot f42c179701 Allow setting thread name by writing to /proc/pid/task/tid.
Test that thread can set its own thread, or peer thread in the same thread
group.

PiperOrigin-RevId: 510595880
2023-02-17 21:49:21 -08:00
Jamie LiuandgVisor bot 2a3fb74ffe Fix flakes in tests that use munmap() to create deliberate MM holes.
PiperOrigin-RevId: 479623755
2022-10-07 11:09:09 -07:00
gVisor bot 3138e0d14b Merge pull request #7976 from cedriccchen:proc
PiperOrigin-RevId: 474861876
2022-09-16 11:32:03 -07:00
Chen Hui dbee5ecca5 procfs: support /proc/[pid]/root file
Signed-off-by: Chen Hui <[email protected]>
2022-09-16 12:40:08 +08:00
Sergey MadaminovandgVisor bot 94c40dd35b A procfs file for runtime heap usage information for sentry.
Added a mechanism to query runtime sentry heap usage using procfs from inside
the sandbox. This may help with providing insight regarding sandbox hitting the
memory limit on the host despite reporting a lower application memory usage.
And added a test to `proc.cc`.

PiperOrigin-RevId: 470061488
2022-08-25 12:58:43 -07:00
Ayush RanjanandgVisor bot ceb39c9966 Make anonfs return ENOTDIR for open(O_DIRECTORY) calls.
All anonfs dentries are non-directories. So all FilesystemImpl
methods that would require an anonDentry to be a directory should
return ENOTDIR.

PiperOrigin-RevId: 455271653
2022-06-15 19:07:24 -07:00
Ayush RanjanandgVisor bot f6263c38df Remove VFS1 special handling in tests.
Also clean up usage of GVISOR_VFS environment variable.
Updates #1624

PiperOrigin-RevId: 429100450
2022-02-16 11:41:51 -08:00
Ayush RanjanandgVisor bot 3094195006 Do not check the stability of certain /proc/cpuinfo fields.
PiperOrigin-RevId: 421928736
2022-01-14 15:46:49 -08:00
Adin ScannellandgVisor bot 33a9bf8e30 Refactor CPUID to allow for use in KVM and ring0.
Updates #5039

PiperOrigin-RevId: 421696994
2022-01-13 17:24:28 -08:00
gVisor bot 2184549d77 Merge pull request #6570 from sudo-sturbia:ipc/proc
PiperOrigin-RevId: 398849334
2021-09-24 17:51:25 -07:00
Zyad A. Ali dd1ec58af4 Run proc's static-file tests in a container.
Some /proc files are static in gVisor, but can be updated in native
linux. To test the values of these files, move them to a separate test
and run it using "container" tag to avoid faulty comparisons in native.

Since a separate IPC namespace is used, update shm comparisons to check
the actual value, not an interval.
2021-09-24 14:15:23 +02:00
Jamie LiuandgVisor bot ea5b328b8e Add Uid/Gid/Groups fields to VFS2 /proc/[pid]/status.
For comparison:

```
$ docker run --rm -it ubuntu:focal bash -c 'cat /proc/self/status'
Name:	cat
Umask:	0022
State:	R (running)
Tgid:	1
Ngid:	0
Pid:	1
PPid:	0
TracerPid:	0
Uid:	0	0	0	0
Gid:	0	0	0	0
FDSize:	64
Groups:
NStgid:	1
NSpid:	1
NSpgid:	1
NSsid:	1
VmPeak:	    2660 kB
VmSize:	    2660 kB
VmLck:	       0 kB
VmPin:	       0 kB
VmHWM:	     528 kB
VmRSS:	     528 kB
...

$ docker run --runtime=runsc-vfs2 --rm -it ubuntu:focal bash -c 'cat /proc/self/status'
Name:	cat
State:	R (running)
Tgid:	1
Pid:	1
PPid:	0
TracerPid:	0
Uid:	0	0	0	0
Gid:	0	0	0	0
FDSize:	4
Groups:
VmSize:	10708 kB
VmRSS:	3124 kB
VmData:	316 kB
...
```

Fixes #6374

PiperOrigin-RevId: 387465655
2021-07-28 16:41:35 -07:00
Fabricio VoznikaandgVisor bot 66aefea0c7 Add /proc/sys/vm/max_map_count
Set it to int32 max because gVisor doesn't have a limit.

Fixes #2337

PiperOrigin-RevId: 378722230
2021-06-10 13:36:03 -07:00
Steve SilvaandgVisor bot acc3f657d6 Implement /proc/cmdline
This change implements /proc/cmdline with a basic faux command line
"BOOT_IMAGE=/vmlinuz-[version]-gvisor quiet" so apps that may expect
it do not receive errors.

Also tests for the existence of /proc/cmdline as part of the system
call test suite

PiperOrigin-RevId: 372462070
2021-05-06 18:03:42 -07:00
Fabricio VoznikaandgVisor bot 94bf29345c Fix deadlock in /proc/[pid]/fd/[num]
In order to resolve path names, fsSymlink.Readlink() may need to reenter
kernfs. Change the code so that kernfs.Inode.Readlink() is called without
locks and document the new contract.

PiperOrigin-RevId: 371770222
2021-05-03 13:50:37 -07:00
Fabricio VoznikaandgVisor bot 3fe6a879b2 Remove side effect from test cases
Restore capabilities for tests that need to change them.

PiperOrigin-RevId: 371007047
2021-04-28 16:22:24 -07:00
Rahat MahmoodandgVisor bot 5d7079da00 Also report mount options through /proc/<pid>/mounts.
PiperOrigin-RevId: 369967629
2021-04-22 15:52:24 -07:00
Adin ScannellandgVisor bot ce8ee943e7 Remove _NoRandomSave tests.
We do not currently run random save tests.

PiperOrigin-RevId: 368309921
2021-04-13 15:42:41 -07:00