fix(relinker): clear Linux guest finalizer arguments #5614

Merged
JJenkx merged 6 commits from upstream-pr/5614 into main 2026-10-16 19:23:13 +00:00
JJenkx commented 2026-10-14 01:11:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-14T01:11:50Z.


What

Linux guest-module DT_FINI wrappers tail-jumped into guest code with arbitrary host argument registers. A guest finalizer accepting an optional callback could interpret stale RDX as a function pointer. Clear all three guest arguments before the jump, matching the existing macOS wrapper. Startup argument forwarding is unchanged.

The synthetic regression poisons all three arguments and checks zero/null values during direct wrapper invocation and native-loader unload, for modules both with and without DT_INIT.

Tested

Full fork CI passes head 0093322ba1810dbdf06f5115c0b75ac4fab8d4c0 against base feddf7f4c654112663b7576c8a1bc3b87657396d: Linux 1044 passed/46 expected skips; Windows 721 passed/389 expected skips. Expected skips remain unvalidated.

The regression fails before the fix. Earlier native RollerCoaster Tycoon Adventures: Deluxe debugging showed this removes an invalid shutdown callback jump; a separate registry-lifetime fix was needed for ordinary exit. That integration result does not establish title compatibility for this standalone PR. The previous d167-based CI Windows attempt timed out in agc_driver_pm4 after its success line; the failed job passed on retry, with the cause unisolated. The fresh run linked above passed.

The branch merges cleanly into main b16a1a72f3dd824da1c53184d279a14709bdffda; current conventions and whitespace checks pass. Full CI applies to its recorded head/base, not the latest-main merged tree.

Independent title evidence

hugodearaujo reports a controlled Hollow Knight: Silksong PPSA12544 test: Linux / RX 9070 XT, main f0854887d plus #5905, identical libraries and title tree, alternating relinkers with or without this wrapper change. Four baseline exits segfaulted; four with this change did not. Each run waited at the main menu for 60 seconds, then received SIGTERM. Their debugger/disassembly identifies CommonDialog's optional finalizer callback being read from stale RDX. Behavior before exit was unchanged.

This is the other contributor's reported evidence on their recorded base, not a new run on my machine or validation against today's main. It links this generic shutdown fix to the Silksong bring-up; it does not claim full title compatibility.

Manual overlap review for #6901 at be4f4aa72a5c06b5320f1bb8b96e24e312112a95: its listed LinuxGuestModuleWriter.cpp still uses callThrough(image.Fini), so it does not implement this finalizer argument-clearing change. It is not a prerequisite. This branch also passes a fresh local merge-tree check against main d9b696ddbb000991f127dc9f4ba2fd980c517742; this is mergeability evidence, not a fresh full build.

Checklist

  • One topic; generic behavior.
  • No proprietary assets or investigation artifacts committed.
  • Depends on: none.
  • Unblocks: PPSA12544 #726 (Linux shutdown crash; independent test linked above).
  • GPUs tested: n/a.
  • AI-assisted: yes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851536665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5614). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-14T01:11:50Z. --- ### What Linux guest-module DT_FINI wrappers tail-jumped into guest code with arbitrary host argument registers. A guest finalizer accepting an optional callback could interpret stale RDX as a function pointer. Clear all three guest arguments before the jump, matching the existing macOS wrapper. Startup argument forwarding is unchanged. The synthetic regression poisons all three arguments and checks zero/null values during direct wrapper invocation and native-loader unload, for modules both with and without DT_INIT. ### Tested [Full fork CI](https://github.com/JJenkx/AnyPS5/actions/runs/38491420814) passes head `0093322ba1810dbdf06f5115c0b75ac4fab8d4c0` against base `feddf7f4c654112663b7576c8a1bc3b87657396d`: Linux 1044 passed/46 expected skips; Windows 721 passed/389 expected skips. Expected skips remain unvalidated. The regression fails before the fix. Earlier native RollerCoaster Tycoon Adventures: Deluxe debugging showed this removes an invalid shutdown callback jump; a separate registry-lifetime fix was needed for ordinary exit. That integration result does not establish title compatibility for this standalone PR. The previous d167-based CI Windows attempt timed out in agc_driver_pm4 after its success line; the failed job passed on retry, with the cause unisolated. The fresh run linked above passed. The branch merges cleanly into main `b16a1a72f3dd824da1c53184d279a14709bdffda`; current conventions and whitespace checks pass. Full CI applies to its recorded head/base, not the latest-main merged tree. ### Independent title evidence [hugodearaujo reports a controlled Hollow Knight: Silksong PPSA12544 test](https://github.com/boykopovar/AnyPS5/pull/5614#issuecomment-6176500011): Linux / RX 9070 XT, main `f0854887d` plus #5905, identical libraries and title tree, alternating relinkers with or without this wrapper change. Four baseline exits segfaulted; four with this change did not. Each run waited at the main menu for 60 seconds, then received SIGTERM. Their debugger/disassembly identifies CommonDialog's optional finalizer callback being read from stale RDX. Behavior before exit was unchanged. This is the other contributor's reported evidence on their recorded base, not a new run on my machine or validation against today's main. It links this generic shutdown fix to the [Silksong bring-up](https://github.com/boykopovar/AnyPS5/discussions/726); it does not claim full title compatibility. Manual overlap review for #6901 at `be4f4aa72a5c06b5320f1bb8b96e24e312112a95`: its listed `LinuxGuestModuleWriter.cpp` still uses `callThrough(image.Fini)`, so it does not implement this finalizer argument-clearing change. It is not a prerequisite. This branch also passes a fresh local merge-tree check against main `d9b696ddbb000991f127dc9f4ba2fd980c517742`; this is mergeability evidence, not a fresh full build. ### Checklist - [x] One topic; generic behavior. - [x] No proprietary assets or investigation artifacts committed. - [x] Depends on: none. - [x] Unblocks: PPSA12544 #726 (Linux shutdown crash; independent test linked above). - [x] GPUs tested: n/a. - [x] AI-assisted: yes.
hugodearaujo commented 2026-10-14 19:24:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-14T19:24:41Z.


A title that needs this: Hollow Knight: Silksong (PPSA12544, my own dump) crashes with SIGSEGV every time it exits on Linux, and this PR removes the crash.

What happens. Silksong loads its Unity plugins at run time (Media/Plugins, relinked with --module-dir Media/Plugins). When the process exits, glibc's _dl_fini calls each plugin's DT_FINI, which is the plain jmp this PR replaces. CommonDialog.prx's finalizer takes a callback in rdx and calls it when it is not null:

3fe7: cmpb   $0x0,0xc022(%rip)   ; already finalized?
3fee: jne    406a
3ff0: test   %rdx,%rdx
3ff3: je     3ff9                ; null: its own module_stop path
3ff5: call   *%rdx

Under gdb (SIGTERM after 60 s at the main menu), the crashing thread is in that call. rdx was left by glibc and points into the module's own .dynamic (module base + 0x16548; PT_DYNAMIC is 0x160f8+0x480). The thread then executes the zero bytes there:

SIGSEGV, si_addr 0xb443e0ef
rip 0x7fffb443e54d  add %al,(%rax)        rax 0xb443e0ef  rdx 0x7fffb443e548
#1  0x7fffb442bff7  (CommonDialog.prx.guest.prx + 0x3ff7, the return address of `call *%rdx`)
map 7fffb443c000-7fffb443f000 rwxp 00018000 .../Media/Plugins/CommonDialog.prx.guest.prx

Measured. RX 9070 XT, Linux, main f0854887d with #5905 (libraries unchanged between the two arms). The only difference is the relinker used for the same title tree, --registry --module-dir Media/Plugins: built from that tree, or with this PR's LinuxGuestModuleWriter.cpp change on top. Each run waits at the main menu with no input for 60 s, then gets SIGTERM. The runs alternate between the two arms.

Relinker Runs SIGSEGV at exit
without this PR 4 4
this PR 4 0

The title behaves the same until the exit in both arms.

AI-assisted: written with Claude Code; I reviewed the stacks, the disassembly and the runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176500011 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5614#issuecomment-6176500011). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-14T19:24:41Z. --- A title that needs this: Hollow Knight: Silksong (PPSA12544, my own dump) crashes with SIGSEGV every time it exits on Linux, and this PR removes the crash. **What happens.** Silksong loads its Unity plugins at run time (`Media/Plugins`, relinked with `--module-dir Media/Plugins`). When the process exits, glibc's `_dl_fini` calls each plugin's `DT_FINI`, which is the plain `jmp` this PR replaces. `CommonDialog.prx`'s finalizer takes a callback in `rdx` and calls it when it is not null: ``` 3fe7: cmpb $0x0,0xc022(%rip) ; already finalized? 3fee: jne 406a 3ff0: test %rdx,%rdx 3ff3: je 3ff9 ; null: its own module_stop path 3ff5: call *%rdx ``` Under gdb (SIGTERM after 60 s at the main menu), the crashing thread is in that call. `rdx` was left by glibc and points into the module's own `.dynamic` (module base + `0x16548`; `PT_DYNAMIC` is `0x160f8`+`0x480`). The thread then executes the zero bytes there: ``` SIGSEGV, si_addr 0xb443e0ef rip 0x7fffb443e54d add %al,(%rax) rax 0xb443e0ef rdx 0x7fffb443e548 #1 0x7fffb442bff7 (CommonDialog.prx.guest.prx + 0x3ff7, the return address of `call *%rdx`) map 7fffb443c000-7fffb443f000 rwxp 00018000 .../Media/Plugins/CommonDialog.prx.guest.prx ``` **Measured.** RX 9070 XT, Linux, `main` `f0854887d` with #5905 (libraries unchanged between the two arms). The only difference is the relinker used for the same title tree, `--registry --module-dir Media/Plugins`: built from that tree, or with this PR's `LinuxGuestModuleWriter.cpp` change on top. Each run waits at the main menu with no input for 60 s, then gets SIGTERM. The runs alternate between the two arms. | Relinker | Runs | SIGSEGV at exit | |---|---|---| | without this PR | 4 | 4 | | this PR | 4 | 0 | The title behaves the same until the exit in both arms. AI-assisted: written with Claude Code; I reviewed the stacks, the disassembly and the runs.
github-actions[bot] commented 2026-10-15 12:08:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:08:14Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191679483 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5614#issuecomment-6191679483). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:08:14Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` |
adriadam10 commented 2026-10-16 18:19:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T18:19:20Z.


Checked the finalizer wrapper (xor edi/esi/edx then jmp rel32, displacement computed from start + 11), built and ran the relinker ctest scope (136/136 pass, guest_module_fini runs natively, not skipped). Reverting only LinuxGuestModuleWriter.cpp makes guest_module_fini fail, so the test pins the fix. hugodearaujo's A/B on Silksong covers the real-title case. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6221947526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5614#issuecomment-6221947526). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T18:19:20Z. --- Checked the finalizer wrapper (`xor edi/esi/edx` then `jmp rel32`, displacement computed from `start + 11`), built and ran the relinker ctest scope (136/136 pass, `guest_module_fini` runs natively, not skipped). Reverting only `LinuxGuestModuleWriter.cpp` makes `guest_module_fini` fail, so the test pins the fix. hugodearaujo's A/B on Silksong covers the real-title case. Merging once the full Build is green.
JJenkx commented 2026-10-16 18:45:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-16T18:45:08Z.


The current head remains mergeable. The Linux, Windows, and macOS relinker jobs passed, but the full linux and windows jobs on the Build run were skipped. Could a maintainer dispatch Build on upstream main with pr=5614, linux=true, and full=true to satisfy the remaining gate? My account has read-only upstream permissions, so I cannot dispatch it. No source changes since the reviewed head 0093322ba1810dbdf06f5115c0b75ac4fab8d4c0.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222389952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5614#issuecomment-6222389952). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-16T18:45:08Z. --- The current head remains mergeable. The Linux, Windows, and macOS relinker jobs passed, but the full `linux` and `windows` jobs on [the Build run](https://github.com/boykopovar/AnyPS5/actions/runs/38494387434) were skipped. Could a maintainer dispatch **Build** on upstream `main` with `pr=5614`, `linux=true`, and `full=true` to satisfy the remaining gate? My account has read-only upstream permissions, so I cannot dispatch it. No source changes since the reviewed head `0093322ba1810dbdf06f5115c0b75ac4fab8d4c0`.
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!5614
No description provided.