tools: an audit of exports that access guest pointer parameters directly, instead of one EFAULT fix per function #14445

Closed
opened 2026-11-01 13:52:54 +00:00 by LeandroLP23 · 0 comments
LeandroLP23 commented 2026-11-01 13:52:54 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-01T13:52:54Z.


One EFAULT fix per function keeps coming. Of the 268 fix pull requests opened on Oct 29–30, 28 add EFAULT (or an unwritable/unreadable-pointer check) to one export each: 17 merged, 8 still open. Examples: #13443, #13537, #13552, #13576, #13577, #13587 and #13582. More single-function issues are open too: #13951, #13955, #13959.

The cause is the same each time. An export reads or writes a guest pointer parameter directly (*out = …, out->field, std::memcpy(out, …), std::strlen(path)), and the fix routes it through GuestCopyOut_nid_no_patch / GuestCopyIn_nid_no_patch or the CopyGuest* helpers in libc/include/General.hpp. The helpers exist, but no rule or tool points at the exports that bypass them, so they are found one per pull request.

Proposal: tools/guest_pointer_audit.py, an audit in the style of import_audit.py, not a CI gate. It reuses progress.py's parsing (APS5_VABI definitions, comment and literal stripping) and, for each exported function, reports the pointer parameters the body uses through ->, [], * or a raw mem*/str*/std::copy call without passing them to one of the safe helpers. Output is file:line: function: parameter (kind) plus a per-library count, or JSON.

A prototype over main e53aff3f56 finds 2,739 such parameter uses in 2,210 exports. The largest groups are libc (345), libkernel (252), libSceNpCppWebApi (232), libSceJson2 (185) and libSceNpCommon (171); libkernel_sys has 23. A random sample of 10 libkernel/libkernel_sys findings were all real direct accesses, for example uuidgen's store[index], which #13187 fixes.

What it doesn't decide. On the console, EFAULT comes from the kernel's copyin/copyout, that is from syscalls. A userland function such as most pthread_*/scePthreadAttr* ones probably faults there too, and several merged fixes describe EFAULT as a host-safety fallback with the console behaviour unmeasured. So the audit only lists candidates, and the error to return stays a per-function decision.

Questions:

  1. Would you take the tool? I'd open it with a test over synthetic sources: each access kind is flagged, uses through each safe helper and pointer-to-function parameters are not.
  2. Should EFAULT fixes be grouped per file or per library, using this list, instead of one per function?
  3. Is a line in AGENTS.md wanted, e.g. "access guest pointer parameters through GuestCopyIn/GuestCopyOut or the CopyGuest* helpers"? Or only for syscall-backed exports?

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6147676627 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/14445). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-01T13:52:54Z. --- **One `EFAULT` fix per function keeps coming.** Of the 268 `fix` pull requests opened on Oct 29–30, 28 add `EFAULT` (or an unwritable/unreadable-pointer check) to one export each: 17 merged, 8 still open. Examples: #13443, #13537, #13552, #13576, #13577, #13587 and #13582. More single-function issues are open too: #13951, #13955, #13959. The cause is the same each time. An export reads or writes a guest pointer parameter directly (`*out = …`, `out->field`, `std::memcpy(out, …)`, `std::strlen(path)`), and the fix routes it through `GuestCopyOut_nid_no_patch` / `GuestCopyIn_nid_no_patch` or the `CopyGuest*` helpers in `libc/include/General.hpp`. The helpers exist, but no rule or tool points at the exports that bypass them, so they are found one per pull request. **Proposal: `tools/guest_pointer_audit.py`**, an audit in the style of `import_audit.py`, not a CI gate. It reuses `progress.py`'s parsing (`APS5_VABI` definitions, comment and literal stripping) and, for each exported function, reports the pointer parameters the body uses through `->`, `[]`, `*` or a raw `mem*`/`str*`/`std::copy` call without passing them to one of the safe helpers. Output is `file:line: function: parameter (kind)` plus a per-library count, or JSON. A prototype over `main` `e53aff3f56` finds 2,739 such parameter uses in 2,210 exports. The largest groups are libc (345), libkernel (252), libSceNpCppWebApi (232), libSceJson2 (185) and libSceNpCommon (171); libkernel_sys has 23. A random sample of 10 libkernel/libkernel_sys findings were all real direct accesses, for example `uuidgen`'s `store[index]`, which #13187 fixes. **What it doesn't decide.** On the console, `EFAULT` comes from the kernel's copyin/copyout, that is from syscalls. A userland function such as most `pthread_*`/`scePthreadAttr*` ones probably faults there too, and several merged fixes describe `EFAULT` as a host-safety fallback with the console behaviour unmeasured. So the audit only lists candidates, and the error to return stays a per-function decision. Questions: 1. Would you take the tool? I'd open it with a test over synthetic sources: each access kind is flagged, uses through each safe helper and pointer-to-function parameters are not. 2. Should `EFAULT` fixes be grouped per file or per library, using this list, instead of one per function? 3. Is a line in AGENTS.md wanted, e.g. "access guest pointer parameters through `GuestCopyIn`/`GuestCopyOut` or the `CopyGuest*` helpers"? Or only for syscall-backed exports? AI-assisted: yes (Claude Code)
Sign in to join this conversation.
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#14445
No description provided.