tools: import_audit.py --modules never checks a guest module's own imports, only whether it's used as a dependency #4202

Closed
opened 2026-10-12 01:13:17 +00:00 by Dextroid17 · 4 comments
Dextroid17 commented 2026-10-12 01:13:17 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T01:13:17Z.


tools/import_audit.py --modules marks a title's shipped guest module as fully resolved without auditing what the module itself still imports

Found while climbing a different title (Trails in the Sky 2nd Chapter, PPSA35169) on a local branch that
turned out to be well behind upstream/main. The specific symbol that first surfaced this (a title's
shipped libc.prx importing _umtx_op) is a poor example on its own — _umtx_op is already implemented
on upstream/main (PRs #1482, #2051, #3845) and the branch used for this exploration was simply stale —
but the audit-tooling gap it exposed is independent of that and still real on upstream/main today.

The gap. --modules's own help text says, verbatim: "directory of the title's own modules; libraries named there are not checked" (tools/import_audit.py:295). In audit() (:193), an import whose library name is in modules is classified into its own, separate "module" class rather than "implemented" or "absent" (:201-202), and that library name is excluded from the "missing libraries" report (:218) — but the module's own file is never opened or parsed. module_files() (:142-143) only reads the directory's file names; the file's only content-reading functions are the ones that extract exports from --libs entries and the ones that parse a registry JSON passed as a positional argument. There is no code path that opens a --modules file and traces its own dynamic imports against the system library set.

Measured effect: the Oct 9 audit of this title's main executable (via sweep_titles.py, which passes --modules pointed at the title's sce_module directory) reported only 4 "absent" imports — all against the main executable's own import table. It missed entirely that the shipped sce_module/libc.prx has its own import (_umtx_op, NID 04AjkP0jO9U) that the audit never checked, because that import is module-internal and never appears in the main executable's registry at all. This particular symbol turned out to be implemented on upstream/main (so no action is needed on it specifically) — but the audit would have reported the same "clean, 4 absent imports" result whether _umtx_op were implemented or not, because it never looks at the module's own imports either way. The only way the gap surfaced here was an actual runtime symbol-lookup failure at process start, on a stale branch where the symbol genuinely was missing.

Why this matters: a title that ships its own guest module (common — PS4/PS5 titles frequently bundle a patched libc.prx or similar) can pass the existing audit cleanly while still being unbootable, because the audit's blind trust in --modules hides exactly the imports that would catch it. The audit is meant to answer "will this title run," and right now it can answer yes when the real answer is no. (Note: if a module's own registry is generated separately and passed as a positional argument, import_audit.py would audit it the normal way — the gap is specific to the --modules convenience path, not to the tool as a whole.)

Possible direction (not proposing a specific implementation): when --modules is given, also read each module's own dynamic imports (the same way the main executable's are read) and classify them against --libs plus the other modules in --modules — a module should only be exempt from being checked as a dependency of other things, not exempt from having its own imports checked.

Edit — re-verified directly against upstream/main, not just the local branch this was found on: this report was originally drafted from a branch that turned out to be ~1,500 commits behind upstream/main, so before relying on it I pulled tools/import_audit.py straight from upstream/main and re-checked every claim above against it line by line (the file has changed since — elf_exports/pe_exports gained real validation hardening — but none of that touches this path). On upstream/main today: module_files() still only collects file.name from each --modules directory ({file.name for directory in directories for file in directory_files(directory, "*")}), audit() still only uses that set to classify a matching import as "module" and exclude its library from the missing-libraries report, and main()'s only other use of the module files is folding them into the --json output's overwrite-safety check — their contents are never opened. So the gap described above is current, not a stale-branch artifact.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5806955425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4202). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T01:13:17Z. --- **`tools/import_audit.py --modules` marks a title's shipped guest module as fully resolved without auditing what the module itself still imports** Found while climbing a different title (Trails in the Sky 2nd Chapter, PPSA35169) on a local branch that turned out to be well behind `upstream/main`. The specific symbol that first surfaced this (a title's shipped `libc.prx` importing `_umtx_op`) is a poor example on its own — `_umtx_op` is already implemented on `upstream/main` (PRs #1482, #2051, #3845) and the branch used for this exploration was simply stale — but the audit-tooling gap it exposed is independent of that and still real on `upstream/main` today. **The gap.** `--modules`'s own help text says, verbatim: *"directory of the title's own modules; libraries named there are not checked"* (`tools/import_audit.py:295`). In `audit()` (`:193`), an import whose library name is in `modules` is classified into its own, separate `"module"` class rather than `"implemented"` or `"absent"` (`:201-202`), and that library name is excluded from the "missing libraries" report (`:218`) — but the module's *own* file is never opened or parsed. `module_files()` (`:142-143`) only reads the directory's file **names**; the file's only content-reading functions are the ones that extract exports from `--libs` entries and the ones that parse a registry JSON passed as a positional argument. There is no code path that opens a `--modules` file and traces its own dynamic imports against the system library set. **Measured effect:** the Oct 9 audit of this title's main executable (via `sweep_titles.py`, which passes `--modules` pointed at the title's `sce_module` directory) reported only 4 "absent" imports — all against the main executable's own import table. It missed entirely that the shipped `sce_module/libc.prx` has its own import (`_umtx_op`, NID `04AjkP0jO9U`) that the audit never checked, because that import is module-internal and never appears in the main executable's registry at all. **This particular symbol turned out to be implemented on `upstream/main`** (so no action is needed on it specifically) — but the audit would have reported the same "clean, 4 absent imports" result whether `_umtx_op` were implemented or not, because it never looks at the module's own imports either way. The only way the gap surfaced here was an actual runtime symbol-lookup failure at process start, on a stale branch where the symbol genuinely was missing. **Why this matters:** a title that ships its own guest module (common — PS4/PS5 titles frequently bundle a patched `libc.prx` or similar) can pass the existing audit cleanly while still being unbootable, because the audit's blind trust in `--modules` hides exactly the imports that would catch it. The audit is meant to answer "will this title run," and right now it can answer yes when the real answer is no. (Note: if a module's own registry is generated separately and passed as a positional argument, `import_audit.py` *would* audit it the normal way — the gap is specific to the `--modules` convenience path, not to the tool as a whole.) **Possible direction (not proposing a specific implementation):** when `--modules` is given, also read each module's own dynamic imports (the same way the main executable's are read) and classify them against `--libs` plus the *other* modules in `--modules` — a module should only be exempt from *being checked as a dependency of other things*, not exempt from *having its own imports checked*. **Edit — re-verified directly against `upstream/main`, not just the local branch this was found on:** this report was originally drafted from a branch that turned out to be ~1,500 commits behind `upstream/main`, so before relying on it I pulled `tools/import_audit.py` straight from `upstream/main` and re-checked every claim above against it line by line (the file has changed since — `elf_exports`/`pe_exports` gained real validation hardening — but none of that touches this path). On `upstream/main` today: `module_files()` still only collects `file.name` from each `--modules` directory (`{file.name for directory in directories for file in directory_files(directory, "*")}`), `audit()` still only uses that set to classify a matching import as `"module"` and exclude its library from the missing-libraries report, and `main()`'s only other use of the module files is folding them into the `--json` output's overwrite-safety check — their contents are never opened. So the gap described above is current, not a stale-branch artifact. Written with AI assistance.
LeandroSSB commented 2026-10-12 01:38:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroSSB on 2026-10-12T01:38:50Z.


The direction you sketched is implemented on my fork: LeandroSSB/AnyPS5:fix/import-audit-module-imports (one commit, 7ddd00a57, on main 7a84b2226).

--modules files are now opened: a new elf_imports reader (beside elf_exports, same take/unpack/cstring idiom and the same ELF64 little-endian guard) reads each module's undefined dynamic symbols and DT_NEEDED names. Each module's own imports are classified exactly like registry imports — implemented / stub / absent — against the --libs exports plus the exports of the sibling modules in --modules, and every record is attributed to its module in the report (an (imported by <module>) label; the JSON record carries the module name). A DT_NEEDED library with no file in --libs or --modules joins the existing missing-libraries report. Modules keep their exemption as dependency targets — imports naming them still classify as module — and with no --modules the output is byte-identical.

So the #4202 shape is now caught: tools/tests/test_import_audit.py gains a module that imports a symbol nobody provides and asserts absent with exit 1 (plus lib-provided, stub, sibling-module-provided, DT_NEEDED-missing, and non-ELF-module error cases; 4 new tests, TDD red→green). Full suite: 178/178, tools/check_conventions.py --base origin/main passes. Two deliberate behavior notes: a non-ELF64 file in --modules now fails with a clear error naming the file instead of being silently trusted, and weak undefined symbols are audited like strong ones (conservative, matching the registry path's coarseness — a future refinement could split them).

Not opened as a PR because of the intake pause; a maintainer is welcome to carry the commit.

AI-assisted (Claude Code); I reviewed the change and ran everything above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116223984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4202#issuecomment-6116223984). Originally posted by [LeandroSSB](https://github.com/LeandroSSB) on 2026-10-12T01:38:50Z. --- The direction you sketched is implemented on my fork: [`LeandroSSB/AnyPS5:fix/import-audit-module-imports`](https://github.com/LeandroSSB/AnyPS5/tree/fix/import-audit-module-imports) (one commit, `7ddd00a57`, on `main` `7a84b2226`). `--modules` files are now opened: a new `elf_imports` reader (beside `elf_exports`, same `take`/`unpack`/`cstring` idiom and the same ELF64 little-endian guard) reads each module's undefined dynamic symbols and `DT_NEEDED` names. Each module's own imports are classified exactly like registry imports — implemented / stub / absent — against the `--libs` exports **plus the exports of the sibling modules in `--modules`**, and every record is attributed to its module in the report (an `(imported by <module>)` label; the JSON record carries the module name). A `DT_NEEDED` library with no file in `--libs` or `--modules` joins the existing missing-libraries report. Modules keep their exemption as dependency targets — imports naming them still classify as `module` — and with no `--modules` the output is byte-identical. So the \#4202 shape is now caught: `tools/tests/test_import_audit.py` gains a module that imports a symbol nobody provides and asserts `absent` with exit 1 (plus lib-provided, stub, sibling-module-provided, `DT_NEEDED`-missing, and non-ELF-module error cases; 4 new tests, TDD red→green). Full suite: 178/178, `tools/check_conventions.py --base origin/main` passes. Two deliberate behavior notes: a non-ELF64 file in `--modules` now fails with a clear error naming the file instead of being silently trusted, and weak undefined symbols are audited like strong ones (conservative, matching the registry path's coarseness — a future refinement could split them). Not opened as a PR because of the intake pause; a maintainer is welcome to carry the commit. AI-assisted (Claude Code); I reviewed the change and ran everything above on my machine.
LeandroSSB commented 2026-10-12 03:43:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroSSB on 2026-10-12T03:43:41Z.


Checking the resolution: this was closed as completed at 03:37Z, but I don't see the fix on main yet — the branch cited above isn't carried (no elf_imports in the tree as of d146ec1b6) and no import-audit PR has merged. If a carry is in flight, please ignore this note; if it was closed by mistake, reopening keeps the blind spot visible for whoever hits it next.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117347031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4202#issuecomment-6117347031). Originally posted by [LeandroSSB](https://github.com/LeandroSSB) on 2026-10-12T03:43:41Z. --- Checking the resolution: this was closed as completed at 03:37Z, but I don't see the fix on `main` yet — the branch cited above isn't carried (no `elf_imports` in the tree as of `d146ec1b6`) and no import-audit PR has merged. If a carry is in flight, please ignore this note; if it was closed by mistake, reopening keeps the blind spot visible for whoever hits it next.
Dextroid17 commented 2026-10-12 03:58:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T03:58:04Z.


Thanks for following up, and apologies — the close was accidental, not a decision about the fix. Reopened.

You're right that nothing of it is on main. What exists is a carry of your work: #4243 is open and CLEAN but unmerged, and it preserves your authorship on the patch — it cherry-picks your commit 7ddd00a57 as 82f9bf7f0, over tools/import_audit.py, tools/tests/test_import_audit.py and docs/user/USAGE.md. So the change is waiting on review rather than lost, but it genuinely is not in main yet, and your reading of the tree is correct.

Two things worth knowing, since this is the second attempt: the earlier carry of this fix (#4208) was closed unmerged and replaced by #4243, and #4243's own body notes that a rebase may still be needed depending on the order against open #4196. If #4243 is superseded as well, this issue should stay open rather than be closed again — the gap is real until the code is in main.

Thanks for the implementation, and for checking the resolution rather than assuming it.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117475703 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4202#issuecomment-6117475703). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T03:58:04Z. --- Thanks for following up, and apologies — the close was accidental, not a decision about the fix. Reopened. You're right that nothing of it is on `main`. What exists is a carry of your work: #4243 is open and `CLEAN` but unmerged, and it preserves your authorship on the patch — it cherry-picks your commit `7ddd00a57` as `82f9bf7f0`, over `tools/import_audit.py`, `tools/tests/test_import_audit.py` and `docs/user/USAGE.md`. So the change is waiting on review rather than lost, but it genuinely is not in `main` yet, and your reading of the tree is correct. Two things worth knowing, since this is the second attempt: the earlier carry of this fix (#4208) was closed unmerged and replaced by #4243, and #4243's own body notes that a rebase may still be needed depending on the order against open #4196. If #4243 is superseded as well, this issue should stay open rather than be closed again — the gap is real until the code is in `main`. Thanks for the implementation, and for checking the resolution rather than assuming it. Written with AI assistance.
LeandroSSB commented 2026-10-12 07:51:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by LeandroSSB on 2026-10-12T07:51:02Z.


Both findings from the #4243 close are fixed on the branch above (updated to 2d0d70780, still one commit on current main):

  • PRX without a section header table no longer aborts the run: elf_imports returns None for such a file, so its own-imports audit is skipped (its exports still register as a sibling provider via elf_exports, which now returns an empty set instead of raising). The registry-JSON path Dextroid17 mentioned keeps full coverage where it exists; the --modules path no longer crashes where it doesn't.
  • The #lib#mod suffix is stripped from dynamic symbol names before classification (symbol.split("#", 1)[0]).

Two new tests pin both behaviors (test_module_without_section_headers_is_skipped, test_module_symbol_suffix_is_stripped); the suite is 180/180 and conventions pass. If a stripped PRX has imports worth auditing, that would need a program-header/dynamic-segment reader — the current fix at minimum makes the documented --modules source/sce_module run complete instead of exiting 2.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120045977 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4202#issuecomment-6120045977). Originally posted by [LeandroSSB](https://github.com/LeandroSSB) on 2026-10-12T07:51:02Z. --- Both findings from the #4243 close are fixed on the branch above (updated to `2d0d70780`, still one commit on current `main`): - **PRX without a section header table** no longer aborts the run: `elf_imports` returns `None` for such a file, so its own-imports audit is skipped (its exports still register as a sibling provider via `elf_exports`, which now returns an empty set instead of raising). The registry-JSON path Dextroid17 mentioned keeps full coverage where it exists; the `--modules` path no longer crashes where it doesn't. - **The `#lib#mod` suffix** is stripped from dynamic symbol names before classification (`symbol.split("#", 1)[0]`). Two new tests pin both behaviors (`test_module_without_section_headers_is_skipped`, `test_module_symbol_suffix_is_stripped`); the suite is 180/180 and conventions pass. If a stripped PRX has imports worth auditing, that would need a program-header/dynamic-segment reader — the current fix at minimum makes the documented `--modules source/sce_module` run complete instead of exiting 2.
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#4202
No description provided.