117 Commits
Author SHA1 Message Date
Nicolas LacasseandgVisor bot f9b1ce2f7d Clean up tty.CheckChange and call it in SetForegroundProcessGroup.
Previously, CheckChange (corresponding to Linux's tty/tty_check_change()) was
only used the host TTY implementation, not the devpts implementation.

Furthermore, ThreadGroup.SetForegroundProcessGroup() duplicated some of the
logic in CheckChange, notably sending SIGTTOU to background tasks. This means
that, for host TTYs, we could send SIGTTOU multiple times. In some
circumstances, this leads the ioctl returning ERESTARTSYS in an infinite loop.

PiperOrigin-RevId: 735934036
2025-03-11 16:46:55 -07:00
Fabricio VoznikaandgVisor bot 0c17600995 Fix restore with pending exec session
Exec'd processes cannot be stitched back to the original caller
and are killed after restore. So ignore failures
to restore host FDs (generally stdio) that belong
to them.

Fixes #11439

PiperOrigin-RevId: 732972054
2025-03-03 10:30:25 -08:00
Nicolas LacasseandgVisor bot a4a0e84b5c Allow sending and importing a host event fd.
PiperOrigin-RevId: 724046820
2025-02-06 13:16:47 -08:00
Andrei VaginandgVisor bot 9fcf0b5b53 proc: invalidate task inodes when tasks are destroyed
PiperOrigin-RevId: 705785809
2024-12-13 00:58:08 -08:00
Nicolas LacasseandgVisor bot 892ba3d7f6 Fix nil-pointer bug in tty.checkChange.
The logic is the same as Linux's __tty_check_change, but we forgot to check the
case that the tty does not have an associated process group.

PiperOrigin-RevId: 693119939
2024-11-04 16:01:58 -08:00
Nicolas LacasseandgVisor bot cceb04f05a Clean up host.TTYFileOperations.
We used to track the foreground process group & session on the
TTYFileOperation, but these are already tracked in kernel.TTY.ThreadGroup.

So remove TTYFileOperations.fgProcessGroup and .session, and replace them with
a kernel.TTY.

This is analogous to how sentry-internal tty's already work.

Updates #10925

PiperOrigin-RevId: 681957240
2024-10-03 11:25:52 -07:00
Nicolas LacasseandgVisor bot d5a9d523bb Implement /dev/tty for donated host TTYs
Fixes #10925

PiperOrigin-RevId: 681684673
2024-10-02 19:40:43 -07:00
Fabricio VoznikaandgVisor bot bcc70e30fc Make all restored host FDs explicit
This ensures that host FDs are not using some random FD
upon restore. All host FDs must be part of the restore
FD map that is explicity set, otherwise restore fails.

Updates #1956

PiperOrigin-RevId: 615581166
2024-03-13 16:34:32 -07: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
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
Andrei VaginandgVisor bot f3b0a527c2 inet: allow to create abstract unix sockets in non-root namespaces
PiperOrigin-RevId: 573253619
2023-10-13 10:20:56 -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
Fabricio VoznikaandgVisor bot 919cfd12bd Add FIONREAD to host file description
Closes #8544

PiperOrigin-RevId: 535456427
2023-05-25 18:25:42 -07:00
B. Blechschmidt 761bda09a5 Add support for execution via host file descriptor
This commit adds support for program execution via a host file
descriptor. To make use of this feature, the host file descriptor must
be provided to the --exec-fd argument. For example,

    exec 3</usr/bin/echo
    runsc exec --exec-fd=3 mycontainer hello world

will run the host's echo binary inside gVisor. In this case, "hello" is
supplied to echo as argv[0]. As a result, the output of the above
command is "world".

This feature is useful for bootstrapping unknown guest environments and
allows static executables to perform setup actions inside the container
while they need not be part of the guest file system.
2023-04-02 01:27:19 +02:00
Etienne PerotandgVisor bot f8b9824813 Update unimpl.EmitUnimplementedEvent interface to add the syscall number.
This catches up the interface to the `EmitUnimplementedEvent` method signature
on `kernel.Kernel`.

Also add build-time test to verify that `kernel.Kernel` implements this
interface, in order to catch such breakages at build time in the future.

PiperOrigin-RevId: 519000411
2023-03-23 17:01:37 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Lucas ManningandgVisor bot fc52a6d9cc Give FUSE hard link capabilities and enable the link syscall test.
PiperOrigin-RevId: 507001947
2023-02-03 15:00:04 -08:00
Ayush RanjanandgVisor bot 175db901ca Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Ayush RanjanandgVisor bot 1fa3c06f1e Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Ayush RanjanandgVisor bot 7eeeb796f8 Delete VFS1 filesystem implementations.
Updates #1624

PiperOrigin-RevId: 488986080
2022-11-16 11:05:10 -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
Ayush RanjanandgVisor bot dfd9045221 Remove host fchmod(2) calls from the sentry.
fchmod(2) is not part of sentry's seccomp filters. So the sentry
should not be trying to make this syscall. Instead we will error
out gracefully. Violating seccomp filters will kill the entire
sandbox.

There was only one instance in host filesystem (both in VFS1
and VFS2). I am only fixing VFS2, because VFS1 is already
deprecated. I manually checked that all other host syscalls
made by fsimpl/host are allowed by sentry seccomp filters.

PiperOrigin-RevId: 460335687
2022-07-11 17:16:11 -07:00
Kevin KrakauerandgVisor bot 9050184c20 switch fsimpl/ from sync/atomic to atomicbitops for 32 bit values
PiperOrigin-RevId: 443535714
2022-04-21 18:32:04 -07:00
Kevin KrakauerandgVisor bot 019e0c9301 use atomicbitops, not sync/atomic, in refsvfs2
Since refsvfs2 are used in netstack, we should use atomicbitops to avoid
breaking 32-bit builds.

On 64-bit builds there is no performance difference.

PiperOrigin-RevId: 439687980
2022-04-05 15:16:01 -07:00
Fabricio VoznikaandgVisor bot dfcf798425 Fix epoll_ctl(2) regular files and dirs
Linux behaves differently for regular files and dirs for poll(2)/select(2)
compared to epoll_ctl(2). The latter returns EPERM for file and dirs.
I've also changed host FDs to behave like the underlying FD in regards
to epoll to keep it compatible with docker.

Fixes #7134

PiperOrigin-RevId: 429412692
2022-02-17 15:12:36 -08:00