342 Commits
Author SHA1 Message Date
gVisor bot 86abc85f37 Merge pull request #11473 from Champ-Goblem:shim-add-cgroup-v2-metrics-support
PiperOrigin-RevId: 730560110
2025-02-25 14:52:09 -08:00
Nicolas LacasseandgVisor bot 689db80e98 Automated rollback of changelist 691984293
PiperOrigin-RevId: 715964287
2025-01-15 15:16:06 -08:00
Andrei Vagin 679c77e4f0 proc: Allow interrupting generation of /proc/pid/mount{s,info}
In some cases, generating /proc/pid/mount{s,info} can take a long time.
This change allows the process to be interrupted.

Reported-by: syzbot+9e7465bc6f00665727ad@syzkaller.appspotmail.com
Signed-off-by: Andrei Vagin <avagin@google.com>
2025-01-06 14:02:17 -08:00
Jamie LiuandgVisor bot f66f0e235a Fix memmap.MappingIdentity.Device/InodeID() lock ordering.
For vfs.FileDescriptions for which FileDescriptionOptions.UseDentryMetadata is
true, memmap.MappingIdentity.Device/InodeID() => FileDescription.Stat() =>
FilesystemImpl.StatAt() takes fsimpl locks for path traversal, which violates
the lock ordering and is unnecessary since no path is being traversed. Fix this
by carving out a special case where FilesystemImpl.Stat() (and
FileDescriptionImpl.Stat()) are required to meet the lock ordering requirements
of memmap.MappingIdentity.Device/InodeID(), and implement that special case by
skipping path traversal (and gofer revalidation) locks when not required.

PiperOrigin-RevId: 698608924
2024-11-20 19:30:02 -08:00
Jamie LiuandgVisor bot 336dc85043 vfs: use ancestryMu in implementations of DentryImpl.InotifyWithParent
This lock was introduced in cl/696713993 and only protects parent/name for all
dentries, which is all that's required by InotifyWithParent().

PiperOrigin-RevId: 697016824
2024-11-15 15:27:27 -08:00
Jamie LiuandgVisor bot 0659b6035a vfs: establish lock ordering for FilesystemImpl.PrependPath
- Add type parameter Filesystem to vfs/genericfstree, which is required to
  provide `ancestryMu sync.RWMutex`, and add such a RWMutex to all FSImpls that
  use genericfstree.

- Modify genericfstree.PrependPath() and genericfstree.IsDescendant() to use
  ancestryMu to ensure atomicity. For callers of genericfstree.PrependPath(),
  this means that (broader) FSImpl locks no longer need to be held during the
  call. For callers of genericfstree.IsDescendant(), this means that we can
  remove documentation warnings about its non-atomicity.

- Minor cleanup: Remove useless variable `start`, which is always 0, from
  MM.ReadMaps/SmapsDataInto().

PiperOrigin-RevId: 696713993
2024-11-14 18:14:27 -08:00
Jamie LiuandgVisor bot e23347e5b5 Move //pkg/sentry/kernel/time to //pkg/sentry/ktime.
This avoids needing to rename it everywhere it's imported.

PiperOrigin-RevId: 693930089
2024-11-06 18:13:51 -08:00
Ayush RanjanandgVisor bot 1e5b6ec429 Add more context to errors during restore.
This will help with debugging restore failures.

PiperOrigin-RevId: 693436013
2024-11-05 12:18:57 -08:00
Jamie LiuandgVisor bot b2d8bb498f vfs: skip unresolved mount promises in procfs
Also handle PathnameReachable() failure in GenerateProcMounts() consistently
with GenerateProcMountInfo() (the latter changed in cl/485155018).

PiperOrigin-RevId: 691984293
2024-10-31 17:19:04 -07:00
Jamie LiuandgVisor bot a5459a26cb Add memmap.MMapOpts.RequirePlatformEffect and use where appropriate.
Per the comment for vfs.GenericProxyDeviceConfigureMMap(), this ensures that if
invalid arguments are provided to application mmap() for a proxy device file,
then an error is returned immediately (from host mmap()) rather than when
demand paging causes host mmap() to be invoked.

PiperOrigin-RevId: 680733678
2024-09-30 15:13:16 -07:00
Lucas ManningandgVisor bot f229b3e772 Fix small logic bug with CLONE_NEWUSER|CLONE_NEWNS in clone.
The new mount namespace was being created with the old user namespace,
not the new one. This led to permission errors when creating new mounts.

PiperOrigin-RevId: 676489580
2024-09-19 11:24:15 -07:00
Lucas ManningandgVisor bot 290789bab8 Refactor tpu chroot operations.
Ubuntu TPU images do not have the vfio-dev directories that COS images do,
so we need a more robust way of setting up the sandbox chroot to handle this
case. This change implements a way to get devices and minor numbers into the
sandbox with minimal support from the host filesystem and cleans up a few
methods to reflect their current usage.

Addresses #10795

PiperOrigin-RevId: 674363342
2024-09-13 11:15:28 -07:00
Nicolas LacasseandgVisor bot 742b914fcb Don't log mount.root because it leads to racy access.
I don't think these logs have been useful in the past anyways.

Reported-by: syzbot+73ebb3f2046b3352bb94@syzkaller.appspotmail.com
PiperOrigin-RevId: 658846904
2024-08-02 11:21:47 -07:00
Jing ChenandgVisor bot a4349dab65 Update TODO bug id in order to close docker in gvisor bug.
PiperOrigin-RevId: 638730275
2024-05-30 11:50:04 -07:00
Jing ChenandgVisor bot 79331f35cf Create utility for integer-based proc files.
PiperOrigin-RevId: 635890464
2024-05-21 12:26:14 -07:00
Lucas ManningandgVisor bot 0d71d29b6d Log the correct path in mount promise timeout panic message.
PiperOrigin-RevId: 629460961
2024-04-30 10:47:12 -07:00
gVisor bot 13ff778ec5 Merge pull request #10207 from worrycare:master
PiperOrigin-RevId: 622246120
2024-04-05 12:09:55 -07:00
Lucas ManningandgVisor bot 3c206d825a Fix mount promise TOCTOU bug.
Bug scenario:

T1: Creates waiter queue, adds waiter, emits mount promise block event,
    waits.
T2: Gets waiter queue from vfs.mountPromises with read lock.
T1: Daemon does mount, notifies original waiter, deletes promise.
T2: Emits another mount promise block event, but mount already happened!
T2: Waits forever for a mount that will never come.
PiperOrigin-RevId: 619974202
2024-03-28 10:11:01 -07:00
dongjinlong ba02461e12 chore: remove repetitive words in comments
Signed-off-by: dongjinlong <dongjinlong@outlook.com>
2024-03-26 19:57:40 +08:00
Fabricio VoznikaandgVisor bot 26dd42a0ea Allow host FD to be restored with a different FD
FD numbers can vary between depending on the options used with
runsc command. For example, there are extra FDs passed to
`runsc boot` if `debug-log` is enabled. So instead of requiring
all FDs to have the exact same numbering during restore, provide
a mechanism to remap the FD. Each host FD has a unique identifier
with a map to their corresponding FD. Then during restore, FD
numbers are remapped to the correct ones.

Updates #1956

PiperOrigin-RevId: 615215783
2024-03-12 16:57:07 -07:00
Ayush RanjanandgVisor bot 50db853e59 Update fsimpl/erofs to not depend on FilesystemImplSaveRestoreExtension.
Now with restore context available in afterLoad(), we don't need to depend
on this extension.

PiperOrigin-RevId: 614913227
2024-03-11 22:36:46 -07:00
Ayush RanjanandgVisor bot faf07bade6 Reassociate pma.file to the correct pgalloc.MemoryFile on restore.
Earlier we were always restoring pma.file to mm.mfp.MemoryFile(). However,
d8eb29ed6f ("Add support for saving PMAs referencing tmpfs filestore files.")
added support for saving PMAs that reference "private" pgalloc.MemoryFiles that
are different from mm.mfp.MemoryFile().

We achieve the correct restore by:
- Adding a "RestoreID" field to pgalloc.MemoryFile. Private MemoryFiles set
  this with a vfs.RestoreID.String(). Non-private MemoryFile does not set it.
- MemoryFile struct is not savable by itself, but pma.file field is saved as a
  string. We store the RestoreID string there.
- On restore, if RestoreID is "", then restore using CtxMemoryFile. If it has a
  non-empty RestoreID, then restore using CtxMemoryFileMap.
- Cleanup: vfs.CtxFilesystemMemoryFileMap was moved to pgalloc.CtxMemoryFileMap
  so we can now provide a pgalloc.MemoryFileMapFromContext() method which
  cleans up some code. Also the key to this map (MemoryFileOpts.RestoreID)
  belongs to pgalloc, so it seems like the right place to have this context.

PiperOrigin-RevId: 614903073
2024-03-11 21:44:03 -07:00
Ayush RanjanandgVisor bot 7e395bbbd4 Plumb restore context to load*() methods.
This allows for external information to be passed to restore code.
Similar to c087777e37 ("Plumb restore context to afterLoad()").

Updates #1956.

PiperOrigin-RevId: 614125262
2024-03-08 20:28:02 -08:00
Jing ChenandgVisor bot 3cf3384220 Return a task image's file capability when the image is loaded to be executed.
PiperOrigin-RevId: 613732844
2024-03-07 16:06:34 -08:00
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