feat(tools): list exports that access guest pointer parameters directly #14446

Merged
LeandroLP23 merged 6 commits from upstream-pr/14446 into main 2026-11-06 23:16:44 +00:00
LeandroLP23 commented 2026-11-01 13:57:43 +00:00 (Migrated from github.com)

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


What

tools/guest_pointer_audit.py lists exported functions that read or write a guest pointer parameter directly instead of through GuestCopyIn_nid_no_patch, GuestCopyOut_nid_no_patch or the CopyGuest* helpers in libc/include/General.hpp. The background is #14445: in two days, 28 fix pull requests each added EFAULT to one export, because nothing points at the exports that bypass the helpers.

  • It reuses progress.py's parsing: APS5_VABI definitions, body_end and code(), which blanks comments and literals with the repository tokenizer. Test sources under a library's tests/ are skipped, as progress.py does.
  • For each pointer parameter (multi-level and const-qualified included), it reports a direct use through ->, [], unary *, or as a pointer operand of a raw mem*/str*/std::copy/copy_n/fill/fill_n call. Every pointer operand position of these calls is checked, including the destination of copy, and casts are seen through. The address arguments of the safe helpers and every operand of sizeof, alignof, decltype and noexcept are blanked before matching, with line positions kept, so &out->size or out->name passed to GuestCopyOut as an address is not an access, while a size argument such as p->size and a separate direct access to the same parameter are still reported. The reported line is the earliest access of any kind. References and pointer-to-function parameters are skipped.
  • Output is file:line: function: parameter (kinds) with a per-library count, or --json. Libraries can be named; the default is every directory under core/libs/prx. It is an audit, not a CI gate: it always exits 0. It reads one function body at a time, so it doesn't follow a pointer passed to another function or copied to a local first, and a clean report doesn't mean a library has no direct guest access. It also doesn't decide which error an export returns, since that depends on whether the console function is syscall-backed (see #14445).
  • docs/dev/CONVENTIONS.md mentions it at the end of "Host writes into guest memory".

On main it reports 2,797 uses in 2,239 exports. libkernel and libkernel_sys account for 281 of them. A random sample of 10 of those were all real direct accesses, e.g. uuidgen's store[index] (#13187).

Tested

  • Windows 11, Python 3.13: tools/tests/test_guest_pointer_audit.py (14 tests, registered as guest_pointer_audit). The 4 added in 76f5b80618 fail on bc6c4d4b4c, and the 2 added in 4b0cfd5b37 fail on c70ebe89d0. It checks that each access kind is reported, that the safe helpers, references, pointer-to-function parameters, null comparisons, comments and string literals are not, that the reported line is the first access, the JSON shape, the skipping of tests/, the per-library summary, and the usage error for an unknown library.
  • test_progress_wrappers.py, test_progress_read_encoding.py and test_test_registration.py pass; check_conventions.py --base origin/main passes.
  • Run on the whole tree, from the repository root and from tools/. Against c70ebe89d0, 4b0cfd5b37 adds 12 findings and removes none; all 12 are raw strncpy/memcpy/strcmp operands that a -> in an earlier argument had hidden, such as sceUltMutexCreate's name.

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 (implements the tool proposed in #14445; its policy questions stay open there)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5108016533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14446). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-01T13:57:43Z. --- ### What `tools/guest_pointer_audit.py` lists exported functions that read or write a guest pointer parameter directly instead of through `GuestCopyIn_nid_no_patch`, `GuestCopyOut_nid_no_patch` or the `CopyGuest*` helpers in `libc/include/General.hpp`. The background is #14445: in two days, 28 `fix` pull requests each added `EFAULT` to one export, because nothing points at the exports that bypass the helpers. - It reuses `progress.py`'s parsing: `APS5_VABI` definitions, `body_end` and `code()`, which blanks comments and literals with the repository tokenizer. Test sources under a library's `tests/` are skipped, as `progress.py` does. - For each pointer parameter (multi-level and `const`-qualified included), it reports a direct use through `->`, `[]`, unary `*`, or as a pointer operand of a raw `mem*`/`str*`/`std::copy`/`copy_n`/`fill`/`fill_n` call. Every pointer operand position of these calls is checked, including the destination of `copy`, and casts are seen through. The address arguments of the safe helpers and every operand of `sizeof`, `alignof`, `decltype` and `noexcept` are blanked before matching, with line positions kept, so `&out->size` or `out->name` passed to `GuestCopyOut` as an address is not an access, while a size argument such as `p->size` and a separate direct access to the same parameter are still reported. The reported line is the earliest access of any kind. References and pointer-to-function parameters are skipped. - Output is `file:line: function: parameter (kinds)` with a per-library count, or `--json`. Libraries can be named; the default is every directory under `core/libs/prx`. It is an audit, not a CI gate: it always exits 0. It reads one function body at a time, so it doesn't follow a pointer passed to another function or copied to a local first, and a clean report doesn't mean a library has no direct guest access. It also doesn't decide which error an export returns, since that depends on whether the console function is syscall-backed (see #14445). - `docs/dev/CONVENTIONS.md` mentions it at the end of "Host writes into guest memory". On `main` it reports 2,797 uses in 2,239 exports. libkernel and libkernel_sys account for 281 of them. A random sample of 10 of those were all real direct accesses, e.g. `uuidgen`'s `store[index]` (#13187). ### Tested - Windows 11, Python 3.13: `tools/tests/test_guest_pointer_audit.py` (14 tests, registered as `guest_pointer_audit`). The 4 added in 76f5b80618 fail on `bc6c4d4b4c`, and the 2 added in 4b0cfd5b37 fail on `c70ebe89d0`. It checks that each access kind is reported, that the safe helpers, references, pointer-to-function parameters, null comparisons, comments and string literals are not, that the reported line is the first access, the JSON shape, the skipping of `tests/`, the per-library summary, and the usage error for an unknown library. - `test_progress_wrappers.py`, `test_progress_read_encoding.py` and `test_test_registration.py` pass; `check_conventions.py --base origin/main` passes. - Run on the whole tree, from the repository root and from `tools/`. Against `c70ebe89d0`, 4b0cfd5b37 adds 12 findings and removes none; all 12 are raw `strncpy`/`memcpy`/`strcmp` operands that a `->` in an earlier argument had hidden, such as `sceUltMutexCreate`'s `name`. ### 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 (implements the tool proposed in #14445; its policy questions stay open there) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-01 14:14:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T14:14:38Z.

Review: COMMENTED


Reviewed — no blocking findings

I read the new audit tool, its unit tests and its CONVENTIONS entry at head bc6c4d4b4c and found no blocking defect; the Python unit tests were not run here, so the tool's behaviour is checked from source only.

What I ran

  • Exact head: bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb. PR base: f1a7b02028ae50adaf6c5aaaef892a51841b25bf. No merged preview was run.
  • Environment: Linux 6.1 host, Python 3.11.2, git 2.39.5. No build, no compile.
  • Commands:
git diff --check f1a7b02028ae50adaf6c5aaaef892a51841b25bf...bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb
python3 -I tools/check_conventions.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb --title "feat(tools): list exports that access guest pointer parameters directly" --body <PR body file>
  • Not run: tools/tests/test_guest_pointer_audit.py (7 tests) and the new tool itself. Running code from this PR was not permitted in this review session, so I read the diff only.

Results

Check Result
git diff --check (base...head) passed
Conventions and PR template (tools/check_conventions.py) passed
test_guest_pointer_audit.py (7 tests) not run
Run of tools/guest_pointer_audit.py on the tree not run
Hosted CI for bc6c4d4b4c queued when I checked; not complete
Conventions, unedited output
All conventions checks passed.

Negative control

Not run. I did not change the code under test, and I did not run the new assertions against base.

Findings

Blocking: none.

Non-blocking:

  • The reported line is not always the first access. accesses() appends hits grouped by pattern kind, in the order member, index, dereference, library call (tools/guest_pointer_audit.py#L41-L53), and audit_text() takes hits[0] for line (#L69). For void APS5_VABI sceExampleMix(Info* info) { followed by info[0].size = 1; on line 2 and info->size = 2; on line 3, the tool reports line 3. The test test_line_points_at_the_first_access (#L55-L59) uses one access kind, so it does not catch this, although the PR body says it checks that the line is the first access. Smallest fix: return sorted(found, key=lambda hit: hit[1]) in accesses(), plus a two-kind case in that test.
  • The CONVENTIONS paragraph says mem*, str* or std::copy. RAW_CALLS also matches snprintf, sprintf, copy_n, fill and fill_n, which the paragraph does not name. Minor wording gap.

Sources

Not verified

  • The 7 unit tests and the tool's output on the tree were not run here. The PR body's Windows 11 / Python 3.13 test run and its count of 2,753 uses in 2,210 exports on main e53aff3f56 are author-reported and were not reproduced.
  • Hosted CI for this head was not complete when I checked.

To get this to a good state

Fix the line selection (sort the hits by position) and add a two-kind case to the line test. Optionally align the CONVENTIONS list with RAW_CALLS. The next pass re-checks the new head once hosted CI finishes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728511574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14446#pullrequestreview-5728511574). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T14:14:38Z. **Review:** COMMENTED --- # Reviewed — no blocking findings I read the new audit tool, its unit tests and its CONVENTIONS entry at head `bc6c4d4b4c` and found no blocking defect; the Python unit tests were not run here, so the tool's behaviour is checked from source only. ## What I ran - Exact head: `bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb`. PR base: `f1a7b02028ae50adaf6c5aaaef892a51841b25bf`. No merged preview was run. - Environment: Linux 6.1 host, Python 3.11.2, git 2.39.5. No build, no compile. - Commands: ```sh git diff --check f1a7b02028ae50adaf6c5aaaef892a51841b25bf...bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb python3 -I tools/check_conventions.py --base f1a7b02028ae50adaf6c5aaaef892a51841b25bf --head bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb --title "feat(tools): list exports that access guest pointer parameters directly" --body <PR body file> ``` - Not run: `tools/tests/test_guest_pointer_audit.py` (7 tests) and the new tool itself. Running code from this PR was not permitted in this review session, so I read the diff only. ## Results | Check | Result | |---|---| | `git diff --check` (base...head) | passed | | Conventions and PR template (`tools/check_conventions.py`) | passed | | `test_guest_pointer_audit.py` (7 tests) | not run | | Run of `tools/guest_pointer_audit.py` on the tree | not run | | Hosted CI for `bc6c4d4b4c` | queued when I checked; not complete | <details><summary>Conventions, unedited output</summary> ```text All conventions checks passed. ``` </details> ## Negative control Not run. I did not change the code under test, and I did not run the new assertions against base. ## Findings **Blocking:** none. **Non-blocking:** - The reported line is not always the first access. `accesses()` appends hits grouped by pattern kind, in the order member, index, dereference, library call ([tools/guest_pointer_audit.py#L41-L53](https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/tools/guest_pointer_audit.py#L41-L53)), and `audit_text()` takes `hits[0]` for `line` ([#L69](https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/tools/guest_pointer_audit.py#L69)). For `void APS5_VABI sceExampleMix(Info* info) {` followed by `info[0].size = 1;` on line 2 and `info->size = 2;` on line 3, the tool reports line 3. The test `test_line_points_at_the_first_access` ([#L55-L59](https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/tools/tests/test_guest_pointer_audit.py#L55-L59)) uses one access kind, so it does not catch this, although the PR body says it checks that the line is the first access. Smallest fix: `return sorted(found, key=lambda hit: hit[1])` in `accesses()`, plus a two-kind case in that test. - The CONVENTIONS paragraph says `mem*`, `str*` or `std::copy`. `RAW_CALLS` also matches `snprintf`, `sprintf`, `copy_n`, `fill` and `fill_n`, which the paragraph does not name. Minor wording gap. ## Sources - Tool at head: https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/tools/guest_pointer_audit.py - Test at head: https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/tools/tests/test_guest_pointer_audit.py - CONVENTIONS entry at head: https://github.com/boykopovar/AnyPS5/blob/bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb/docs/dev/CONVENTIONS.md ## Not verified - The 7 unit tests and the tool's output on the tree were not run here. The PR body's Windows 11 / Python 3.13 test run and its count of 2,753 uses in 2,210 exports on `main` `e53aff3f56` are author-reported and were not reproduced. - Hosted CI for this head was not complete when I checked. ## To get this to a good state Fix the line selection (sort the hits by position) and add a two-kind case to the line test. Optionally align the CONVENTIONS list with `RAW_CALLS`. The next pass re-checks the new head once hosted CI finishes.
MarcZX10 commented 2026-11-02 07:42:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:42:51Z.

Review: COMMENTED


Reviewed — no blocking findings; the guest-pointer audit runs in CTest, but it always exits 0

This PR adds tools/guest_pointer_audit.py, a report-only script that lists exported functions which read or write a guest pointer parameter directly instead of through GuestCopyIn, GuestCopyOut or the string helpers. The Ubuntu relinker job ran its test file as CTest guest_pointer_audit, and it passed. I read the tool in full. The 140-line test file is listed by name only.

What I ran

  • Head be1b2c59b1491d4c40713732de2ecf2fde587a46; base f1a7b02028ae50adaf6c5aaaef892a51841b25bf. 4 files, +292: tools/guest_pointer_audit.py (+148, new), tools/tests/test_guest_pointer_audit.py (+140, new), CMakeLists.txt (+2, the CTest case), and docs/dev/CONVENTIONS.md (+2).
  • Read tools/guest_pointer_audit.py in full. It finds pointer parameters from each definition, blanks the arguments of the safe guest-copy calls and of sizeof-style operators, and then looks for member access, indexing, dereference, and the raw library calls in RAW_CALLS that receive the parameter. The main function prints the findings and returns 0 in both the text and the JSON paths.
  • Test file: read the method names only.
  • Hosted: the Ubuntu relinker job's CTest guest_pointer_audit (Test #34) passed in a run of 558 of 558 (job 125148479225). Relinkers (macOS, Ubuntu, Windows) and relinker-asan succeeded. Windows succeeded.
  • Read-only checks from the trusted main checkout: diff check and conventions passed. ABI audit not applicable. Stack check: clean, no declared dependencies, no errors.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check: clean; no declared dependencies
ABI audit not applicable no export changed
guest_pointer_audit (hosted, Ubuntu relinker job) passed Test #34
Relinkers, relinker-asan and Windows (hosted) passed all succeeded
guest_pointer_audit.py (read in full) passed by reading no blocking defect found in the read
Coverage against real libraries not verified the tool was not run here
Test bodies in test_guest_pointer_audit.py not verified names only
Negative controls not run no local build; no PR-head Python runs here
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: clean, no declared dependencies, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/be1b2c59b1491d4c40713732de2ecf2fde587a46/check-runs, and the Ubuntu relinker job log (job 125148479225).

Negative control

Not run here. A negative control needs a local run of the audit on a known-bad function, and no PR-head Python runs on this machine.

Findings

Blocking

None from the code read.

Non-blocking

  • The tool returns 0 whether or not it finds accesses, so it cannot act as a gate yet. That fits a report, and the PR says so only if its body does.
  • The audit is regex-based. It sees direct accesses in one function body. It does not follow a pointer that is passed to another function or copied to a local first. A clean report therefore does not show that a library is free of direct guest access.

Sources

Not verified

  • How many direct guest accesses the tool finds across the libraries, and whether they are all real.
  • The test bodies in test_guest_pointer_audit.py.

To get this to a good state

  • Nothing blocking. Say in the tool's help or the conventions text that the audit is a report and not a gate, or add an exit code for a gate.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5733354355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14446#pullrequestreview-5733354355). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T07:42:51Z. **Review:** COMMENTED --- # Reviewed — no blocking findings; the guest-pointer audit runs in CTest, but it always exits 0 This PR adds `tools/guest_pointer_audit.py`, a report-only script that lists exported functions which read or write a guest pointer parameter directly instead of through `GuestCopyIn`, `GuestCopyOut` or the string helpers. The Ubuntu relinker job ran its test file as CTest `guest_pointer_audit`, and it passed. I read the tool in full. The 140-line test file is listed by name only. ## What I ran - Head `be1b2c59b1491d4c40713732de2ecf2fde587a46`; base `f1a7b02028ae50adaf6c5aaaef892a51841b25bf`. 4 files, +292: `tools/guest_pointer_audit.py` (+148, new), `tools/tests/test_guest_pointer_audit.py` (+140, new), `CMakeLists.txt` (+2, the CTest case), and `docs/dev/CONVENTIONS.md` (+2). - Read `tools/guest_pointer_audit.py` in full. It finds pointer parameters from each definition, blanks the arguments of the safe guest-copy calls and of `sizeof`-style operators, and then looks for member access, indexing, dereference, and the raw library calls in `RAW_CALLS` that receive the parameter. The `main` function prints the findings and returns 0 in both the text and the JSON paths. - Test file: read the method names only. - Hosted: the Ubuntu relinker job's CTest `guest_pointer_audit` (Test #34) passed in a run of 558 of 558 (job 125148479225). Relinkers (macOS, Ubuntu, Windows) and relinker-asan succeeded. Windows succeeded. - Read-only checks from the trusted main checkout: diff check and conventions passed. ABI audit not applicable. Stack check: clean, no declared dependencies, no errors. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check: clean; no declared dependencies | | ABI audit | not applicable | no export changed | | `guest_pointer_audit` (hosted, Ubuntu relinker job) | passed | Test #34 | | Relinkers, relinker-asan and Windows (hosted) | passed | all succeeded | | `guest_pointer_audit.py` (read in full) | passed by reading | no blocking defect found in the read | | Coverage against real libraries | not verified | the tool was not run here | | Test bodies in `test_guest_pointer_audit.py` | not verified | names only | | Negative controls | not run | no local build; no PR-head Python runs here | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: clean, no declared dependencies, no errors. Hosted: `gh api repos/boykopovar/AnyPS5/commits/be1b2c59b1491d4c40713732de2ecf2fde587a46/check-runs`, and the Ubuntu relinker job log (job 125148479225). </details> ## Negative control Not run here. A negative control needs a local run of the audit on a known-bad function, and no PR-head Python runs on this machine. ## Findings **Blocking** None from the code read. **Non-blocking** - The tool returns 0 whether or not it finds accesses, so it cannot act as a gate yet. That fits a report, and the PR says so only if its body does. - The audit is regex-based. It sees direct accesses in one function body. It does not follow a pointer that is passed to another function or copied to a local first. A clean report therefore does not show that a library is free of direct guest access. ## Sources - Tool: https://github.com/boykopovar/AnyPS5/blob/be1b2c59b1491d4c40713732de2ecf2fde587a46/tools/guest_pointer_audit.py - Tests: https://github.com/boykopovar/AnyPS5/blob/be1b2c59b1491d4c40713732de2ecf2fde587a46/tools/tests/test_guest_pointer_audit.py - CTest registration: https://github.com/boykopovar/AnyPS5/blob/be1b2c59b1491d4c40713732de2ecf2fde587a46/CMakeLists.txt - Ubuntu relinker job log: job 125148479225 on be1b2c59b1491d4c40713732de2ecf2fde587a46 ## Not verified - How many direct guest accesses the tool finds across the libraries, and whether they are all real. - The test bodies in `test_guest_pointer_audit.py`. ## To get this to a good state - Nothing blocking. Say in the tool's help or the conventions text that the audit is a report and not a gate, or add an exit code for a gate.
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!14446
No description provided.