fix(libkernel): return ENOTTY for malformed ioctl requests #5569

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/5569 into main
MarcZX10 commented 2026-10-14 00:08:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:08:21Z.


What

Fixes #5564. Validate the encoded ioctl request before reading its argument or looking up the descriptor, returning ENOTTY for malformed requests on files, pipes, directories, sockets, and invalid descriptors. The malformed cases follow FreeBSD's sys_ioctl: no direction bit, an output request with zero length, or a void request whose length is not sizeof(int). Input-only requests with zero length are left to the existing path because FreeBSD behavior depends on compatibility options and the console configuration is unknown.

Hussein Kadhim's implementation commit is carried with his original author attribution preserved. The existing behavior for well-formed requests is unchanged. The issue's overlap scan noted only a shared docs/dev/debt/libkernel.md line with #5451, #5020 and #5053; there is no implementation dependency, and a later debt-line merge may need a small rebase.

Tested

Linux, GCC 12.2, Ninja Release, BUILD_TESTING=ON, current main d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca:

  • Built guest_kernel_fcntl_tests, guest_udp_tests, and guest_sendfile_tests.
  • guest_kernel_fcntl and guest_sendfile passed three consecutive CTest runs each (6/6).
  • Baseline control: with the new guest_kernel_fcntl checks retained but the three implementation files restored from current main, guest_kernel_fcntl aborts as expected; with the fix restored, it passes 3/3.
  • guest_udp passed once and then aborted on a repeated run. The same intermittent abort reproduced with Udp.cpp restored from current main, so I am not claiming that test passed reliably in this environment.
  • tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD passed.
  • Windows was not run locally; the issue records the source author's Windows test results and request-word probe.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • 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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes; reviewed and tested by MarcZX100
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851077905 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5569). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T00:08:21Z. --- ### What Fixes #5564. Validate the encoded `ioctl` request before reading its argument or looking up the descriptor, returning `ENOTTY` for malformed requests on files, pipes, directories, sockets, and invalid descriptors. The malformed cases follow FreeBSD's `sys_ioctl`: no direction bit, an output request with zero length, or a void request whose length is not `sizeof(int)`. Input-only requests with zero length are left to the existing path because FreeBSD behavior depends on compatibility options and the console configuration is unknown. Hussein Kadhim's implementation commit is carried with his original author attribution preserved. The existing behavior for well-formed requests is unchanged. The issue's overlap scan noted only a shared `docs/dev/debt/libkernel.md` line with #5451, #5020 and #5053; there is no implementation dependency, and a later debt-line merge may need a small rebase. ### Tested Linux, GCC 12.2, Ninja Release, `BUILD_TESTING=ON`, current `main` `d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca`: - Built `guest_kernel_fcntl_tests`, `guest_udp_tests`, and `guest_sendfile_tests`. - `guest_kernel_fcntl` and `guest_sendfile` passed three consecutive CTest runs each (6/6). - Baseline control: with the new `guest_kernel_fcntl` checks retained but the three implementation files restored from current `main`, `guest_kernel_fcntl` aborts as expected; with the fix restored, it passes 3/3. - `guest_udp` passed once and then aborted on a repeated run. The same intermittent abort reproduced with `Udp.cpp` restored from current `main`, so I am not claiming that test passed reliably in this environment. - `tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...HEAD` passed. - Windows was not run locally; the issue records the source author's Windows test results and request-word probe. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [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) - [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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes; reviewed and tested by MarcZX100
github-actions[bot] commented 2026-10-14 00:22:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T00:22:37Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5020 docs/dev/debt/libkernel.md L161-162
#5053 docs/dev/debt/libkernel.md L162
#5186 core/libs/tests/GuestKernelFcntl.cpp L65
docs/dev/debt/libkernel.md L162
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158043681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5569#issuecomment-6158043681). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T00:22:37Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5020 | `docs/dev/debt/libkernel.md` [L161-162](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/docs/dev/debt/libkernel.md#L161-L162) | | | | #5053 | `docs/dev/debt/libkernel.md` [L162](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/docs/dev/debt/libkernel.md#L162) | | | | #5186 | `core/libs/tests/GuestKernelFcntl.cpp` [L65](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/core/libs/tests/GuestKernelFcntl.cpp#L65)<br>`docs/dev/debt/libkernel.md` [L162](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/docs/dev/debt/libkernel.md#L162) | | |
oneandonlydean commented 2026-10-14 01:08:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:08:11Z.


Closing: no title is known to reach this. With the queue at 750 open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158591662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5569#issuecomment-6158591662). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:08:11Z. --- Closing: no title is known to reach this. With the queue at 750 open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5569
No description provided.