Repository navigation
devpts: return ESPIPE on positional read and write - #14505
Merged
copybara-service[bot] merged 1 commit intoSep 28, 2026
Merged
Conversation
rexren-gif
approved these changes
Sep 28, 2026
copybara-service Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Positional I/O (`pread`, `pwrite`, `preadv`, `pwritev`, `preadv2`, `pwritev2` with an offset) on Linux pseudo-terminals fails with `ESPIPE`. In gVisor, `masterFileDescription` and `replicaFileDescription` inherited `FileDescriptionDefaultImpl`, which returns `EINVAL` when `opts.DenyPRead` and `opts.DenyPWrite` are false. Set `DenyPRead` and `DenyPWrite` in `FileDescriptionOptions` when initializing both master and replica file descriptions so positional reads and writes return `ESPIPE`. Fixes #13738. FUTURE_COPYBARA_INTEGRATE_REVIEW=#14505 from adi-IL:fix/devpts-positional-io-espipe 3270e65 PiperOrigin-RevId: 989705902
copybara-service Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Positional I/O (`pread`, `pwrite`, `preadv`, `pwritev`, `preadv2`, `pwritev2` with an offset) on Linux pseudo-terminals fails with `ESPIPE`. In gVisor, `masterFileDescription` and `replicaFileDescription` inherited `FileDescriptionDefaultImpl`, which returns `EINVAL` when `opts.DenyPRead` and `opts.DenyPWrite` are false. Set `DenyPRead` and `DenyPWrite` in `FileDescriptionOptions` when initializing both master and replica file descriptions so positional reads and writes return `ESPIPE`. Fixes #13738. FUTURE_COPYBARA_INTEGRATE_REVIEW=#14505 from adi-IL:fix/devpts-positional-io-espipe 3270e65 PiperOrigin-RevId: 989705902
copybara-service Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Positional I/O (`pread`, `pwrite`, `preadv`, `pwritev`, `preadv2`, `pwritev2` with an offset) on Linux pseudo-terminals fails with `ESPIPE`. In gVisor, `masterFileDescription` and `replicaFileDescription` inherited `FileDescriptionDefaultImpl`, which returns `EINVAL` when `opts.DenyPRead` and `opts.DenyPWrite` are false. Set `DenyPRead` and `DenyPWrite` in `FileDescriptionOptions` when initializing both master and replica file descriptions so positional reads and writes return `ESPIPE`. Fixes #13738. FUTURE_COPYBARA_INTEGRATE_REVIEW=#14505 from adi-IL:fix/devpts-positional-io-espipe 3270e65 PiperOrigin-RevId: 989705902
copybara-service Bot
pushed a commit
that referenced
this pull request
Sep 28, 2026
Positional I/O (`pread`, `pwrite`, `preadv`, `pwritev`, `preadv2`, `pwritev2` with an offset) on Linux pseudo-terminals fails with `ESPIPE`. In gVisor, `masterFileDescription` and `replicaFileDescription` inherited `FileDescriptionDefaultImpl`, which returns `EINVAL` when `opts.DenyPRead` and `opts.DenyPWrite` are false. Set `DenyPRead` and `DenyPWrite` in `FileDescriptionOptions` when initializing both master and replica file descriptions so positional reads and writes return `ESPIPE`. Fixes #13738. FUTURE_COPYBARA_INTEGRATE_REVIEW=#14505 from adi-IL:fix/devpts-positional-io-espipe 3270e65 PiperOrigin-RevId: 989705902
This was referenced Oct 8, 2026
milantracy
pushed a commit
that referenced
this pull request
Nov 24, 2026
gVisor treats a PTY master as hung up whenever it has no open replica file descriptors, including before any replica has been opened. In that state, poll() on the master reports POLLHUP and read() fails with EIO. A program that opens a PTY, forks a child that opens the replica, and reads the master at once sees a hang up if the read runs before the child opens the replica. Local Nix builds fail at random under runsc because of this ([NixOS/nix#15181](NixOS/nix#15181)). Nix reads the builder's startup line from a PTY master while the forked builder opens the replica. When the read runs first, Nix fails with "unexpected EOF reading a line". A minimal reproduction example for this: ```python import os, fcntl, struct, select m = os.open("/dev/ptmx", os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) fcntl.ioctl(m, 0x40045431, struct.pack("i", 0)) # TIOCSPTLCK p = select.poll(); p.register(m, select.POLLIN | select.POLLOUT) print("revents:", p.poll(0)) try: os.read(m, 1) except OSError as e: print("read:", e.strerror) ``` ``` poll read Linux 7.3.1 POLLOUT EAGAIN runsc, without fix POLLOUT|POLLHUP EIO runsc, with fix POLLOUT EAGAIN ``` There's been some related work on this as well: PR #14505 closed #13738, but it fixed a different devpts bug (ESPIPE on positional I/O); this change _actually_ fixes the bug the issue reports. The POLLHUP for a master without replicas came from the fix for #9951 and #9333, which still work because they close a replica that was opened. Fixes #13738. (I think it makes sense to re-open that one, since it's still valid, and have it closed by this pr?) Signed-off-by: faukah <[email protected]>
EtiennePerot
pushed a commit
that referenced
this pull request
Nov 26, 2026
gVisor treats a PTY master as hung up whenever it has no open replica file descriptors, including before any replica has been opened. In that state, poll() on the master reports POLLHUP and read() fails with EIO. A program that opens a PTY, forks a child that opens the replica, and reads the master at once sees a hang up if the read runs before the child opens the replica. Local Nix builds fail at random under runsc because of this ([NixOS/nix#15181](NixOS/nix#15181)). Nix reads the builder's startup line from a PTY master while the forked builder opens the replica. When the read runs first, Nix fails with "unexpected EOF reading a line". A minimal reproduction example for this: ```python import os, fcntl, struct, select m = os.open("/dev/ptmx", os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK) fcntl.ioctl(m, 0x40045431, struct.pack("i", 0)) # TIOCSPTLCK p = select.poll(); p.register(m, select.POLLIN | select.POLLOUT) print("revents:", p.poll(0)) try: os.read(m, 1) except OSError as e: print("read:", e.strerror) ``` ``` poll read Linux 7.3.1 POLLOUT EAGAIN runsc, without fix POLLOUT|POLLHUP EIO runsc, with fix POLLOUT EAGAIN ``` There's been some related work on this as well: PR #14505 closed #13738, but it fixed a different devpts bug (ESPIPE on positional I/O); this change _actually_ fixes the bug the issue reports. The POLLHUP for a master without replicas came from the fix for #9951 and #9333, which still work because they close a replica that was opened. Fixes #13738. (I think it makes sense to re-open that one, since it's still valid, and have it closed by this pr?) Signed-off-by: faukah <[email protected]> (cherry picked from commit 5cc6d03)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Positional I/O (
pread,pwrite,preadv,pwritev,preadv2,pwritev2with an offset) on Linux pseudo-terminals fails withESPIPE.In gVisor,
masterFileDescriptionandreplicaFileDescriptioninheritedFileDescriptionDefaultImpl, which returnsEINVALwhenopts.DenyPReadandopts.DenyPWriteare false.Set
DenyPReadandDenyPWriteinFileDescriptionOptionswhen initializing both master and replica file descriptions so positional reads and writes returnESPIPE.Fixes #13738.