24 Commits
Author SHA1 Message Date
Fabricio VoznikaandgVisor bot c087777e37 Plumb restore context to afterLoad()
This allows for external information to be passed to restore code, like
host FDs to be remapped.

Updates #1956

PiperOrigin-RevId: 612540749
2024-03-04 12:21:50 -08:00
Jamie LiuandgVisor bot f4b851067a Un-delete devtmpfs.
This partially reverts cl/578969556, but implements devtmpfs using fsimpl/dev
(added by that CL).

Note that the behavior of "devtmpfs" differs compared to before cl/578969556.
Container runtime specs typically specify a tmpfs mount at /dev, which the
container runtime is required to prepopulate with certain device files
(https://github.com/opencontainers/runtime-spec/blob/main/config-linux.md#default-devices).
Prior to cl/578969556, runsc did so by silently replacing tmpfs mounts at /dev
with devtmpfs mounts. After that CL, runsc does so by silently replacing tmpfs
mounts at /dev with fsimpl/dev mounts. The distinction is that devtmpfs is a
singleton whereas fsimpl/dev is not, so in a multi-container sandbox, all
containers shared the contents of /dev before cl/578969556, but not after that
CL; this change was necessary due to differences in GPU/TPU accessibility
between containers, and is also more consistent with runc (which also creates
separate tmpfs mounts for /dev as specified).

As a side effect, explicit devtmpfs mounts shared the same filesystem as every
container's /dev before cl/578969556. Since the change to container /dev won't
be reverted, our options now are:

- All devtmpfs mounts share a single filesystem, which is distinct from any
  container's /dev.

- Each devtmpfs mount gets a distinct filesystem.

This CL chooses the former option for greater similarity to Linux devtmpfs
semantics. (In runc, explicit devtmpfs mounts share a single filesystem, which
is the *host's* /dev.)

PiperOrigin-RevId: 589021563
2023-12-07 23:10:44 -08:00
Ayush RanjanandgVisor bot 9e66f710de Delete devtmpfs and replace it with tmpfs.
Our devtmpfs implementation uses the same tmpfs filesystem instance for all
devtmpfs mounts in the sandbox. This would mean that devices mounted in a
container are visible and accessible to all other containers in the sandbox.

With GPU/TPU, the contents of devtmpfs can be different for different
containers within the same sandbox. So it is important to not share the same
devtmpfs contents.

It is better to drop support for devtmpfs, than to implement it incorrectly.
Instead, this change introduces a new dummy filesystem type named `dev`. This
filesystem can not be mounted or listed by the application. This filesystem
creates a new tmpfs instance on GetFilesystem() and populates it with all the
device files.

PiperOrigin-RevId: 578969556
2023-11-02 13:58:58 -07:00
Andrei VaginandgVisor bot eb6b3ac00b 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
Andrei VaginandgVisor bot aa2c8c33c6 Implement setns for mount namespaces
PiperOrigin-RevId: 552859231
2023-08-01 11:12:29 -07:00
Ayush RanjanandgVisor bot f2392c37ea Do not rely on vfs.MkdirAt() for existence check during mountpoint creation.
Readonly mounts or readonly path mappings will return EROFS or EPERM even if
the file exists at that location. So relying on MkdirAt() to return EEXIST can
yield incorrect results.

Instead call MkdirAllAt(), which uses StatAt() to check for existence. This
yields accurate results.

PiperOrigin-RevId: 539228542
2023-06-09 19:11:47 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Kevin KrakauerandgVisor bot d8aa09e04c 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
Ian LewisandgVisor bot e6a9780f3c Fix TODO comments.
Fix TODO comments referring to incorrect issue numbers. Also fix the link in
issue reviver comments to include the right url fragment.

PiperOrigin-RevId: 373491821
2021-05-12 18:09:03 -07:00
Jamie LiuandgVisor bot 9f87400f08 Support VFS2 save/restore.
Inode number consistency checks are now skipped in save/restore tests for
reasons described in greatest detail in StatTest.StateDoesntChangeAfterRename.
They pass in VFS1 due to the bug described in new test case
SimpleStatTest.DifferentFilesHaveDifferentDeviceInodeNumberPairs.

Fixes #1663

PiperOrigin-RevId: 338776148
2020-10-23 17:48:33 -07:00
Dean DengandgVisor bot 432963dd2d [vfs2] Don't take reference in Task.MountNamespaceVFS2 and MountNamespace.Root.
This fixes reference leaks related to accidentally forgetting to DecRef()
after calling one or the other.

PiperOrigin-RevId: 336918922
2020-10-13 11:31:22 -07:00
Dean DengandgVisor bot 577c82f22c [vfs2] Add FilesystemType.Release to avoid reference leaks.
Singleton filesystem like devpts and devtmpfs have a single filesystem shared
among all mounts, so they acquire a "self-reference" when initialized that
must be released when the entire virtual filesystem is released at sandbox
exit.

PiperOrigin-RevId: 336828852
2020-10-13 01:13:22 -07:00
Adin ScannellandgVisor bot 0a7075f38a Add basic stateify annotations.
Updates #1663

PiperOrigin-RevId: 333539293
2020-09-24 10:13:04 -07:00
Fabricio VoznikaandgVisor bot c8f1ce288d Honor readonly flag for root mount
Updates #1487

PiperOrigin-RevId: 330580699
2020-09-08 14:00:43 -07:00
Nicolas LacasseandgVisor bot 5ec3d4ed3e Make mounts ReadWrite first, then later change to ReadOnly.
This lets us create "synthetic" mountpoint directories in ReadOnly mounts
during VFS setup.

Also add context.WithMountNamespace, as some filesystems (like overlay) require
a MountNamespace on ctx to handle vfs.Filesystem Operations.

PiperOrigin-RevId: 327874971
2020-08-21 14:30:03 -07:00
Nicolas LacasseandgVisor bot 2c422b7f21 Fix parent directory creation in CreateDeviceFile.
It was not properly creating recursive directories. Added tests for this case.

Updates #1196

PiperOrigin-RevId: 327850811
2020-08-21 12:10:14 -07:00
Nayana BidariandgVisor bot b2ae7ea1bb Plumbing context.Context to DecRef() and Release().
context is passed to DecRef() and Release() which is
needed for SO_LINGER implementation.

PiperOrigin-RevId: 324672584
2020-08-03 13:36:05 -07:00
Nicolas LacasseandgVisor bot 58880bf551 Port /dev/net/tun device to VFS2.
Updates #2912 #1035

PiperOrigin-RevId: 318162565
2020-06-24 16:23:44 -07:00
Nicolas LacasseandgVisor bot 696feaf10c Port devpts to VFS2.
PiperOrigin-RevId: 308164359
2020-04-23 17:34:29 -07:00
Nicolas LacasseandgVisor bot 10f2c8db91 Add FilesystemType.Name method, and FilesystemType field to Filesystem struct.
Both have analogues in Linux:
* struct file_system_type has a char *name field.
* struct super_block keeps a pointer to the file_system_type.

These fields are necessary to support the `filesystem type` field in
/proc/[pid]/mountinfo.

PiperOrigin-RevId: 303434063
2020-03-27 16:56:16 -07:00
gVisor bot e4c7f3e6f6 Inline vfs.VirtualFilesystem in Kernel struct
This saves one pointer dereference per VFS access.

Updates #1623

PiperOrigin-RevId: 295216176
2020-02-14 13:40:39 -08:00
gVisor bot 4075de11be Plumb VFS2 inside the Sentry
- Added fsbridge package with interface that can be used to open
  and read from VFS1 and VFS2 files.
- Converted ELF loader to use fsbridge
- Added VFS2 types to FSContext
- Added vfs.MountNamespace to ThreadGroup

Updates #1623

PiperOrigin-RevId: 295183950
2020-02-14 11:12:47 -08:00
Fabricio VoznikaandgVisor bot dcffddf0ca Remove argument from vfs.MountNamespace.DecRef()
Updates #1035

PiperOrigin-RevId: 293194631
2020-02-04 11:48:36 -08:00
Jamie LiuandgVisor bot 2862b0b1be Add //pkg/sentry/fsimpl/devtmpfs.
PiperOrigin-RevId: 292021389
2020-01-28 15:05:24 -08:00