fix(libkernel): consume queried module info in address matching #18111

Merged
HenriksApsitis merged 1 commit from upstream-pr/18111 into main 2026-11-16 02:19:50 +00:00
HenriksApsitis commented 2026-11-10 13:27:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by HenriksApsitis on 2026-11-10T13:27:31Z.


What

Fix the query-to-match sequence reported for LEGO Voyagers (PPSA23732) in #8675. This is a current producer/consumer mismatch, not another implementation of the original #8676 fix.

__elf_phdr_match_addr recognizes a ModuleInfoEx only when its first word equals sizeof(ModuleInfoEx). Since merged #10230 (3717573887504046961817cebbe89b70f23203df), sceKernelGetModuleInfoFromAddr deliberately returns zero there, matching the reporter's PS5 firmware 13.60 measurements. Passing its unchanged result to the matcher therefore falls into the dl_phdr_info parser and treats module-name bytes as a header pointer.

Make the supported pointer ABI explicit as const ModuleInfoEx* and consume its already-relocated segment records regardless of st_size. Remove the FreeBSD-layout fallback: #337 explicitly inferred that signature without a title or console check, whereas #8675 documents the title passing the module-info query's object. Accepting zero as a second layout tag would be ambiguous with a legitimate dl_phdr_info.dlpi_addr == 0. The export name, NID and machine-level argument ABI are unchanged.

Preserve the existing ModuleInfoEx branch's executable protection check, eight-byte remaining-range rule and four-segment bound. Migrate the synthetic coverage to that record type and add the real query-to-match sequence for both accepted query flags, a non-executable data control, record non-mutation and range/count limits. Record the unmeasured console edge semantics in debt.

Tested

CachyOS Linux 7.3.1-1-cachyos, AMD Ryzen 5 9600X, GCC 16.2.1, CMake 4.4.5, Ninja 1.13.2, Python 3.14.9. Clean isolated full-runtime Release configuration with BUILD_TESTING=ON; only the relevant test targets and their runtime/fixture dependencies were built, not the whole runtime suite. Reproduction baseline 698b6ed1215316a5f85bcd0e9939e4a96ed52b7d; publication base 706573b02fb1e473092498cce6ee1b5c2ac856af; final head 50695b0d9b299297f1bd642aed8767909deefdb4. The four-file patch is byte-identical after rebasing; the seven focused tests were rebuilt and repeated on the final clean head.

  • Before production edits, the unchanged guest_elf_phdr_match and guest_module_info pass (2/2). Adding only the real query-to-match regression makes guest_elf_phdr_match fail with SIGSEGV (CTest exit 8).
  • A separate unchanged probe against the saved exact-baseline libraries prints query=0 size=0 ... segments=4, then faults at __elf_phdr_match_addr_nid_postfix+48, cmpl $0x1,(%rax). The identical executable against candidate libraries prints match=1 and exits zero. No record fields are rewritten between query and match.
  • Candidate: guest_elf_phdr_match, guest_module_info, guest_dynamic_loader, guest_dynamic_loader_variant_names, guest_unwind_module_info, guest_unwind_module_info_failure, and guest_kernel_sys_module_internal pass three repetitions each (7 distinct tests, 21 executions, no skips). The six neighboring controls also pass three repetitions each against the saved baseline libraries.
  • Full public-header audit and standalone umbrella compilation pass: 407 libraries and 33,850 exports. Conventions and whitespace checks pass on the committed candidate and final head.
  • Independent specification review and subsequent code-quality/security review pass without findings. Both reviewed frozen patch SHA-256 a92061808b33b2727a5e0b835bbba08ef667b31855177c2764df53eafe6be00e; the final rebased diff has that same digest. Reviewers did not execute the builds/tests reported above.

Full pr_overlap.py --base main --branch audit/module-info-query-match-candidate --repo boykopovar/AnyPS5 --jobs 4 inspected 1,987 open PRs and 115 shared-file/export candidates against main 706573b02fb1e473092498cce6ee1b5c2ac856af. It exited 2, not a clean pass: 38 other branches conflict with the base, so their shared files could not be compared automatically. Manually compared all 38 API-verified fetched heads against each of their merge bases (39 comparisons; #10442 has two), retaining full diffs and pins. None changes this helper, its declaration, its regression or its new debt entry. #5021's shared code adds macOS unwind-table handling; #6149 changes module-start arguments; #11215 changes an unrelated context-function declaration. The rest share only unrelated debt entries or blank-line formatting. No dependency is required from these comparisons.

Manual overlap audit: exact heads
  • #5021 151294f979ab00aaff2f702314425caf61a72790 — feat(aot): consolidate native ARM64 compiler, runtime and consumers
  • #6149 a407a5ef836405798b7e248b876acd66aa3f39e7 — fix(libkernel): provide default arguments block for DT_INIT on Linux
  • #6740 a9b6788f8bb0142043c145484f4323831869f11a — fix(libkernel): prevent use-after-free on pthread semaphore destruction and notification race
  • #6936 f06949da78cf801f47702e27f0dd987f4b80e184 — feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek
  • #7088 f4155ddf0711db1cb09dd64459065c46ac6dbe8e — feat(libkernel): support kevent read and write events on regular files
  • #7121 cb750ff85695ea65ff493d321c3242407536895b — feat(libkernel): report open, read and close notes on watched files
  • #7149 2456bc05a2e885120c5b282ecc0f46eb0a8b4fe2 — fix(threads): run Windows pthread and small fiber stacks in guest VA range
  • #7447 7faf2fff1fffad65690a893f489943616d129aaa — feat(libc): support archive-backed stdio reads
  • #7464 020917ce9e31d15f27c4bd53c3965cfaf8502e0c — perf(agc): keep unimported label stores on the CPU
  • #9156 550810d74a304089683fd7f6994315974df0aaa1 — feat(libkernel): implement four pthread_attr forms
  • #9199 355d421183ec89484dd02158f70f58b60c28d191 — docs(debt): cite firmware 10.01 kernel data for four libkernel entries
  • #9293 b208fd6b210d26e58b969d2341404b4cf085f5b0 — feat(libkernel): implement the named ksem semaphores
  • #9297 d07deaa187134d4e2482a5f48aeea9f1f5601ab3 — feat(libkernel_sys): implement POSIX message queues
  • #9302 c045c1e91fe983f7e3e513692110e15b16470953 — feat(libkernel_sys): implement kmq_notify registration
  • #9389 3a75bf46109389bd33cfbb9724b59b8546a47d7d — feat(libkernel_sys): implement sigqueue
  • #9557 f8698a0b663a95a51f59839c42e245bf0f5598e0 — feat(libkernel): keep the SIGIO owner of a pipe for F_GETOWN and F_SETOWN
  • #9566 0bc531a0a29be507638f5edaa51645a8169aed4f — feat(libkernel): answer tcgetpgrp and tcsetpgrp on a pipe with its SIGIO owner
  • #9938 db41fa38767f3347af18c7308d517e7359c13950 — fix(libkernel): honor caller-provided pthread stacks
  • #10442 77fe6e4d65af36605aa4be5d7b2ab3e8b8f3165b — perf(agc): store an unimported label at once when unfinished work leaves guest memory alone
  • #11215 7c3ff4148c2e20144a7d455dc5e6af560297bd7e — feat(libkernel): implement __Ux86_64_setcontext
  • #11628 f013da972573fa4dfca95607f2462501d6ad2234 — feat(relinker): execute supported scalar guest GS accesses on Windows
  • #11661 b813f34cfbbadc2d73e879b1e973491add56377c — feat(relinker): support short scalar guest GS instructions
  • #11689 5551631d9e9263e8634e44d272d683966e1d18b5 — feat(relinker): support SSE guest GS memory accesses
  • #11698 f16c9e062bd1d7607e1b3c976a6071904a81960c — feat(relinker): support VEX guest GS memory accesses
  • #11896 ef5ae8ee9074486c4715f8b10c75ffdb87c735cf — fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer
  • #12682 32121ca48d0abf5e1c11e7c601636d10ec8cb77d — feat(libkernel): cancel blocked POSIX reads with owned operations
  • #12688 8f34999f2fad40fcf704765c3dedcafe5d157fa7 — fix(libkernel): preserve blocking sockets over nonblocking native transport
  • #12700 bf740fcd275bc7e9c8a78cbfce94da554e0e78b0 — feat(libkernel): cancel blocked POSIX writes with partial progress
  • #12965 99dee9956598573e0f66bd0dae68040cfad574ad — feat(libkernel): support deferred cancellation in POSIX accept
  • #14108 3385df150895b96c763650fdf78bc3526274f412 — fix(libkernel): validate null pointers in pthread rwlock functions
  • #14128 4cd962f4ca01fbfbe836d61b7a6952844aa54abe — fix(libkernel): return SCE_KERNEL_ERROR_EINVAL for null key in scePthreadKeyCreate
  • #14212 4d105ce487cac38c209496c2f8cbe3ae340d39da — docs(debt): separate entries with blank lines and drop derived export totals
  • #14497 7d75cace5a99f4029e8699f806fa6fe7b40170fe — fix(libkernel): return EFAULT from JIT shared memory queries for unwritable pointers
  • #14756 8f54a85c1cdd9810bc64d8cc765c603f97c94aa4 — feat(libkernel): follow FreeBSD for SO_ACCEPTFILTER on a listening socket
  • #15037 a5d352f04d1375b14cd4eac88c6691e346dc5bf1 — feat(libkernel_sys): implement mount, unmount and nmount privilege checks
  • #15571 3bd7e736346200b05f4504a2aaf42f2757659bfd — fix(libkernel): fail scePthreadGetname and pthread_getname_np with EFAULT on an unwritable buffer
  • #16441 af179438e196e5143b999a852a25ea68dffd904c — test(libkernel): name the exception fault test's assembly symbols for Mach-O
  • #16826 6b9840b9a63301c5b1e15e8fccca82a4e6400bfa — fix(libSceNet): keep close-on-exec for fcntl on a sceNetSocket socket as FreeBSD does

This manual result does not turn the automatic exit 2 into a passing gate.

No console, LEGO Voyagers or other title run; no native Windows/macOS execution, complete runtime suite, GPU validation or performance claim. The related title evidence belongs to the original issue/PR reporters. Exact range-boundary and invalid-pointer console behavior remain unmeasured.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5242097939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18111). Originally posted by [HenriksApsitis](https://github.com/HenriksApsitis) on 2026-11-10T13:27:31Z. --- ### What Fix the query-to-match sequence reported for LEGO Voyagers (PPSA23732) in #8675. This is a current producer/consumer mismatch, not another implementation of the original #8676 fix. `__elf_phdr_match_addr` recognizes a `ModuleInfoEx` only when its first word equals `sizeof(ModuleInfoEx)`. Since merged #10230 (`3717573887504046961817cebbe89b70f23203df`), `sceKernelGetModuleInfoFromAddr` deliberately returns zero there, matching the reporter's PS5 firmware 13.60 measurements. Passing its unchanged result to the matcher therefore falls into the `dl_phdr_info` parser and treats module-name bytes as a header pointer. Make the supported pointer ABI explicit as `const ModuleInfoEx*` and consume its already-relocated segment records regardless of `st_size`. Remove the FreeBSD-layout fallback: #337 explicitly inferred that signature without a title or console check, whereas #8675 documents the title passing the module-info query's object. Accepting zero as a second layout tag would be ambiguous with a legitimate `dl_phdr_info.dlpi_addr == 0`. The export name, NID and machine-level argument ABI are unchanged. Preserve the existing ModuleInfoEx branch's executable protection check, eight-byte remaining-range rule and four-segment bound. Migrate the synthetic coverage to that record type and add the real query-to-match sequence for both accepted query flags, a non-executable data control, record non-mutation and range/count limits. Record the unmeasured console edge semantics in debt. ### Tested CachyOS Linux `7.3.1-1-cachyos`, AMD Ryzen 5 9600X, GCC 16.2.1, CMake 4.4.5, Ninja 1.13.2, Python 3.14.9. Clean isolated full-runtime Release configuration with `BUILD_TESTING=ON`; only the relevant test targets and their runtime/fixture dependencies were built, not the whole runtime suite. Reproduction baseline `698b6ed1215316a5f85bcd0e9939e4a96ed52b7d`; publication base `706573b02fb1e473092498cce6ee1b5c2ac856af`; final head `50695b0d9b299297f1bd642aed8767909deefdb4`. The four-file patch is byte-identical after rebasing; the seven focused tests were rebuilt and repeated on the final clean head. - Before production edits, the unchanged `guest_elf_phdr_match` and `guest_module_info` pass (2/2). Adding only the real query-to-match regression makes `guest_elf_phdr_match` fail with SIGSEGV (CTest exit 8). - A separate unchanged probe against the saved exact-baseline libraries prints `query=0 size=0 ... segments=4`, then faults at `__elf_phdr_match_addr_nid_postfix+48`, `cmpl $0x1,(%rax)`. The identical executable against candidate libraries prints `match=1` and exits zero. No record fields are rewritten between query and match. - Candidate: `guest_elf_phdr_match`, `guest_module_info`, `guest_dynamic_loader`, `guest_dynamic_loader_variant_names`, `guest_unwind_module_info`, `guest_unwind_module_info_failure`, and `guest_kernel_sys_module_internal` pass three repetitions each (7 distinct tests, 21 executions, no skips). The six neighboring controls also pass three repetitions each against the saved baseline libraries. - Full public-header audit and standalone umbrella compilation pass: 407 libraries and 33,850 exports. Conventions and whitespace checks pass on the committed candidate and final head. - Independent specification review and subsequent code-quality/security review pass without findings. Both reviewed frozen patch SHA-256 `a92061808b33b2727a5e0b835bbba08ef667b31855177c2764df53eafe6be00e`; the final rebased diff has that same digest. Reviewers did not execute the builds/tests reported above. Full `pr_overlap.py --base main --branch audit/module-info-query-match-candidate --repo boykopovar/AnyPS5 --jobs 4` inspected 1,987 open PRs and 115 shared-file/export candidates against main `706573b02fb1e473092498cce6ee1b5c2ac856af`. It exited **2**, not a clean pass: 38 other branches conflict with the base, so their shared files could not be compared automatically. Manually compared all 38 API-verified fetched heads against each of their merge bases (39 comparisons; #10442 has two), retaining full diffs and pins. None changes this helper, its declaration, its regression or its new debt entry. #5021's shared code adds macOS unwind-table handling; #6149 changes module-start arguments; #11215 changes an unrelated context-function declaration. The rest share only unrelated debt entries or blank-line formatting. No dependency is required from these comparisons. <details><summary>Manual overlap audit: exact heads</summary> - #5021 `151294f979ab00aaff2f702314425caf61a72790` — feat(aot): consolidate native ARM64 compiler, runtime and consumers - #6149 `a407a5ef836405798b7e248b876acd66aa3f39e7` — fix(libkernel): provide default arguments block for DT_INIT on Linux - #6740 `a9b6788f8bb0142043c145484f4323831869f11a` — fix(libkernel): prevent use-after-free on pthread semaphore destruction and notification race - #6936 `f06949da78cf801f47702e27f0dd987f4b80e184` — feat(libkernel): support SEEK_DATA and SEEK_HOLE in lseek - #7088 `f4155ddf0711db1cb09dd64459065c46ac6dbe8e` — feat(libkernel): support kevent read and write events on regular files - #7121 `cb750ff85695ea65ff493d321c3242407536895b` — feat(libkernel): report open, read and close notes on watched files - #7149 `2456bc05a2e885120c5b282ecc0f46eb0a8b4fe2` — fix(threads): run Windows pthread and small fiber stacks in guest VA range - #7447 `7faf2fff1fffad65690a893f489943616d129aaa` — feat(libc): support archive-backed stdio reads - #7464 `020917ce9e31d15f27c4bd53c3965cfaf8502e0c` — perf(agc): keep unimported label stores on the CPU - #9156 `550810d74a304089683fd7f6994315974df0aaa1` — feat(libkernel): implement four pthread_attr forms - #9199 `355d421183ec89484dd02158f70f58b60c28d191` — docs(debt): cite firmware 10.01 kernel data for four libkernel entries - #9293 `b208fd6b210d26e58b969d2341404b4cf085f5b0` — feat(libkernel): implement the named ksem semaphores - #9297 `d07deaa187134d4e2482a5f48aeea9f1f5601ab3` — feat(libkernel_sys): implement POSIX message queues - #9302 `c045c1e91fe983f7e3e513692110e15b16470953` — feat(libkernel_sys): implement kmq_notify registration - #9389 `3a75bf46109389bd33cfbb9724b59b8546a47d7d` — feat(libkernel_sys): implement sigqueue - #9557 `f8698a0b663a95a51f59839c42e245bf0f5598e0` — feat(libkernel): keep the SIGIO owner of a pipe for F_GETOWN and F_SETOWN - #9566 `0bc531a0a29be507638f5edaa51645a8169aed4f` — feat(libkernel): answer tcgetpgrp and tcsetpgrp on a pipe with its SIGIO owner - #9938 `db41fa38767f3347af18c7308d517e7359c13950` — fix(libkernel): honor caller-provided pthread stacks - #10442 `77fe6e4d65af36605aa4be5d7b2ab3e8b8f3165b` — perf(agc): store an unimported label at once when unfinished work leaves guest memory alone - #11215 `7c3ff4148c2e20144a7d455dc5e6af560297bd7e` — feat(libkernel): implement __Ux86_64_setcontext - #11628 `f013da972573fa4dfca95607f2462501d6ad2234` — feat(relinker): execute supported scalar guest GS accesses on Windows - #11661 `b813f34cfbbadc2d73e879b1e973491add56377c` — feat(relinker): support short scalar guest GS instructions - #11689 `5551631d9e9263e8634e44d272d683966e1d18b5` — feat(relinker): support SSE guest GS memory accesses - #11698 `f16c9e062bd1d7607e1b3c976a6071904a81960c` — feat(relinker): support VEX guest GS memory accesses - #11896 `ef5ae8ee9074486c4715f8b10c75ffdb87c735cf` — fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer - #12682 `32121ca48d0abf5e1c11e7c601636d10ec8cb77d` — feat(libkernel): cancel blocked POSIX reads with owned operations - #12688 `8f34999f2fad40fcf704765c3dedcafe5d157fa7` — fix(libkernel): preserve blocking sockets over nonblocking native transport - #12700 `bf740fcd275bc7e9c8a78cbfce94da554e0e78b0` — feat(libkernel): cancel blocked POSIX writes with partial progress - #12965 `99dee9956598573e0f66bd0dae68040cfad574ad` — feat(libkernel): support deferred cancellation in POSIX accept - #14108 `3385df150895b96c763650fdf78bc3526274f412` — fix(libkernel): validate null pointers in pthread rwlock functions - #14128 `4cd962f4ca01fbfbe836d61b7a6952844aa54abe` — fix(libkernel): return SCE_KERNEL_ERROR_EINVAL for null key in scePthreadKeyCreate - #14212 `4d105ce487cac38c209496c2f8cbe3ae340d39da` — docs(debt): separate entries with blank lines and drop derived export totals - #14497 `7d75cace5a99f4029e8699f806fa6fe7b40170fe` — fix(libkernel): return EFAULT from JIT shared memory queries for unwritable pointers - #14756 `8f54a85c1cdd9810bc64d8cc765c603f97c94aa4` — feat(libkernel): follow FreeBSD for SO_ACCEPTFILTER on a listening socket - #15037 `a5d352f04d1375b14cd4eac88c6691e346dc5bf1` — feat(libkernel_sys): implement mount, unmount and nmount privilege checks - #15571 `3bd7e736346200b05f4504a2aaf42f2757659bfd` — fix(libkernel): fail scePthreadGetname and pthread_getname_np with EFAULT on an unwritable buffer - #16441 `af179438e196e5143b999a852a25ea68dffd904c` — test(libkernel): name the exception fault test's assembly symbols for Mach-O - #16826 `6b9840b9a63301c5b1e15e8fccca82a4e6400bfa` — fix(libSceNet): keep close-on-exec for fcntl on a sceNetSocket socket as FreeBSD does This manual result does not turn the automatic exit 2 into a passing gate. </details> No console, LEGO Voyagers or other title run; no native Windows/macOS execution, complete runtime suite, GPU validation or performance claim. The related title evidence belongs to the original issue/PR reporters. Exact range-boundary and invalid-pointer console behavior remain unmeasured. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
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!18111
No description provided.