fix(libkernel): fail an ioctl request pipe_ioctl does not handle with ENOTTY on a pipe, as FreeBSD 11.4 does #22296

Merged
brajankw merged 2 commits from upstream-pr/22296 into main 2026-11-17 13:05:56 +00:00
brajankw commented 2026-11-17 11:20:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T11:20:31Z.


What

Builds on #22295, which this branch contains; review its last commit.

A well-formed ioctl request on a pipe or FIFO that has no case for every descriptor (FIOCLEX, FIONCLEX, FIONBIO, FIONREAD, FIOASYNC, termios) threw. Examples are FIONWRITE, FIONSPACE, FIODTYPE and any request outside groups f and t. In FreeBSD 11.4, kern_ioctl passes such a request to pipe_ioctl (sys/kern/sys_pipe.c:1346-1419), whose default returns ENOTTY, and a FIFO uses the same pipe operations (fifo_open, sys/fs/fifofs/fifo_vnops.c:252). On a pipe above descriptor 2, the request now fails with ENOTTY and leaves its argument alone. An input argument is first copied in as sys_ioctl does, so an unreadable one fails with EFAULT. An IOC_VOID request passes its argument by value, so nothing is copied for it. The existing null-argument check in File::Ioctl follows that rule too; sockets keep their own check in Udp.cpp. So an IOC_IN|IOC_VOID request with a null argument, which used to fail with EFAULT, now gets ENOTTY on a pipe above descriptor 2, on a kqueue or for a t group request, as on FreeBSD, and reaches the existing throw on a file (one read from app0.zar included), a directory, the random device or another device.

  • Descriptors 0 to 2 are not taken as pipes, whatever the host attaches to them, as Terminal.cpp and poll already treat them, so such requests still throw there.
  • FIOSETOWN and FIOGETOWN still throw on a pipe, since the pipe's SIGIO owner is not kept here; #9557 and #9566 implement it.
  • TIOCSPGRP and TIOCGPGRP keep the ENOTTY that every termios request gets.
  • GuestKernelIoctlFionread.cpp checks both ends of a pipe, through both ioctl and _ioctl:
    • FIONWRITE, FIONSPACE, FIODTYPE and _IOW('x', 1, int) fail with ENOTTY and leave the argument unchanged;
    • _IOW('x', 1, int) with an unreadable argument fails with EFAULT;
    • FIONWRITE with an unreadable argument still fails with ENOTTY, since nothing is copied out on an error;
    • the IOC_IN|IOC_VOID request 0xa0047801 fails with ENOTTY with a null and with an unreadable argument.
  • Debt fragment: a new ioctl on a pipe entry. It lists first what still differs from FreeBSD: the owner requests and descriptors 0 to 2. The ioctl, _ioctl entry's "any other well-formed request not listed here" now points to it; the entry stays under 1000 characters.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main 47b33132f9 with #22295.

  • ctest -R '^(guest_kernel_ioctl.*|guest_kernel_fcntl.*)$': 3 passed.
  • Negative control: without the change, the new check aborts with ioctl: request 0x40046677 on a pipe is not implemented.
  • Full ctest (6000 tests, -j 12) on this branch and my other five branches of this round, merged onto main 47b33132f9: 5985 passed. All 15 failures also fail on main in the same environment:
    • nine need a .git directory, network access or a passwd entry for the user: conventions_git_errors, test_script_registration, web_library_assets, title_run, title_run_identity, guest_kernel_sys_login, guest_net_ctl, guest_getlogin and guest_getlogin_no_session;
    • six are agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch:
    • #9566 adds the same SetOwnerRequest and GetOwnerRequest constants next to mine in DescriptorControl.cpp, so the two conflict textually.
    • #18457 conflicts with #22295's test.
    • It failed closed on #7121, #9557, #12682, #12688, #12700 and #12965, which conflict with main; none returns ENOTTY for other pipe requests.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #22295
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5355862009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22296). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T11:20:31Z. --- ### What Builds on #22295, which this branch contains; review its last commit. A well-formed `ioctl` request on a pipe or FIFO that has no case for every descriptor (`FIOCLEX`, `FIONCLEX`, `FIONBIO`, `FIONREAD`, `FIOASYNC`, termios) threw. Examples are `FIONWRITE`, `FIONSPACE`, `FIODTYPE` and any request outside groups `f` and `t`. In FreeBSD 11.4, `kern_ioctl` passes such a request to `pipe_ioctl` (`sys/kern/sys_pipe.c:1346-1419`), whose `default` returns `ENOTTY`, and a FIFO uses the same pipe operations (`fifo_open`, `sys/fs/fifofs/fifo_vnops.c:252`). On a pipe above descriptor 2, the request now fails with `ENOTTY` and leaves its argument alone. An input argument is first copied in as `sys_ioctl` does, so an unreadable one fails with `EFAULT`. An `IOC_VOID` request passes its argument by value, so nothing is copied for it. The existing null-argument check in `File::Ioctl` follows that rule too; sockets keep their own check in `Udp.cpp`. So an `IOC_IN|IOC_VOID` request with a null argument, which used to fail with `EFAULT`, now gets `ENOTTY` on a pipe above descriptor 2, on a kqueue or for a `t` group request, as on FreeBSD, and reaches the existing throw on a file (one read from app0.zar included), a directory, the random device or another device. - Descriptors 0 to 2 are not taken as pipes, whatever the host attaches to them, as `Terminal.cpp` and `poll` already treat them, so such requests still throw there. - `FIOSETOWN` and `FIOGETOWN` still throw on a pipe, since the pipe's `SIGIO` owner is not kept here; #9557 and #9566 implement it. - `TIOCSPGRP` and `TIOCGPGRP` keep the `ENOTTY` that every termios request gets. - `GuestKernelIoctlFionread.cpp` checks both ends of a pipe, through both `ioctl` and `_ioctl`: - `FIONWRITE`, `FIONSPACE`, `FIODTYPE` and `_IOW('x', 1, int)` fail with `ENOTTY` and leave the argument unchanged; - `_IOW('x', 1, int)` with an unreadable argument fails with `EFAULT`; - `FIONWRITE` with an unreadable argument still fails with `ENOTTY`, since nothing is copied out on an error; - the `IOC_IN|IOC_VOID` request `0xa0047801` fails with `ENOTTY` with a null and with an unreadable argument. - Debt fragment: a new `ioctl on a pipe` entry. It lists first what still differs from FreeBSD: the owner requests and descriptors 0 to 2. The `ioctl, _ioctl` entry's "any other well-formed request not listed here" now points to it; the entry stays under 1000 characters. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `47b33132f9` with #22295. - `ctest -R '^(guest_kernel_ioctl.*|guest_kernel_fcntl.*)$'`: 3 passed. - Negative control: without the change, the new check aborts with `ioctl: request 0x40046677 on a pipe is not implemented`. - Full `ctest` (6000 tests, `-j 12`) on this branch and my other five branches of this round, merged onto `main` `47b33132f9`: 5985 passed. All 15 failures also fail on `main` in the same environment: - nine need a `.git` directory, network access or a passwd entry for the user: `conventions_git_errors`, `test_script_registration`, `web_library_assets`, `title_run`, `title_run_identity`, `guest_kernel_sys_login`, `guest_net_ctl`, `guest_getlogin` and `guest_getlogin_no_session`; - six are `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own). - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: - #9566 adds the same `SetOwnerRequest` and `GetOwnerRequest` constants next to mine in `DescriptorControl.cpp`, so the two conflict textually. - #18457 conflicts with #22295's test. - It failed closed on #7121, #9557, #12682, #12688, #12700 and #12965, which conflict with `main`; none returns `ENOTTY` for other pipe requests. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #22295 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 11:30:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T11:30:59Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ec2bf019bb:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_fcntl_tests, guest_kernel_ioctl_fionread_tests built cleanly.
  • CTest (guest_kernel_fcntl, guest_kernel_ioctl_fionread):
    1/2 Test #5566: guest_kernel_ioctl_fionread ......   Passed    0.04 sec
    2/2 Test #5562: guest_kernel_fcntl ...............   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libkernel/File/src/DescriptorControl.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #5562: guest_kernel_fcntl ...............Subprocess aborted***Exception:   0.84 sec
    2/2 Test #5566: guest_kernel_ioctl_fionread ......Subprocess aborted***Exception:   0.93 sec
    0% tests passed, 2 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified DescriptorControl.cpp:579-581 handling of RequestVoid vs RequestIn: copied length correctly masks out void commands so IOC_VOID requests do not require non-null arguments or copy-in
    • Verified DescriptorControl.cpp:589-594 handling of NonblockingRequest and AsynchronousRequest: GuestCopyIn correctly checks argument validity before updating descriptor flags
    • Verified DescriptorControl.cpp:604-610 pipe ioctl handling: descriptors 0-2 and owner requests (FIOSETOWN/FIOGETOWN) are excluded, payload size copied accurately uses GuestCopyIn_nid_no_patch and returns GuestEfault on invalid guest memory before returning GuestEnotty
    • Verified docs/dev/debt/changes/ technical debt fragments follow repo format and accurately document FIOASYNC and pipe ioctl ENOTTY behavior matching FreeBSD 11.4
    • Verified test coverage in GuestKernelFcntl.cpp and GuestKernelIoctlFionread.cpp covers read/write pipe ends, IOC_VOID, input copying, EFAULT on bad pointers, and ENOTTY on unknown requests

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5937632299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22296#pullrequestreview-5937632299). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T11:30:59Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ec2bf019bb`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_fcntl_tests`, `guest_kernel_ioctl_fionread_tests` built cleanly. - **CTest** (`guest_kernel_fcntl`, `guest_kernel_ioctl_fionread`): ``` 1/2 Test #5566: guest_kernel_ioctl_fionread ...... Passed 0.04 sec 2/2 Test #5562: guest_kernel_fcntl ............... Passed 0.05 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #5562: guest_kernel_fcntl ...............Subprocess aborted***Exception: 0.84 sec 2/2 Test #5566: guest_kernel_ioctl_fionread ......Subprocess aborted***Exception: 0.93 sec 0% tests passed, 2 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Verified DescriptorControl.cpp:579-581 handling of RequestVoid vs RequestIn: copied length correctly masks out void commands so IOC_VOID requests do not require non-null arguments or copy-in - Verified DescriptorControl.cpp:589-594 handling of NonblockingRequest and AsynchronousRequest: GuestCopyIn correctly checks argument validity before updating descriptor flags - Verified DescriptorControl.cpp:604-610 pipe ioctl handling: descriptors 0-2 and owner requests (FIOSETOWN/FIOGETOWN) are excluded, payload size copied accurately uses GuestCopyIn_nid_no_patch and returns GuestEfault on invalid guest memory before returning GuestEnotty - Verified docs/dev/debt/changes/ technical debt fragments follow repo format and accurately document FIOASYNC and pipe ioctl ENOTTY behavior matching FreeBSD 11.4 - Verified test coverage in GuestKernelFcntl.cpp and GuestKernelIoctlFionread.cpp covers read/write pipe ends, IOC_VOID, input copying, EFAULT on bad pointers, and ENOTTY on unknown requests Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22296
No description provided.