1000 Commits

Author SHA1 Message Date
Lucas Manning 8482715727 Enable save/restore with TPUproxy.
This change also adds some small cleanup to TPU code.

PiperOrigin-RevId: 737673712
2025-03-17 10:55:06 -07:00
Nicolas Lacasse 6b0a0af862 Implement basic packet mode support for ptys.
From man TIOCPKT:
"""
In packet mode, each subsequent read(2) will return a packet that either
contains a single nonzero control byte, or has a single byte containing zero
('\0') followed by data written on the slave side of the pseudoterminal."
"""

This CL implements only the data portion of packet mode, not the control bytes,
but that seems to be enough to get xfce4-terminal to work.

PiperOrigin-RevId: 737175092
2025-03-15 09:26:56 -07:00
Jamie Liu 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
Lucas Manning 11aeff69c2 Fix host-backed event FD restore.
Before this change, host-backed event FDs would always crash the sandbox
during exit when the sentry tried to wait on the fdnotifier for an FD that
wasn't there.

PiperOrigin-RevId: 736585573
2025-03-13 11:51:37 -07:00
Nicolas Lacasse 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
Ayush Ranjan f06d4e7ebe goferfs: Add S/R support for open FDs to deleted files.
This support is only needed when the gofer mount in question is writable.
By default, the rootfs has an overlayfs applied, so the gofer lower layer is
not writabled. But if you are using --overlay2=none, then this change should
allow you to save sandbox with open FDs to deleted files in rootfs.

Updates #11425

PiperOrigin-RevId: 733021267
2025-03-03 12:38:10 -08:00
Fabricio Voznika 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
Jamie Liu d71a9b3df5 gofer: fix ref drop when racily-unlinked synthetic file is invalidated
PiperOrigin-RevId: 732340885
2025-02-28 20:25:53 -08:00
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
Ayush Ranjan 84670a4fc6 gofer: Fix bug when casting auth.K{U/G}ID to int.
auth.K{U/G}ID has type uint32. When uid = auth.NoID = math.MaxUint32, which is
intended to represent -1, and it is casted to int, it becomes 4294967295 on
64-bit systems as int is 8 bytes in size. So the == -1 check fails.

Fixed the bug by explicitly setting syscall args to -1 when uid.Ok() == false.
Similarly, fix the bug in runsc/fsgofer.

PiperOrigin-RevId: 728258705
2025-02-18 10:16:08 -08:00
Ayush Ranjan 67b2e7327f gofer: Cleanup unlock code.
Use defers where possible. Makes code more readable.

PiperOrigin-RevId: 727006205
2025-02-14 11:47:06 -08:00
Nicolas Lacasse a4a0e84b5c Allow sending and importing a host event fd.
PiperOrigin-RevId: 724046820
2025-02-06 13:16:47 -08:00
Jamie Liu 8b7b69c978 tmpfs: limit regularFile.Translate() fill range
When e.g. an application thread takes a page fault on an mmapped file, MM calls
`memmap.Mappable.Translate()` to obtain the corresponding host FD range that
should be mapped into the application's address space. It passes both the range
that *must* be mapped (e.g. the faulting page) as `required`, and the maximum
range that *may* be mapped (the previously-unfaulted part of the corresponding
VMA) as `optional`, such that file implementations can map more than `required`
to avoid future page faults.

Prior to this CL, `tmpfs.regularFile.Translate()` always returned translations
up to `optional`, under the assumption that allocating larger ranges from
`pgalloc.MemoryFile` has negligible incremental cost. This behavior dates to
the introduction of `memmap.Mappable.Translate()` (cl/182882705) and thus
predates the implementation of tmpfs size limits (cl/442686814). Now that the
latter exists, unconditionally translating - and therefore allocating pages -
up to `optional` can result in hitting tmpfs size limits prematurely.

Thus: Constrain optional translations returned by
`tmpfs.regularFile.Translate()`, applying the same logic as
`gofer.maxFillRange()`.
PiperOrigin-RevId: 713134287
2025-01-07 20:25:15 -08:00
gVisor bot 7aa4c49b0d Merge pull request #11291 from xianzhe-databricks:fix-uds-auth
PiperOrigin-RevId: 712981221
2025-01-07 11:25:40 -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
xianzhe-databricks c4f686f4e1 Add a new RPC ConnectWithCreds to allow gofer to connect to a unix domain socket with application's credentials 2025-01-03 17:50:06 +01:00
Fabricio Voznika fb730ff784 Remove checkpoint_count from runsc wait --checkpoint
This is done because external callers are not able to know
the snapshot generation number from the outside.

PiperOrigin-RevId: 707979556
2024-12-19 11:48:10 -08:00
Andrei Vagin 9fcf0b5b53 proc: invalidate task inodes when tasks are destroyed
PiperOrigin-RevId: 705785809
2024-12-13 00:58:08 -08:00
Ayush Ranjan ab9d8455d4 Re-use the same device file inode in tmpfs for overlay whiteout files.
When using overlayfs with tmpfs as the upper layer (common case), depending on
the application, a lot of whiteouts can be created. This leads to a lot of
memory allocation because new dentry and inode structs need to be allocated for
each whiteout. With this change, we at least avoid the inode allocations.

This is analogous with what Linux does. See fs/overlayfs/ovl_entry.h:ovl_fs's
field `whiteout` with comment "Shared whiteout cache".

PiperOrigin-RevId: 704897805
2024-12-10 17:11:22 -08:00
Kevin Krakauer a8e963b095 remove outdated bug references for PTYs
PiperOrigin-RevId: 702986132
2024-12-04 22:43:42 -08:00
gVisor bot ac42faf002 Internal change.
PiperOrigin-RevId: 700478551
2024-11-26 15:37:43 -08:00
Jamie Liu 64e48cc3c6 fsimpl/gofer: implement specialFileFD.InvalidateUnsavable()
This fixes save/restore of mmapped gofer.specialFileFDs (usually obtained via
mount option "disable_file_handle_sharing") for which mappings have actually
been used (mm.pmas have been obtained).

PiperOrigin-RevId: 700465816
2024-11-26 14:46:38 -08:00
Jamie Liu 0e6fe26a3a fsimpl/gofer: hold extra dentry reference if endpoint != nil
Fixes #11202

PiperOrigin-RevId: 700163466
2024-11-25 18:16:22 -08:00
Jamie Liu 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
Andrei Vagin a92fc7b8c9 overlay: remove dirInoCache entries from RmdirAt()
Right now, entries are never removed from dirInoCache and if someone creates
and deletes directories in a loop, they observe memory leaks.

PiperOrigin-RevId: 698195540
2024-11-19 17:14:01 -08:00