Commit Graph
146 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot 9cb9a05aee proc: add /proc/{bus,fs,irq,sysrq-trigger}
Docker fails starting a container without these paths. All of them are
enumerated in readonlyPaths of a container spec.

PiperOrigin-RevId: 559984658
2023-08-24 22:59:41 -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
Andrei VaginandgVisor bot f556917137 vfs: MountNamespace.Root() has to return a top mount of /
A few mounts can be mounted on top of `/`.

PiperOrigin-RevId: 558264274
2023-08-18 15:35:47 -07:00
Nayana BidariandgVisor bot 3995928c06 Add GetMemoryUsage() API to the gVisor sandbox.
Adds GetMemoryUsage() API to get the memory usage of the containers.

PiperOrigin-RevId: 557923509
2023-08-17 13:43:56 -07:00
Shambhavi SrivastavaandgVisor bot 76b2713c08 Adding /proc/[pid]/task/[tid]/children
PiperOrigin-RevId: 557888186
2023-08-17 11:41:48 -07:00
Jing ChenandgVisor bot 906efa4976 Implement setns CLONE_NEWUTS namespace type.
PiperOrigin-RevId: 554306089
2023-08-06 15:33:25 -07:00
Andrei VaginandgVisor bot 4af420d420 Implement setns for mount namespaces
PiperOrigin-RevId: 552859231
2023-08-01 11:12:29 -07:00
Jing ChenandgVisor bot a595c26bfe Implement setns CLONE_NEWIPC namespace type.
PiperOrigin-RevId: 552619565
2023-07-31 16:12:45 -07:00
Andrei VaginandgVisor bot eda2762235 kernel: check that a task has a network namespace
task.GetNetworkNamespace has to be used when we try to access a remote task.

PiperOrigin-RevId: 552593738
2023-07-31 14:43:55 -07:00
Andrei VaginandgVisor bot c5493106c6 Implement the setns syscall
This change introduces the nsfs file system. Each new namespace allocates
a new nsfs inode.

Here are reasons why we need these inodes:
* each namespace has to have an unique id.
* proc/pid/ns/ contains one entry for each namespace. Bind mounting one of
  the files in this directory to somewhere else in the filesystem keeps the
  corresponding namespace alive even if all processes currently in
  the namespace terminate.
* setns() allows the calling process to join an existing namespace specified
  by a file descriptor.

PiperOrigin-RevId: 550694515
2023-07-24 15:45:08 -07:00
Andrei VaginandgVisor bot f5c8b355eb proc: allow to write null-terminated strings in /proc/pid/oom_score_adj
In Linux, oom_adj_write treats an input buffer as a string. It means that
it parses only the part before the first zero byte.

PiperOrigin-RevId: 544711418
2023-06-30 11:44:45 -07:00
Jamie LiuandgVisor bot a3a83a54fa Return consistent IDs for PID namespaces via procfs.
PiperOrigin-RevId: 543529000
2023-06-26 13:49:23 -07:00
Nicolas LacasseandgVisor bot b9124318dc Mark some kernfs inode as Anonymous.
These inodes can never be part of a filesystem tree. They are nameless and
never have a parent.

This allows us to avoid taking a lock in kernfs.InotifyWithParent for such
anonymous inodes.

PiperOrigin-RevId: 538823227
2023-06-08 10:25:04 -07:00
Nicolas LacasseandgVisor bot 0703267651 Remove extra space after "Groups:" in /proc/pid/status.
Linux does not include this space, and the Go 1.20 runtime tests
check for the string equality exactly.

PiperOrigin-RevId: 523159824
2023-04-10 11:06:49 -07:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -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
Kevin KrakauerandgVisor bot f5c38f9275 don't take an unnecessary reference in proc.fdSymlink.Valid()
Reported-by: [email protected]
PiperOrigin-RevId: 510454946
2023-02-17 09:51:21 -08:00
Josh Seba 51fa4c9cd1 Get limits only once instead of each loop iteration 2022-12-12 17:13:27 -08:00
Josh Seba 06bbc49069 Add support for /proc/[pid]/limits 2022-12-12 14:06:51 -08:00
Ayush RanjanandgVisor bot 64e8ac9ea1 Delete fsbridge.
Updates #1624

PiperOrigin-RevId: 492286535
2022-12-01 13:36:10 -08:00
Ayush RanjanandgVisor bot d937df6218 Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Ayush RanjanandgVisor bot 1003ae8e93 Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Ayush RanjanandgVisor bot ee523cfbc7 Delete VFS1 filesystem implementations.
Updates #1624

PiperOrigin-RevId: 488986080
2022-11-16 11:05:10 -08:00
Kevin KrakauerandgVisor bot 3a76efe831 convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Shambhavi SrivastavaandgVisor bot 81440a7c9a Add /proc/[pid]/maps to runsc trace procfs
Updates #7897

PiperOrigin-RevId: 478903608
2022-10-04 15:57:45 -07:00
Nicolas LacasseandgVisor bot 4546519e78 Replace ESRCH error with panic in procfs Readlink methods.
Use of RootFromContext(ctx) should always return a valid root in these cases.

The comment about "racing with process deletion" and ESRCH return value was
erroniously copy-pastad from the task.FSContext().RootDirectory() usage, where
such a race is possible.

PiperOrigin-RevId: 474885394
2022-09-16 13:15:53 -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 de25857eea Add inotify support to kernfs and anonfs.
This is consistent with Linux. Some applications recursively add
files to inotify FD. They fail if they run into kernfs files
because inotify_add_watch(2) returns EPERM in that case.

PiperOrigin-RevId: 462642204
2022-07-22 09:45:24 -07:00
Ayush RanjanandgVisor bot 7054987fb3 Fix remaining comments to adhere to gofmt.
PiperOrigin-RevId: 456544446
2022-06-22 10:20:08 -07:00
Ayush RanjanandgVisor bot 65f6af6417 Add support for /prod/[pid]/cmdline and /proc/[pid]/environ to trace procfs.
This change exports some logic in fsimpl/proc so that runsc/boot can use it.

Added tests for these fields.

Updates #4805

PiperOrigin-RevId: 449794552
2022-05-19 11:30:22 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Kevin KrakauerandgVisor bot 3e7fcef1df switch fsimpl/ from sync/atomic to atomicbitops for 32 bit values
PiperOrigin-RevId: 443535714
2022-04-21 18:32:04 -07:00
Kevin KrakauerandgVisor bot b8dd528b97 prohibit direct use of sync/atomic (u)int64 functions
All atomic 64 bit ints are changed to atomicbitops.(Ui|I)nt64. A nogo checker
enforces that sync/atomic 64 bit functions are not called.

For reviewers: the interesting changes are in the atomicbitops and checkaligned
packages.

Why do this?
- It is very easy to accidentally use atomic values without sync/atomic funcs.
- We have checkatomics, but this is optional and is forgotten in several places.
  - Using a type+checker to enforce this seems less error prone and simpler.
- We get NoCopy protection.
- Use of 64 bit atomics can break 32 bit builds. We have types to handle this
  without any runtime cost, so we might as well use them.

PiperOrigin-RevId: 440473398
2022-04-08 16:06:26 -07:00
Kevin KrakauerandgVisor bot 87df090030 use atomicbitops, not sync/atomic, in refsvfs2
Since refsvfs2 are used in netstack, we should use atomicbitops to avoid
breaking 32-bit builds.

On 64-bit builds there is no performance difference.

PiperOrigin-RevId: 439687980
2022-04-05 15:16:01 -07:00
Rahat MahmoodandgVisor bot cba44f0e4f cgroupfs: Implement task migration
PiperOrigin-RevId: 430273113
2022-02-22 12:43:54 -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
Andrei VaginandgVisor bot b3b324eab1 unix: call Listening under the endpoint lock
PiperOrigin-RevId: 419703575
2022-01-04 16:26:46 -08:00
Fabricio VoznikaandgVisor bot 890373e232 Report total memory based on limit or host
gVisor was previously reporting the lower of cgroup limit or 2GB as total
memory. This may cause applications to make bad decisions based on amount
of memory available to them when more than 2GB is required.

This change makes the lower of cgroup limit or the host total memory to be
reported inside the sandbox. This also is more inline with docker which always
reports host total memory. Note that reporting cgroup limit is strictly better
than host total memory when there is a limit set.

Fixes #5608

PiperOrigin-RevId: 403241608
2021-10-14 18:42:07 -07:00
Zyad A. Ali 98da581f07 Add procfs files for SysV message queues. 2021-09-27 19:51:11 +02:00
Nicolas LacasseandgVisor bot 35f1723116 Fix lock order violations: mm.mappingMu > Task.mu.
Document this ordering in mm/mm.go.

PiperOrigin-RevId: 393413203
2021-08-27 13:18:49 -07:00
Zach KoopmansandgVisor bot 83bf514e27 [syserror] Remove pkg syserror.
Removes package syserror and moves still relevant code to either linuxerr
or to syserr (to be later removed).

Internal errors are converted from random types to *errors.Error types used
in linuxerr. Internal errors are in linuxerr/internal.go.

PiperOrigin-RevId: 390724202
2021-08-13 17:16:52 -07:00
Zach KoopmansandgVisor bot f26a93e634 [syserror] Convert remaining syserror definitions to linuxerr.
Convert remaining public errors (e.g. EINTR) from syserror to linuxerr.

PiperOrigin-RevId: 390471763
2021-08-12 15:19:12 -07: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 8ab7a9c7cd Fix deadlock in procfs
Kernfs provides an internal mechanism to defer calls to `DecRef()` because
on the last reference `Filesystem.mu` must be held and most places that
need to call `DecRef()` are inside the lock. The same can be true for
filesystems that extend kernfs. procfs needs to look up files and `DecRef()`
them inside the `kernfs.Filesystem.mu`. If the files happen to be procfs
files, it can deadlock trying to decrement if it's the last reference.
This change extends the mechanism to external callers to defer DecRefs
to `vfs.FileDescription` and `vfs.VirtualDentries`.

PiperOrigin-RevId: 384361647
2021-07-12 18:30:46 -07:00
Zach KoopmansandgVisor bot 5e6d494c2f [syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent:
EEXIST
EFAULT
ENOTDIR
ENOTTY
EOPNOTSUPP
ERANGE
ESRCH

PiperOrigin-RevId: 384329869
2021-07-12 15:26:20 -07:00
Zach KoopmansandgVisor bot 895c2eaa09 [syserror] Update syserror to linuxerr for EACCES, EBADF, and EPERM.
Update all instances of the above errors to the faster linuxerr implementation.
With the temporary linuxerr.Equals(), no logical changes are made.

PiperOrigin-RevId: 382306655
2021-06-30 08:18:59 -07:00
Zach KoopmansandgVisor bot cd84634cc0 [syserror] Change syserror to linuxerr for E2BIG, EADDRINUSE, and EINVAL
Remove three syserror entries duplicated in linuxerr. Because of the
linuxerr.Equals method, this is a mere change of return values from
syserror to linuxerr definitions.

Done with only these three errnos as CLs removing all grow to a significantly
large size.

PiperOrigin-RevId: 382173835
2021-06-29 15:08:46 -07:00
Zach KoopmansandgVisor bot 45b64220cb [syserror] Add conversions to linuxerr with temporary Equals method.
Add Equals method to compare syserror and unix.Errno errors to linuxerr errors.
This will facilitate removal of syserror definitions in a followup, and
finding needed conversions from unix.Errno to linuxerr.

PiperOrigin-RevId: 380909667
2021-06-22 15:53:32 -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