79 Commits
Author SHA1 Message Date
Nicolas LacasseandgVisor bot 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
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
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 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 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
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
dongjinlong ba02461e12 chore: remove repetitive words in comments
Signed-off-by: dongjinlong <dongjinlong@outlook.com>
2024-03-26 19:57:40 +08:00
gVisor bot 52af950390 Merge pull request #9954 from thecodingwizard:fix-pty-eof
PiperOrigin-RevId: 609075893
2024-02-21 12:02:14 -08:00
gVisor bot 3a73915fcc Merge pull request #9950 from thecodingwizard:master
PiperOrigin-RevId: 605691085
2024-02-09 11:47:53 -08:00
Ayush RanjanandgVisor bot cdededb792 Notify master waiter when all replicas are closed.
Fixes #9951
Fixes #9333

PiperOrigin-RevId: 605462571
2024-02-08 16:41:01 -08:00
Nathan Wang 0a818095d9 Add partial support for VERASE and VWERASE in canonical mode in PTYs 2024-02-08 01:59:41 +00:00
Nathan Wang ff34288f92 Fix EOFs when reading from empty canon->noncanon PTY
when switching from canonical to non-canonical mode, only mark inQueue as readable if there is input to be read
2024-02-02 23:50:03 +00:00
Nathan Wang 89c034566e Do not return ErrWouldBlock when writing nothing to PTY replica output
Previously, writing an empty string to the PTY replica output queue
would return linux.ErrWouldBlock. This PR fixes this behavior to
not return an error.
2024-02-01 20:38:59 +00: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
Etienne PerotandgVisor bot 917bee5b6d Add a size limit to outputQueueTransformer.transform.
This applies a similar limit as `inputQueueTransformer.transform`.

The goal is to avoid large allocations of memory.

I'm not sure if this is the right thing to do, but it seems better than the
status quo of not having any limits.

PiperOrigin-RevId: 581034478
2023-11-09 14:59:32 -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
gVisor bot 4146284b60 Merge pull request #9339 from kevinGC:tcsetsf2
PiperOrigin-RevId: 563207341
2023-09-06 13:58:08 -07:00
gVisor bot 0230a371c2 Merge pull request #9336 from thundergolfer:jonathon/dev-pts-eof-handling
PiperOrigin-RevId: 563199056
2023-09-06 13:29:19 -07:00
Jonathon Belotti e8c399a093 Fix EOF (^D) handling in devpts (partially addr #9333) 2023-09-06 01:18:18 +00:00
Kevin Krakauer 7928ff6f0c tty: enable TCSETSF
While there is a difference between flavors of this ioctl (`TCSETS`,
`TCSETSF`, `TCSETSW`), in practice it seems not to matter. We should let
users call `TCSETSF` and can implement those differences if necessary.
2023-09-05 09:53:50 -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
gVisor bot 243aeddd59 [pty] Return enqueued data and then EIO if the replica is closed
PiperOrigin-RevId: 532496868
2023-05-16 10:15:01 -07: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