feat(tools): list exports that access guest pointer parameters directly #14446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14446"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-01T13:57:43Z.
What
tools/guest_pointer_audit.pylists exported functions that read or write a guest pointer parameter directly instead of throughGuestCopyIn_nid_no_patch,GuestCopyOut_nid_no_patchor theCopyGuest*helpers inlibc/include/General.hpp. The background is #14445: in two days, 28fixpull requests each addedEFAULTto one export, because nothing points at the exports that bypass the helpers.progress.py's parsing:APS5_VABIdefinitions,body_endandcode(), which blanks comments and literals with the repository tokenizer. Test sources under a library'stests/are skipped, asprogress.pydoes.const-qualified included), it reports a direct use through->,[], unary*, or as a pointer operand of a rawmem*/str*/std::copy/copy_n/fill/fill_ncall. Every pointer operand position of these calls is checked, including the destination ofcopy, and casts are seen through. The address arguments of the safe helpers and every operand ofsizeof,alignof,decltypeandnoexceptare blanked before matching, with line positions kept, so&out->sizeorout->namepassed toGuestCopyOutas an address is not an access, while a size argument such asp->sizeand 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.file:line: function: parameter (kinds)with a per-library count, or--json. Libraries can be named; the default is every directory undercore/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.mdmentions it at the end of "Host writes into guest memory".On
mainit 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'sstore[index](#13187).Tested
tools/tests/test_guest_pointer_audit.py(14 tests, registered asguest_pointer_audit). The 4 added in 76f5b80618 fail onbc6c4d4b4c, and the 2 added in 4b0cfd5b37 fail onc70ebe89d0. 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 oftests/, the per-library summary, and the usage error for an unknown library.test_progress_wrappers.py,test_progress_read_encoding.pyandtest_test_registration.pypass;check_conventions.py --base origin/mainpasses.tools/. Againstc70ebe89d0, 4b0cfd5b37 adds 12 findings and removes none; all 12 are rawstrncpy/memcpy/strcmpoperands that a->in an earlier argument had hidden, such assceUltMutexCreate'sname.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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
bc6c4d4b4cand 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
bc6c4d4b4c4127c1ebf6f59cbf362e4fc75252bb. PR base:f1a7b02028ae50adaf6c5aaaef892a51841b25bf. No merged preview was 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
git diff --check(base...head)tools/check_conventions.py)test_guest_pointer_audit.py(7 tests)tools/guest_pointer_audit.pyon the treebc6c4d4b4cConventions, unedited output
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:
accesses()appends hits grouped by pattern kind, in the order member, index, dereference, library call (tools/guest_pointer_audit.py#L41-L53), andaudit_text()takeshits[0]forline(#L69). Forvoid APS5_VABI sceExampleMix(Info* info) {followed byinfo[0].size = 1;on line 2 andinfo->size = 2;on line 3, the tool reports line 3. The testtest_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])inaccesses(), plus a two-kind case in that test.mem*,str*orstd::copy.RAW_CALLSalso matchessnprintf,sprintf,copy_n,fillandfill_n, which the paragraph does not name. Minor wording gap.Sources
github.com/boykopovar/AnyPS5@bc6c4d4b4c/tools/guest_pointer_audit.pygithub.com/boykopovar/AnyPS5@bc6c4d4b4c/tools/tests/test_guest_pointer_audit.pygithub.com/boykopovar/AnyPS5@bc6c4d4b4c/docs/dev/CONVENTIONS.mdNot verified
maine53aff3f56are author-reported and were not reproduced.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.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 throughGuestCopyIn,GuestCopyOutor the string helpers. The Ubuntu relinker job ran its test file as CTestguest_pointer_audit, and it passed. I read the tool in full. The 140-line test file is listed by name only.What I ran
be1b2c59b1491d4c40713732de2ecf2fde587a46; basef1a7b02028ae50adaf6c5aaaef892a51841b25bf. 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), anddocs/dev/CONVENTIONS.md(+2).tools/guest_pointer_audit.pyin full. It finds pointer parameters from each definition, blanks the arguments of the safe guest-copy calls and ofsizeof-style operators, and then looks for member access, indexing, dereference, and the raw library calls inRAW_CALLSthat receive the parameter. Themainfunction prints the findings and returns 0 in both the text and the JSON paths.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.Results
guest_pointer_audit(hosted, Ubuntu relinker job)guest_pointer_audit.py(read in full)test_guest_pointer_audit.pyRead-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
Sources
github.com/boykopovar/AnyPS5@be1b2c59b1/tools/guest_pointer_audit.pygithub.com/boykopovar/AnyPS5@be1b2c59b1/tools/tests/test_guest_pointer_audit.pygithub.com/boykopovar/AnyPS5@be1b2c59b1/CMakeLists.txtNot verified
test_guest_pointer_audit.py.To get this to a good state