141 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
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 3971ecbc6c Remove linuxerr.IsValid and use syserr.IsValid instead.
linuxerr.IsValid just checks if the errno is less than the max possible errno
value. syserr.IsValid additionally checks if the errno can be translated by the
syserr package.

Furthermore, drop the usage of linuxerr.TranslateError(), which only checks
against a map with 3 entries of sentry-internal errors. Earlier, connError()
would always fail at this step and end up returning linuxerr.EINVAL even if the
errno being returned is valid.

Reported-by: syzbot+180b8537798c091bf9fd@syzkaller.appspotmail.com
PiperOrigin-RevId: 680021716
2024-09-28 12:34:57 -07:00
Nayana BidariandgVisor bot 9ecb627726 Fix syzkaller panic for unknown error 58.
The errno 58 is not defined and it is the same as deadlock error. Update this
in the host_linux.go file.

Reported-by: syzbot+60bb099bed4694a37f61@syzkaller.appspotmail.com
PiperOrigin-RevId: 667762290
2024-08-26 16:51:29 -07:00
Ayush RanjanandgVisor bot 834bef5996 fuse: Error out in case of unsupported file type instead of panicking.
Linux has the same behavior; see callers of fs/fuse/dir.c:fuse_invalid_attr().

Reported-by: syzbot+7e65f2f0bdf121c71bcf@syzkaller.appspotmail.com
PiperOrigin-RevId: 663853750
2024-08-16 13:59:55 -07:00
Nicolas LacasseandgVisor bot e30fa67177 FUSE: Only block with a task if it is the task goroutine.
Reported-by: syzbot+1a872f529c835812552c@syzkaller.appspotmail.com
PiperOrigin-RevId: 660505372
2024-08-07 13:04:35 -07:00
Kevin KrakauerandgVisor bot b1ade52f24 fuse: handle bad response errors
FUSE is supposed to receive an error code corresponding to Linux errors, but
since it's running in another process we can't guarantee that. So instead of
propogating a nonsensical error code (that can lead, in some cases, to panics),
warn and convert the failure to EINVAL.

PiperOrigin-RevId: 660274364
2024-08-07 00:57:57 -07:00
Jamie LiuandgVisor bot 4748786350 fuse: check write() length correctness
This is consistent with Linux's fs/fuse/dev.c:fuse_do_dev_write().

PiperOrigin-RevId: 660096450
2024-08-06 14:30:22 -07:00
Nicolas LacasseandgVisor bot 2ef09d3bdd FUSE: Avoid panic when opening unknown file type.
Reported-by: syzbot+7958d33bd06200d30e90@syzkaller.appspotmail.com
PiperOrigin-RevId: 659604628
2024-08-05 10:50:02 -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
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
Nayana BidariandgVisor bot 1ebf17e9d9 Fix S/R support for fuse structs.
Add S/R support which was missing for a few structs in fuse, message queue and
tun packages.

PiperOrigin-RevId: 605139914
2024-02-07 17:03:14 -08:00
Jamie LiuandgVisor bot 94f3d8a792 Fix splices to FDs that call usermem.IO.CopyIn/CopyInTo more than once.
Fixes #9932.

When Go is able to detect `io.Copy()` from a TCP socket or `AF_UNIX` stream
socket to a TCP socket, it attempts to implement the copy as a `splice(2)` from
the source to a pipe, followed by a `splice(2)` from the pipe to the
destination [1] (since `splice(2)` requires that one of the endpoints be a
pipe); the size of the pipe is set to 1 MB [2] (from a default of 64 KB [3]) to
reduce the number of splice syscalls required. In gVisor, a bug causes each
splice syscall from pipe to TCP socket to repeatedly read the *first* 64 KB [4]
of the pipe's data (when it contains more than 64 KB of data) rather than
*successive* chunks of 64 KB.

To fix this, advance pipe state by calling `Pipe.consumeLocked()` immediately
after `Pipe.peekLocked()`. Also defensively check that such FDs call
`Pipe.(usermem.IO)` methods on sequential addresses, and change
`fuse.deviceFD.Write()` to have this property.

[1] Go: `net/tcpsock_posix.go:TCPConn.readFrom()` =>
`net/splice_linux.go:splice()` => `internal/poll/splice_linux.go:Splice()`

[2] Go: `internal/poll/splice_linux.go:newPipe()` => `maxSpliceSize`

[3] `pkg/kernel/pipe/pipe.go:DefaultPipeSize`

[4] `pkg/tcpip/transport/tcp/endpoint.go:endpoint.Write()` =>
`endpoint.queueSegment()` => `endpoint.readFromPayloader()` =>
`pkg/buffer/buffer.go:Buffer.WriteFromReader()` =>
`pkg/buffer/chunk.go:MaxChunkSize`

PiperOrigin-RevId: 603151951
2024-01-31 14:02:18 -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 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
Lucas ManningandgVisor bot 6c24ab8dd8 Issue FUSE_FLUSH request during file close.
PiperOrigin-RevId: 571178563
2023-10-05 17:27:49 -07:00
Ayush RanjanandgVisor bot a277f53f25 Fix atomicOTrunc implementation in fusefs.
If FUSE connection does not support atomic O_TRUNC and application calls
open(O_TRUNC), FUSE should truncate the file *first* (without a file handle)
and then subsequently open the file with O_TRUNC filtered out.

We were truncating the file after open(). There were 2 issues with it:
1. We were using the inode's file handle, which may be invalid at this point
   because it is donated to the first FD (to save an open(2) RPC I believe)
   and that FD can close it.
2. The truncate() was being done with fhOptions.useFh = true. However,
   sometimes the file handle might be read-only causing truncate to fail.

Fixed both issues by moving the truncate above open() and making it not use any
file handles.

PiperOrigin-RevId: 567658664
2023-09-22 10:35:43 -07:00
Andrei VaginandgVisor bot aa2c8c33c6 Implement setns for mount namespaces
PiperOrigin-RevId: 552859231
2023-08-01 11:12:29 -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 d6d9fe6236 Change FUSE so that is no longer dependent on kernel tasks.
Filesystem operations are sometimes performed outside of the context of
a kernel task.

PiperOrigin-RevId: 533271322
2023-05-18 15:41:32 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00