tools: import_audit.py --modules never checks a guest module's own imports, only whether it's used as a dependency #4202
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Dextroid17 on 2026-10-12T01:13:17Z.
tools/import_audit.py --modulesmarks a title's shipped guest module as fully resolved without auditing what the module itself still importsFound 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'sshipped
libc.prximporting_umtx_op) is a poor example on its own —_umtx_opis already implementedon
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/maintoday.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). Inaudit()(:193), an import whose library name is inmodulesis 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--libsentries and the ones that parse a registry JSON passed as a positional argument. There is no code path that opens a--modulesfile 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--modulespointed at the title'ssce_moduledirectory) reported only 4 "absent" imports — all against the main executable's own import table. It missed entirely that the shippedsce_module/libc.prxhas its own import (_umtx_op, NID04AjkP0jO9U) 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 onupstream/main(so no action is needed on it specifically) — but the audit would have reported the same "clean, 4 absent imports" result whether_umtx_opwere 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.prxor similar) can pass the existing audit cleanly while still being unbootable, because the audit's blind trust in--moduleshides 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.pywould audit it the normal way — the gap is specific to the--modulesconvenience path, not to the tool as a whole.)Possible direction (not proposing a specific implementation): when
--modulesis given, also read each module's own dynamic imports (the same way the main executable's are read) and classify them against--libsplus 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 behindupstream/main, so before relying on it I pulledtools/import_audit.pystraight fromupstream/mainand re-checked every claim above against it line by line (the file has changed since —elf_exports/pe_exportsgained real validation hardening — but none of that touches this path). Onupstream/maintoday:module_files()still only collectsfile.namefrom each--modulesdirectory ({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, andmain()'s only other use of the module files is folding them into the--jsonoutput'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.
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, onmain7a84b2226).--modulesfiles are now opened: a newelf_importsreader (besideelf_exports, sametake/unpack/cstringidiom and the same ELF64 little-endian guard) reads each module's undefined dynamic symbols andDT_NEEDEDnames. Each module's own imports are classified exactly like registry imports — implemented / stub / absent — against the--libsexports 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). ADT_NEEDEDlibrary with no file in--libsor--modulesjoins the existing missing-libraries report. Modules keep their exemption as dependency targets — imports naming them still classify asmodule— and with no--modulesthe output is byte-identical.So the #4202 shape is now caught:
tools/tests/test_import_audit.pygains a module that imports a symbol nobody provides and assertsabsentwith 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/mainpasses. Two deliberate behavior notes: a non-ELF64 file in--modulesnow 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.
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
mainyet — the branch cited above isn't carried (noelf_importsin the tree as ofd146ec1b6) 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.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 andCLEANbut unmerged, and it preserves your authorship on the patch — it cherry-picks your commit7ddd00a57as82f9bf7f0, overtools/import_audit.py,tools/tests/test_import_audit.pyanddocs/user/USAGE.md. So the change is waiting on review rather than lost, but it genuinely is not inmainyet, 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.
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 currentmain):elf_importsreturnsNonefor such a file, so its own-imports audit is skipped (its exports still register as a sibling provider viaelf_exports, which now returns an empty set instead of raising). The registry-JSON path Dextroid17 mentioned keeps full coverage where it exists; the--modulespath no longer crashes where it doesn't.#lib#modsuffix 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_modulerun complete instead of exiting 2.