fix(libkernel_sys): safely probe the list and timeout of aio_suspend #20604

Merged
milescoviello merged 1 commit from upstream-pr/20604 into main 2026-11-15 11:33:52 +00:00
milescoviello commented 2026-11-15 10:56:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T10:56:27Z.


What

aio_suspend read the timeout with *timeout, then compared each queued job against list[index] straight through the guest pointer on every wake-up. An unmapped timeout, or an unmapped list while a job was queued, faulted the host.

The list (at most 256 entries, the existing count limit) is now copied into a local array once with GuestCopyIn_nid_no_patch, and the timeout is copied into a local KernelTimespec the same way, before the wait starts. This is also what FreeBSD's aio_suspend does: it copyins the list and the timeout up front. An unreadable list or timeout fails with EFAULT, which is what the null list already returns here and what aio_waitcomplete in the same file returns for an unreadable timeout. The EINVAL count and timeout checks, EAGAIN on timeout and the null-entry skipping are unchanged.

The debt entry goes in a fragment under docs/dev/debt/changes/ and records this as unmeasured.

Tested

Linux (Ubuntu 26.04.1), GCC 15.2, Release.

  • guest_kernel_sys_aio:

    • an unmapped timeout (0x10) returns -1 with EFAULT;
    • an unmapped list while a held read is queued returns -1 with EFAULT;
    • new valid-pointer case: a two-entry list {nullptr, &request} with a 5 ms timeout returns 0 for the completed request.

    The existing count, null-list, bad-timeout, cancel and timeout cases still pass.

  • Negative control: with Aio.cpp from main, the test segfaults with both new unmapped cases, and again with only the unmapped-list case.

  • git merge-tree against the open PRs that touch Aio.cpp or the test (#18190, #18112, #16191, #13730): no conflicts.

  • tools/check_conventions.py passes on the branch and this body; tools/debt_fold.py --check passes with the fragment applied to main.

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:5321996887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20604). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-15T10:56:27Z. --- ### What `aio_suspend` read the timeout with `*timeout`, then compared each queued job against `list[index]` straight through the guest pointer on every wake-up. An unmapped timeout, or an unmapped list while a job was queued, faulted the host. The list (at most 256 entries, the existing `count` limit) is now copied into a local array once with `GuestCopyIn_nid_no_patch`, and the timeout is copied into a local `KernelTimespec` the same way, before the wait starts. This is also what FreeBSD's `aio_suspend` does: it `copyin`s the list and the timeout up front. An unreadable list or timeout fails with `EFAULT`, which is what the null list already returns here and what `aio_waitcomplete` in the same file returns for an unreadable timeout. The `EINVAL` count and timeout checks, `EAGAIN` on timeout and the null-entry skipping are unchanged. The debt entry goes in a fragment under `docs/dev/debt/changes/` and records this as unmeasured. ### Tested Linux (Ubuntu 26.04.1), GCC 15.2, Release. - `guest_kernel_sys_aio`: - an unmapped timeout (`0x10`) returns -1 with `EFAULT`; - an unmapped list while a held read is queued returns -1 with `EFAULT`; - new valid-pointer case: a two-entry list `{nullptr, &request}` with a 5 ms timeout returns 0 for the completed request. The existing count, null-list, bad-timeout, cancel and timeout cases still pass. - Negative control: with `Aio.cpp` from `main`, the test segfaults with both new unmapped cases, and again with only the unmapped-list case. - `git merge-tree` against the open PRs that touch `Aio.cpp` or the test (#18190, #18112, #16191, #13730): no conflicts. - `tools/check_conventions.py` passes on the branch and this body; `tools/debt_fold.py --check` passes with the fragment applied to `main`. ### 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) 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
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!20604
No description provided.