fix(libkernel): fail read and write with a null buffer on a kqueue with EOPNOTSUPP, as FreeBSD 11.4 does #24486

Merged
brajankw merged 1 commit from upstream-pr/24486 into main 2026-11-21 15:17:38 +00:00
brajankw commented 2026-11-20 17:25:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-20T17:25:32Z.


What

read, _read, write and _write on a kqueue failed with EFAULT when the buffer was null and the length was not 0. FreeBSD 11.4's kqueueops reads and writes through invfo_rdwr, which fails with EOPNOTSUPP without touching the buffer, so a null buffer gets the same EOPNOTSUPP as any other. A zero-length read still returns 0 first.

  • Tests: KqueueDescriptorOperations in GuestKqueue.cpp, through all four exports.
  • Debt: no fragment.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head aac46a0afc, the single commit on main c8f72e905c.

  • Negative control: with only the test change, on main 84e16538d4, guest_kqueue aborts at the new null-buffer checks.
  • On aac46a0afc, ctest over guest_kernel_sys_ksem, guest_kqueue, guest_kernel_sys, guest_filesystem, guest_file_vector, guest_kernel_sys_aio, guest_equeue_events, guest_kernel_fcntl, guest_kernel_ioctl_fionread and guest_kernel_ioctl_device_type: all 10 pass.
  • Full ctest (6393 tests, -j 12) on this branch and my other eleven branches of this round, merged onto main 84e16538d4: 6378 passed. The 15 failures also fail on main in this 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;
    • five agc_driver GPU cases fail the same way on main: prepared_shaders with its indirect, uncached and debug forms, and storage_file_write;
    • agc_driver_image_table_packed_guards is unstable on main as well (2 of 10 runs passed on its own on main 3f4693be43).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch fix/libkernel-kqueue-null-buffer-eopnotsupp: could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict with main in Stdio.cpp; #12682, #12688, #12700 and #12965 move the callers of TransferArgumentError but do not change it, and none of the others touches it.
  • 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5417523213 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24486). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-20T17:25:32Z. --- ### What `read`, `_read`, `write` and `_write` on a kqueue failed with `EFAULT` when the buffer was null and the length was not 0. FreeBSD 11.4's `kqueueops` reads and writes through [`invfo_rdwr`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_descrip.c#L4029-L4034), which fails with `EOPNOTSUPP` without touching the buffer, so a null buffer gets the same `EOPNOTSUPP` as any other. A zero-length read still returns 0 first. - Tests: `KqueueDescriptorOperations` in `GuestKqueue.cpp`, through all four exports. - Debt: no fragment. ### 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). Head `aac46a0afc`, the single commit on `main` `c8f72e905c`. - Negative control: with only the test change, on `main` `84e16538d4`, `guest_kqueue` aborts at the new null-buffer checks. - On `aac46a0afc`, `ctest` over `guest_kernel_sys_ksem`, `guest_kqueue`, `guest_kernel_sys`, `guest_filesystem`, `guest_file_vector`, `guest_kernel_sys_aio`, `guest_equeue_events`, `guest_kernel_fcntl`, `guest_kernel_ioctl_fionread` and `guest_kernel_ioctl_device_type`: all 10 pass. - Full `ctest` (6393 tests, `-j 12`) on this branch and my other eleven branches of this round, merged onto `main` `84e16538d4`: 6378 passed. The 15 failures also fail on `main` in this 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`; - five `agc_driver` GPU cases fail the same way on `main`: `prepared_shaders` with its `indirect`, `uncached` and `debug` forms, and `storage_file_write`; - `agc_driver_image_table_packed_guards` is unstable on `main` as well (2 of 10 runs passed on its own on `main` `3f4693be43`). - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch fix/libkernel-kqueue-null-buffer-eopnotsupp`: could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict with `main` in `Stdio.cpp`; #12682, #12688, #12700 and #12965 move the callers of `TransferArgumentError` but do not change it, and none of the others touches it. - 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-21 05:43:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:43:04Z.

Review: APPROVED


Reviewed — looks good

The reviewed head is aac46a0afce8eae449069c91c9f7284ed2eb50c2; the inspected change correctly bypasses null-buffer validation for kqueue descriptors before the read/write calls, allowing the kqueue operation to produce its unsupported-operation error. Nothing blocks this; the points below are optional.

What I ran

No commands or tests were run in this review. I read the prepared description, commits, manifest and diff, plus the changed code and its directly relevant callers at the pinned head.

Results

Check Result Note
Source review passed Both changed files inspected
Tests not run Results in the description are author-reported
Platform coverage not run Windows and macOS unverified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or builds were run. I did not verify the author-reported test results or behavior on Windows, macOS, or a physical console. Files read: core/libs/prx/libkernel/File/src/Stdio.cpp (relevant argument validation and read/write callers), core/libs/tests/GuestKqueue.cpp (kqueue descriptor operation tests), and review/description.md, review/commits.md, review/manifest.json, and review/diff.patch. Excluded files: none; the manifest lists only the two changed files, and both were read at the relevant ranges.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003238583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24486#pullrequestreview-6003238583). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T05:43:04Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed head is `aac46a0afce8eae449069c91c9f7284ed2eb50c2`; the inspected change correctly bypasses null-buffer validation for kqueue descriptors before the read/write calls, allowing the kqueue operation to produce its unsupported-operation error. Nothing blocks this; the points below are optional. ## What I ran No commands or tests were run in this review. I read the prepared description, commits, manifest and diff, plus the changed code and its directly relevant callers at the pinned head. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Both changed files inspected | | Tests | not run | Results in the description are author-reported | | Platform coverage | not run | Windows and macOS unverified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or builds were run. I did not verify the author-reported test results or behavior on Windows, macOS, or a physical console. Files read: `core/libs/prx/libkernel/File/src/Stdio.cpp` (relevant argument validation and read/write callers), `core/libs/tests/GuestKqueue.cpp` (kqueue descriptor operation tests), and `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch`. Excluded files: none; the manifest lists only the two changed files, and both were read at the relevant ranges. ## To get this to a good state Nothing is required.
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!24486
No description provided.