32 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot 9fcf0b5b53 proc: invalidate task inodes when tasks are destroyed
PiperOrigin-RevId: 705785809
2024-12-13 00:58:08 -08:00
Kevin KrakauerandgVisor bot a8e963b095 remove outdated bug references for PTYs
PiperOrigin-RevId: 702986132
2024-12-04 22:43:42 -08:00
Nicolas LacasseandgVisor bot 72193f12c9 Implement /dev/tty for sentry-internal ttys.
The /dev/tty acts as a replica for the current thread group's controlling
terminal.

In a follow-up, I will make /dev/tty work for donated host ttys.

Updates #10925

PiperOrigin-RevId: 681629892
2024-10-02 16:23:54 -07:00
Andrei VaginandgVisor bot c96439ecd0 devpts: IterDirents has to check offset and return if it is out of range
panic: runtime error: slice bounds out of range [124:0]

goroutine 136 [running]:
panic({0x3ef9e0?, 0xc000848b28?})
	GOROOT/src/runtime/panic.go:1017
runtime.goPanicSliceB(0x7c, 0x0)
	GOROOT/src/runtime/panic.go:154
gvisor.dev/gvisor/pkg/sentry/fsimpl/devpts.(*rootInode).IterDirents
	pkg/sentry/fsimpl/devpts/devpts.go:342
gvisor.dev/gvisor/pkg/sentry/fsimpl/kernfs.(*GenericDirectoryFD).IterDirents
	pkg/sentry/fsimpl/kernfs/fd_impl_util.go:224

Reported-by: syzbot+4c8983831b3b9c7feff6@syzkaller.appspotmail.com
PiperOrigin-RevId: 583183528
2023-11-16 15:30:03 -08: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
Nicolas LacasseandgVisor bot 8c975e6e6e 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
Lucas ManningandgVisor bot 3c93bb1040 Defer kernfs openflag handling to inode implementations.
Some implementations handle more flags than others, so it doesn't
make sense to have one set of rules for all.

This change should functionally be a no-op.

PiperOrigin-RevId: 502712415
2023-01-17 16:01:40 -08:00
Ayush RanjanandgVisor bot bf4d27a6ca 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
Zach KoopmansandgVisor bot 02370bbd31 [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
Zach KoopmansandgVisor bot 54b71221c0 [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
Rahat MahmoodandgVisor bot c5667022b6 Report filesystem-specific mount options.
PiperOrigin-RevId: 362406813
2021-03-11 16:49:36 -08:00
Dean DengandgVisor bot 0fb5353e45 Initialize references with a value of 1.
This lets us avoid treating a value of 0 as one reference. All references
using the refsvfs2 template must call InitRefs() before the reference is
incremented/decremented, or else a panic will occur. Therefore, it should be
pretty easy to identify missing InitRef calls during testing.

Updates #1486.

PiperOrigin-RevId: 341411151
2020-11-09 08:33:17 -08:00
Dean DengandgVisor bot 265f1eb2c7 Add leak checking for kernfs.Dentry.
Updates #1486.

PiperOrigin-RevId: 339581879
2020-10-28 19:02:02 -07:00
Ayush RanjanandgVisor bot 6ee3520b61 [vfs] kernfs: Implement remaining InodeAttr fields.
Added the following fields in kernfs.InodeAttr:
- blockSize
- atime
- mtime
- ctime

Also resolved all TODOs for #1193.

Fixes #1193

PiperOrigin-RevId: 338714527
2020-10-23 11:43:32 -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
Ayush RanjanandgVisor bot e7bbe70f79 [vfs] kernfs: Fix inode memory leak issue.
This change aims to fix the memory leak issue reported inĀ #3933.

Background:
VFS2 kernfs kept accumulating invalid dentries if those dentries were not
walked on. After substantial consideration of the problem by our team, we
decided to have an LRU cache solution. This change is the first part to that
solution, where we don't cache anything. The LRU cache can be added on top of
this.

What has changed:
- Introduced the concept of an inode tree in kernfs.OrderedChildren.
  This is helpful is cases where the lifecycle of an inode is different from
  that of a dentry.
    - OrderedChildren now deals with initialized inodes instead of initialized
      dentries. It now implements Lookup() where it constructs a new dentry
      using the inode.
    - OrderedChildren holds a ref on all its children inodes. With this change,
      now an inode can "outlive" a dentry pointing to it. See comments in
      kernfs.OrderedChildren.
- The kernfs dentry tree is solely maintained by kernfs only. Inode
  implementations can not modify the dentry tree.
- Dentries that reach ref count 0 are removed from the dentry tree.
- revalidateChildLocked now defer-DecRefs the newly created dentry from
  Inode.Lookup(), limiting its life to the current filesystem operation. If
  refs are picked on the dentry during the FS op (via an FD or something),
  then it will stick around and will be removed when the FD is closed. So there
  is essentially _no caching_ for Look()ed up dentries.
- kernfs.DecRef does not have the precondition that fs.mu must be locked.

Fixes #3933

PiperOrigin-RevId: 336768576
2020-10-12 16:29:33 -07:00
Adin ScannellandgVisor bot 0a7075f38a Add basic stateify annotations.
Updates #1663

PiperOrigin-RevId: 333539293
2020-09-24 10:13:04 -07:00
Ayush RanjanandgVisor bot 20dc83c9ec [vfs] [1/2] kernfs: Internally use kernfs.Dentry instead of vfs.Dentry.
Update signatures for:
- walkExistingLocked
- checkDeleteLocked
- Inode.Open

Updates #1193

PiperOrigin-RevId: 333163381
2020-09-22 14:45:20 -07:00
Dean DengandgVisor bot 10dcefbc77 Use kernfs.Dentry for kernfs.Lookup.
Updates #1193.

PiperOrigin-RevId: 332939026
2020-09-21 14:48:23 -07:00
Tiwei Bie ed4570e6f0 fsimpl: improve the "implements" comments
As noticed by @ayushr2, the "implements" comments are not
consistent, e.g.

// IterDirents implements kernfs.inodeDynamicLookup.
// Generate implements vfs.DynamicBytesSource.Generate.

This patch improves this by making the comments like this
consistently include the package name (when the interface
and struct are not in the same package) and method name.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2020-09-17 11:45:09 +08:00
Ayush RanjanandgVisor bot 2eaf54dd59 Refactor tty codebase to use master-replica terminology.
Updates #2972

PiperOrigin-RevId: 329584905
2020-09-01 14:43:41 -07:00
Rahat MahmoodandgVisor bot b4820e5986 Implement StatFS for various VFS2 filesystems.
This mainly involved enabling kernfs' client filesystems to provide a
StatFS implementation.

Fixes #3411, #3515.

PiperOrigin-RevId: 329009864
2020-08-28 14:31:11 -07:00
Dean DengandgVisor bot df3c105f49 Use new reference count utility throughout gvisor.
This uses the refs_vfs2 template in vfs2 as well as objects common to vfs1 and
vfs2. Note that vfs1-only refcounts are not replaced, since vfs1 will be deleted
soon anyway.

The following structs now use the new tool, with leak check enabled:
devpts:rootInode
fuse:inode
kernfs:Dentry
kernfs:dir
kernfs:readonlyDir
kernfs:StaticDirectory
proc:fdDirInode
proc:fdInfoDirInode
proc:subtasksInode
proc:taskInode
proc:tasksInode
vfs:FileDescription
vfs:MountNamespace
vfs:Filesystem
sys:dir
kernel:FSContext
kernel:ProcessGroup
kernel:Session
shm:Shm
mm:aioMappable
mm:SpecialMappable
transport:queue

And the following use the template, but because they currently are not leak
checked, a TODO is left instead of enabling leak check in this patch:
kernel:FDTable
tun:tunEndpoint

Updates #1486.

PiperOrigin-RevId: 328460377
2020-08-25 21:04:04 -07:00
Rahat MahmoodandgVisor bot 0ea03f501b Clarify seek behaviour for kernfs.GenericDirectoryFD.
- Remove comment about GenericDirectoryFD not being compatible with
  dynamic directories. It is currently being used to implement dynamic
  directories.

- Try to handle SEEK_END better than setting the offset to
  infinity. SEEK_END is poorly defined for dynamic directories
  anyways, so at least try make it work correctly for the static
  entries.

Updates #1193.

PiperOrigin-RevId: 327890128
2020-08-21 16:05:43 -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