fix(libkernel_sys): record EINVAL in the aiocb for oversized and unsigned-signal aio requests #16191

Closed
MarcZX10 wants to merge 4 commits from upstream-pr/16191 into main
MarcZX10 commented 2026-11-05 20:35:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-05T20:35:49Z.


What

Queue() in core/libs/prx/libkernel_sys/Aio.cpp rejects two requests with Fail(GuestEinval), which sets errno but does not store the error in the guest aiocb. The request is never queued, but status stays -1 and error stays 0 (set on entry), so a following aio_error() reports the rejected request as completed without error. The other rejection paths in the same function go through the local fail() helper, which records the error in the aiocb.

Affected checks:

  • nbytes > INT_MAX: fix e3cebfb6a2, test dd23eece9d
  • SIGEV_SIGNAL / SIGEV_THREAD_ID with signo outside 1..SignalMax: fix 2ce12e4318, test 8c10407b0e

The fix only changes the two return statements to fail(GuestEinval). The call still returns -1 with EINVAL; the aiocb now carries the same EINVAL that aio_error() reports.

The existing validation test asserted huge.error == 0 for the oversized request, which pinned the defect; it now expects EINVAL.

Overlap and interaction: open PR #14403 adds a copy-in line directly above the nbytes check in Queue(). It does not change the lines this PR changes, but the hunks are adjacent. Merging this branch with #14403 produces a textual conflict in core/libs/prx/libkernel_sys/Aio.cpp (checked with git merge-tree). This PR does not depend on #14403 and is based on upstream/main. #15115 touches aio_suspend and is not affected.

Tested

Linux host (kernel 6.1), throwaway archive build with the CPU startup gate patched.

  • Ran guest_kernel_sys_aio (guest_kernel_sys_aio_tests) on the fixed head 8c10407b0e: build exit 0, 1/1 passed.
  • Negative control, run: with both fixes removed in the archived copy (not committed), the rebuilt test failed at check failed at line 91 (the nbytes case), as expected.
  • Negative control not run: the signo-only control (only the signo fix removed). The signo case is therefore not individually shown to fail without its fix.
  • python3 tools/check_conventions.py --base upstream/main: passed. git diff --check upstream/main: clean.
  • tools/pr_precheck.py (no-build): conventions and ABI audit passed; build-dependent C++ tests reported not run by that tool, which the build above covers.
  • No export changed, so the public-headers audit was not run.

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
  • 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:5178323721 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16191). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-05T20:35:49Z. --- ### What `Queue()` in `core/libs/prx/libkernel_sys/Aio.cpp` rejects two requests with `Fail(GuestEinval)`, which sets errno but does not store the error in the guest `aiocb`. The request is never queued, but `status` stays -1 and `error` stays 0 (set on entry), so a following `aio_error()` reports the rejected request as completed without error. The other rejection paths in the same function go through the local `fail()` helper, which records the error in the aiocb. Affected checks: - `nbytes > INT_MAX`: fix `e3cebfb6a2`, test `dd23eece9d` - `SIGEV_SIGNAL` / `SIGEV_THREAD_ID` with `signo` outside `1..SignalMax`: fix `2ce12e4318`, test `8c10407b0e` The fix only changes the two `return` statements to `fail(GuestEinval)`. The call still returns -1 with EINVAL; the aiocb now carries the same EINVAL that `aio_error()` reports. The existing validation test asserted `huge.error == 0` for the oversized request, which pinned the defect; it now expects EINVAL. Overlap and interaction: open PR #14403 adds a copy-in line directly above the `nbytes` check in `Queue()`. It does not change the lines this PR changes, but the hunks are adjacent. Merging this branch with #14403 produces a textual conflict in `core/libs/prx/libkernel_sys/Aio.cpp` (checked with `git merge-tree`). This PR does not depend on #14403 and is based on `upstream/main`. #15115 touches `aio_suspend` and is not affected. ### Tested Linux host (kernel 6.1), throwaway archive build with the CPU startup gate patched. - Ran `guest_kernel_sys_aio` (`guest_kernel_sys_aio_tests`) on the fixed head `8c10407b0e`: build exit 0, 1/1 passed. - Negative control, run: with both fixes removed in the archived copy (not committed), the rebuilt test failed at `check failed at line 91` (the `nbytes` case), as expected. - Negative control not run: the signo-only control (only the signo fix removed). The signo case is therefore not individually shown to fail without its fix. - `python3 tools/check_conventions.py --base upstream/main`: passed. `git diff --check upstream/main`: clean. - `tools/pr_precheck.py` (no-build): conventions and ABI audit passed; build-dependent C++ tests reported not run by that tool, which the build above covers. - No export changed, so the public-headers audit was not run. ### Checklist - [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) - [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
gabichuuuuu commented 2026-11-10 11:12:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T11:12:15Z.

Review: COMMENTED


Read 4b9daae4af against main.

Correctness. The two Fail(GuestEinval) returns in Queue (core/libs/prx/libkernel_sys/Aio.cpp) are not an oversight: they reproduce FreeBSD 11.4 aio_aqueue_job (sys/kern/vfs_aio.c), which stores status = -1 and error = 0 on entry, then calls ops->store_error(ujob, ...) for the queue limit, the copy-in failure and a bad sigev_notify, but returns EINVAL without store_error for aio_nbytes > IOSIZE_MAX and for an invalid sigev_signo. FreeBSD's kern_aio_error then takes the "failure of aio_aqueue" path (fetch_status == -1) and returns the stored error, which is 0 for those two cases. So main's aio_error result of 0 for the oversized and bad-signal requests is the reference behaviour, and the huge.error == 0 assertion was pinning it on purpose, next to the notify.error == Einval assertion for the case where FreeBSD does store it. Switching both to fail makes AnyPS5 diverge from FreeBSD with no PS5 measurement given.

Test. The updated assertions fail on main (it leaves error at 0), so they exercise the change, but they encode the non-FreeBSD result. Unless there is console evidence that the PS5 kernel stores EINVAL here, this should stay as it is on main; if there is, cite it and add a libkernel_sys.md entry recording the departure from FreeBSD.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5840903919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16191#pullrequestreview-5840903919). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-10T11:12:15Z. **Review:** COMMENTED --- Read `4b9daae4af` against `main`. **Correctness.** The two `Fail(GuestEinval)` returns in `Queue` (`core/libs/prx/libkernel_sys/Aio.cpp`) are not an oversight: they reproduce FreeBSD 11.4 `aio_aqueue_job` (`sys/kern/vfs_aio.c`), which stores `status = -1` and `error = 0` on entry, then calls `ops->store_error(ujob, ...)` for the queue limit, the copy-in failure and a bad `sigev_notify`, but returns `EINVAL` without `store_error` for `aio_nbytes > IOSIZE_MAX` and for an invalid `sigev_signo`. FreeBSD's `kern_aio_error` then takes the "failure of aio_aqueue" path (`fetch_status == -1`) and returns the stored error, which is 0 for those two cases. So `main`'s `aio_error` result of 0 for the oversized and bad-signal requests is the reference behaviour, and the `huge.error == 0` assertion was pinning it on purpose, next to the `notify.error == Einval` assertion for the case where FreeBSD does store it. Switching both to `fail` makes AnyPS5 diverge from FreeBSD with no PS5 measurement given. **Test.** The updated assertions fail on `main` (it leaves `error` at 0), so they exercise the change, but they encode the non-FreeBSD result. Unless there is console evidence that the PS5 kernel stores EINVAL here, this should stay as it is on `main`; if there is, cite it and add a `libkernel_sys.md` entry recording the departure from FreeBSD. Not run here; this is from reading the code. AI-assisted: yes.

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