184 Commits
Author SHA1 Message Date
Jamie LiuandgVisor bot b01944883b Add memmap.File.MemoryType()
This has no effect (outside of debug logging) until cl/723723715.

Updates #11436

PiperOrigin-RevId: 736686635
2025-03-13 17:08:52 -07:00
Andrei VaginandgVisor bot 9fcf0b5b53 proc: invalidate task inodes when tasks are destroyed
PiperOrigin-RevId: 705785809
2024-12-13 00:58:08 -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
Jamie LiuandgVisor bot a50fb5ded0 Add memmap.File.DataFD().
This is used in cl/674746696 to ensure that users of MemoryFile data wait until
that data has been loaded.

PiperOrigin-RevId: 679255898
2024-09-26 12:51:20 -07:00
Jamie LiuandgVisor bot 7d0bf706d3 gofer,kernfs: invalidate descendants of dentries failing revalidation
This follows cl/630476483, but for fsimpl/gofer. Also restructure
kernfs.Filesystem.invalidateRemovedChildLocked() to follow
gofer.dentry.invalidate() by using a depth-first search rather than recursion,
requiring only one `[]*dentry` per revalidation failure rather than one per
directory.

PiperOrigin-RevId: 632015279
2024-05-08 20:45:19 -07:00
Jamie LiuandgVisor bot a78cff7f8d 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
Jamie LiuandgVisor bot 31979a7187 mm: add fallback to buffered I/O when memmap.File.MapInternal() is unavailable
MapInternal() returns a coherent memory mapping of the host file descriptor
represented by a memmap.File, in the sentry's address space. This is
principally used when the sentry needs to access the contents of application
memory (for e.g. syscall arguments passed by pointer, or the source/destination
of a write()/read() syscall); it usually looks up the memmap.Files backing
application addresses and obtains mappings via MapInternal().

/dev/nvidia-uvm cannot generally be mapped into the sentry's address space, for
reasons described by
https://github.com/google/gvisor/blob/master/g3doc/proposals/nvidia_driver_proxy.md#unified-virtual-memory-uvm
(in short, nvidia-uvm requires that a given page at file offset X can only be
mapped at address X). To allow the sentry to access the contents of such
mappings, make it possible for memmap.File.MapInternal() to indicate that a
fallback to buffered I/O is required, add interface methods
memmap.File.Buffer{Read,Write}At() to perform this buffered I/O, and implement
this fallback in the MM I/O path.

This CL does not use the new buffered I/O fallback anywhere; a following CL
adds it to nvproxy's nvidia-uvm.

Updates #10331

PiperOrigin-RevId: 629830825
2024-05-01 14:05:55 -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 3e952d1e30 Modify FUSE inodes so they're not always assumed to be valid.
PiperOrigin-RevId: 621954030
2024-04-04 13:35:04 -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
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
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
Jing ChenandgVisor bot be48200c0e Re-order loads in BUILD files to make transformations reversible in Copybara.
PiperOrigin-RevId: 598898756
2024-01-16 11:21:40 -08:00
Andrei Vagin 5f4abad306 Fix a few typos
It is an idea of running codespell as part of our presubmit checks.
Before enabling it for new changes, let's fix what it has found.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2023-10-25 12:13:42 -07:00
Jing ChenandgVisor bot ea4f0073d4 Fix data race between getting mount options and updating mount options.
It is not ideal to access a mount's Flags directly, gVisor will access a mount's flags via MountOptions() which locks mount's mu to avoid data race.

PiperOrigin-RevId: 576059331
2023-10-24 01:43:16 -07:00
Andrei VaginandgVisor bot 639488b65a fsimpl/devpts: handle mode, ptmxmode, uid, gid mount options
PiperOrigin-RevId: 576049946
2023-10-24 00:56:23 -07:00
Lucas ManningandgVisor bot 9d5198a863 Add IsDescendant to FilesystemImpl.
IsDescendant gives the VFS layer an easy way to check if a dentry is a
descendant of another, which is important for some mounting procedures.

This method does not take any locks when accessing the parent, so parent
fields need to switch to be atomic to avoid data races.

PiperOrigin-RevId: 570454446
2023-10-03 11:57:01 -07:00
Lucas ManningandgVisor bot c74f5866cb Fix circular lock that can happen during unlink.
Reported-by: syzbot+d93d90350a33fbd2c8b9@syzkaller.appspotmail.com
PiperOrigin-RevId: 570420492
2023-10-03 10:07:40 -07:00
Andrei VaginandgVisor bot 118a17d92d kernfs: set DenySpliceIn for DynamicBytesFD
DynamicBytesFD is used for cgroup and proc files. In Linux, these file systems
don't set splice_write callbacks.

Reported-by: syzbot+79b8543454bedce9858b@syzkaller.appspotmail.com
PiperOrigin-RevId: 553818208
2023-08-04 08:45:42 -07:00
Andrei VaginandgVisor bot aa2c8c33c6 Implement setns for mount namespaces
PiperOrigin-RevId: 552859231
2023-08-01 11:12:29 -07:00
Nayana BidariandgVisor bot aff5168121 Plumb memory cgroup id in memmap.IncRef.
Update the memmap IncRef method to pass memory cgroup id and store it in the
FrameRefSet which will be used for memory accounting. During DecRef, the
memCgID from the FrameRefSet will be retrieved and passed to MemoryLocked.Dec
to remove the memory from the cgroup.

PiperOrigin-RevId: 549656411
2023-07-20 09:39:44 -07:00
Nicolas LacasseandgVisor bot 150831fad9 kernfs: Don't try to cache anonymous inodes.
They have no parent, so are not reachable again.

PiperOrigin-RevId: 548765107
2023-07-17 12:33:03 -07:00