fix(relinker): reject an executable dynamic string table that does not begin with NUL #11382

Merged
roboterspinne merged 4 commits from upstream-pr/11382 into main 2026-10-28 05:11:40 +00:00
roboterspinne commented 2026-10-26 10:04:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-26T10:04:41Z.


What

RelinkerPipeline reads executable names at string offset 0 without checking the first byte of DT_STRTAB: readCStr checks only that the offset is inside DT_STRSZ and that the string ends with NUL within it. On untouched 4017310678, an executable whose string table is Party.prx\0 with DT_NEEDED 0 converts with exit 0 and an output file for Linux, Linux --lazy-binding, --windows and --macos (a 16ff208dc3 build, with the same relinker code as 4017310678, also lists Party.prx in needed.json under --registry); the same offset-0 read names an import whose st_name is 0, including the all-zero symbol entries that the null-symbol handling (#4452, #7902) resolves to 0 plus addend. In the gABI, index 0 of a string table holds a NUL byte and a string at index 0 means no name; GuestImageReader already rejects a module whose string table does not begin with NUL (Invalid string or symbol table).

  • Rule. readCStr throws Dynamic string table does not begin with a NUL byte at the DT_STRTAB offset when it reads offset 0 and the first byte of the table is not NUL, right after the DT_STRSZ bounds check; the CLI exits 2 and writes no output. This covers every name the pipeline reads at offset 0: DT_NEEDED, import module names, import symbol names and export symbol names. The check sits at the offset-0 read because that is where a first byte other than NUL changes a result; a check run once for every executable would also reject the many synthetic fixtures that point DT_STRTAB at the dynamic tags with DT_STRSZ 1 and read no name. Symbol entry 0 is not part of this PR; #11367 rejects relocations against a non-null symbol entry 0.
  • Tests. test_needed_libraries.py: executable_needing takes the bytes before the name, and a new case builds Party.prx\0 with DT_NEEDED 0 and expects exit 2, FAIL: Dynamic string table does not begin with a NUL byte (offset 0x4a00) and no output for Linux, Linux --lazy-binding, --windows and --macos. The fixtures of test_optional_plt.py (convert_strict), test_unused_filter_indirect.py (build) and test_executable_segments.py (with_import) relied on a table beginning with foo; they now use \0foo\0lib.so\0, DT_NEEDED 5 and st_name 1 for symbol 1, which keeps the import named foo and DT_STRSZ 12. With the change and the old fixtures, all three tests fail with the new message.
  • Overlap. pr_overlap.py reports no shared lines with open pull requests that merge with main. It cannot compare this branch with #10792 and #10861, which also change RelinkerPipeline.cpp, because they do not merge with main. Checked by hand against main 7b415520b6: #10792 adds FindPathconfImport after line 25 and changes the syscall patch loop (lines 431 to 437); #10861 changes the unwind block that #8076 rewrote on main (the hasEhFrame block, lines 403 to 416), adds a tail scan after line 439 and SyscallContinuations after line 632. None of this is near readCStr (line 273), where this PR adds lines 276 and 277. Trial merges of this branch with each of them conflict in the same files and regions as main does (GuestModuleBuilder.cpp for #10792; GuestModuleBuilder.cpp, the hasEhFrame block of RelinkerPipeline.cpp and docs/dev/debt/relinker.md for #10861), and apart from the conflict marker labels the merged trees differ from those of main only by the lines of this PR. Neither reads a name at string offset 0: #10792 matches import names that readCStr has already returned, and the fixtures that both add or reuse begin their string tables with NUL.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.

  • Counter-check: needed_libraries with the new case on untouched 4017310678 fails with AssertionError: ([], 0, b''); all four targets exited 0 with an output file and empty stderr. optional_plt, unused_filter_indirect and executable_segments with the edited fixtures pass on untouched code. Rebased onto 3a2c51afd2, which has no relinker changes since 4017310678; with the change needed_libraries passed there in 9.8 s under -j4.
  • Merged current main (7b415520b6, which includes #11058) into the branch without conflicts (a6c2e21b3c; the earlier merges are 5b5d24cb22 in f15b926d04 and 204c6747d0 in b818895614, where main's changes to test_executable_segments.py and test_unused_filter_indirect.py merged automatically); tools/check_main_sync.py --base upstream/main reported 0 behind and a clean merge at 7b415520b6, and the later merges on main up to 035ac96edd touch no relinker file. On a6c2e21b3c, ctest -R 'dynamic_string|needed|null_symbol|import|linux_dynamic_strings|optional_plt|unused_filter_indirect|executable_segments|executable_tls_relocations' -j 6: 22 tests passed: needed_libraries (1.6 s), optional_plt, unused_filter_indirect, executable_segments, linux_dynamic_strings, executable_tls_relocations (extended by #11058), macos_trace_imports, guest_needed_modules, guest_needed_nested_modules, null_symbol_relocations, import_audit, import_symbol_types, guest_unused_import_dependencies, linux_trace_imports, windows_trace_imports, windows_named_imports, linux_named_imports, linux_guest_named_imports, windows_import_modules, weak_imports, windows_guest_weak_imports, macos_guest_weak_imports.
  • Full suite on a6c2e21b3c: ctest --test-dir build-relinker -j 6: 309 tests, 306 passed, long_paths skipped; failures known on this machine on main as well: select_tests (Windows symlink fixture) and patch_advisor_unit (path with spaces, which open #10667 fixes); both failed again alone.
  • python tools/check_conventions.py --base upstream/main with this title and description passed on a6c2e21b3c.
  • Not tested on Linux or macOS; CI runs the tests on all three hosts.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5015564749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11382). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-26T10:04:41Z. --- ### What `RelinkerPipeline` reads executable names at string offset 0 without checking the first byte of `DT_STRTAB`: `readCStr` checks only that the offset is inside `DT_STRSZ` and that the string ends with NUL within it. On untouched 4017310678, an executable whose string table is `Party.prx\0` with `DT_NEEDED` 0 converts with exit 0 and an output file for Linux, Linux `--lazy-binding`, `--windows` and `--macos` (a 16ff208dc3 build, with the same relinker code as 4017310678, also lists `Party.prx` in `needed.json` under `--registry`); the same offset-0 read names an import whose `st_name` is 0, including the all-zero symbol entries that the null-symbol handling (#4452, #7902) resolves to 0 plus addend. In the gABI, index 0 of a string table holds a NUL byte and a string at index 0 means no name; `GuestImageReader` already rejects a module whose string table does not begin with NUL (`Invalid string or symbol table`). - **Rule.** `readCStr` throws `Dynamic string table does not begin with a NUL byte` at the `DT_STRTAB` offset when it reads offset 0 and the first byte of the table is not NUL, right after the `DT_STRSZ` bounds check; the CLI exits 2 and writes no output. This covers every name the pipeline reads at offset 0: `DT_NEEDED`, import module names, import symbol names and export symbol names. The check sits at the offset-0 read because that is where a first byte other than NUL changes a result; a check run once for every executable would also reject the many synthetic fixtures that point `DT_STRTAB` at the dynamic tags with `DT_STRSZ` 1 and read no name. Symbol entry 0 is not part of this PR; #11367 rejects relocations against a non-null symbol entry 0. - **Tests.** `test_needed_libraries.py`: `executable_needing` takes the bytes before the name, and a new case builds `Party.prx\0` with `DT_NEEDED` 0 and expects exit 2, `FAIL: Dynamic string table does not begin with a NUL byte (offset 0x4a00)` and no output for Linux, Linux `--lazy-binding`, `--windows` and `--macos`. The fixtures of `test_optional_plt.py` (`convert_strict`), `test_unused_filter_indirect.py` (`build`) and `test_executable_segments.py` (`with_import`) relied on a table beginning with `foo`; they now use `\0foo\0lib.so\0`, `DT_NEEDED` 5 and `st_name` 1 for symbol 1, which keeps the import named `foo` and `DT_STRSZ` 12. With the change and the old fixtures, all three tests fail with the new message. - **Overlap.** `pr_overlap.py` reports no shared lines with open pull requests that merge with `main`. It cannot compare this branch with #10792 and #10861, which also change `RelinkerPipeline.cpp`, because they do not merge with `main`. Checked by hand against `main` 7b415520b6: #10792 adds `FindPathconfImport` after line 25 and changes the syscall patch loop (lines 431 to 437); #10861 changes the unwind block that #8076 rewrote on `main` (the `hasEhFrame` block, lines 403 to 416), adds a tail scan after line 439 and `SyscallContinuations` after line 632. None of this is near `readCStr` (line 273), where this PR adds lines 276 and 277. Trial merges of this branch with each of them conflict in the same files and regions as `main` does (`GuestModuleBuilder.cpp` for #10792; `GuestModuleBuilder.cpp`, the `hasEhFrame` block of `RelinkerPipeline.cpp` and `docs/dev/debt/relinker.md` for #10861), and apart from the conflict marker labels the merged trees differ from those of `main` only by the lines of this PR. Neither reads a name at string offset 0: #10792 matches import names that `readCStr` has already returned, and the fixtures that both add or reuse begin their string tables with NUL. ### Tested <!-- 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. --> Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew, relinked outputs not run. - Counter-check: `needed_libraries` with the new case on untouched 4017310678 fails with `AssertionError: ([], 0, b'')`; all four targets exited 0 with an output file and empty stderr. `optional_plt`, `unused_filter_indirect` and `executable_segments` with the edited fixtures pass on untouched code. Rebased onto 3a2c51afd2, which has no relinker changes since 4017310678; with the change `needed_libraries` passed there in 9.8 s under `-j4`. - Merged current `main` (7b415520b6, which includes #11058) into the branch without conflicts (a6c2e21b3c; the earlier merges are 5b5d24cb22 in f15b926d04 and 204c6747d0 in b818895614, where `main`'s changes to `test_executable_segments.py` and `test_unused_filter_indirect.py` merged automatically); `tools/check_main_sync.py --base upstream/main` reported 0 behind and a clean merge at 7b415520b6, and the later merges on `main` up to 035ac96edd touch no relinker file. On a6c2e21b3c, `ctest -R 'dynamic_string|needed|null_symbol|import|linux_dynamic_strings|optional_plt|unused_filter_indirect|executable_segments|executable_tls_relocations' -j 6`: 22 tests passed: `needed_libraries` (1.6 s), `optional_plt`, `unused_filter_indirect`, `executable_segments`, `linux_dynamic_strings`, `executable_tls_relocations` (extended by #11058), `macos_trace_imports`, `guest_needed_modules`, `guest_needed_nested_modules`, `null_symbol_relocations`, `import_audit`, `import_symbol_types`, `guest_unused_import_dependencies`, `linux_trace_imports`, `windows_trace_imports`, `windows_named_imports`, `linux_named_imports`, `linux_guest_named_imports`, `windows_import_modules`, `weak_imports`, `windows_guest_weak_imports`, `macos_guest_weak_imports`. - Full suite on a6c2e21b3c: `ctest --test-dir build-relinker -j 6`: 309 tests, 306 passed, `long_paths` skipped; failures known on this machine on `main` as well: `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (path with spaces, which open #10667 fixes); both failed again alone. - `python tools/check_conventions.py --base upstream/main` with this title and description passed on a6c2e21b3c. - Not tested on Linux or macOS; CI runs the tests on all three hosts. ### 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 (Claude Code)
MarcZX10 commented 2026-10-26 10:17:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:17:09Z.

Review: APPROVED


Reviewed the rebased head b81889561420084ee21d33b7877e9c7d050e9599. The offset-zero guard is applied inside the bounded readCStr path, so it rejects a malformed string table only when the pipeline actually reads its empty-name entry. The synthetic regression and fixture updates preserve intended names while restoring the required leading NUL. Hosted Linux, Windows, macOS and macOS x86_64 relinker jobs plus ASan all pass; the reported Windows focused and full-suite results are detailed and accurately identify the two unrelated known failures.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650453203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11382#pullrequestreview-5650453203). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T10:17:09Z. **Review:** APPROVED --- Reviewed the rebased head `b81889561420084ee21d33b7877e9c7d050e9599`. The offset-zero guard is applied inside the bounded `readCStr` path, so it rejects a malformed string table only when the pipeline actually reads its empty-name entry. The synthetic regression and fixture updates preserve intended names while restoring the required leading NUL. Hosted Linux, Windows, macOS and macOS x86_64 relinker jobs plus ASan all pass; the reported Windows focused and full-suite results are detailed and accurately identify the two unrelated known failures.
MarcZX10 commented 2026-10-26 10:38:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:38:48Z.

Review: DISMISSED


The earlier approval covers the dynamic-string-table guard and its fixture behavior on head f15b926d04. Before merge, please sync the current main: this branch's latest main merge is 5b5d24cb22, while current main is cbf76e7a6e and includes #9408's macOS import-tracing changes to RelinkerPipeline.cpp. The preview merge is clean, but those integration changes are not in the tested head. Please rerun the focused dynamic-string/needed-module tests and hosted relinker matrix after syncing. This follows CONTRIBUTING.md's requirement to keep branches up to date; I’m requesting changes only for this integration check.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650732784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11382#pullrequestreview-5650732784). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T10:38:48Z. **Review:** DISMISSED --- The earlier approval covers the dynamic-string-table guard and its fixture behavior on head `f15b926d04`. Before merge, please sync the current `main`: this branch's latest main merge is `5b5d24cb22`, while current `main` is `cbf76e7a6e` and includes #9408's macOS import-tracing changes to `RelinkerPipeline.cpp`. The preview merge is clean, but those integration changes are not in the tested head. Please rerun the focused dynamic-string/needed-module tests and hosted relinker matrix after syncing. This follows `CONTRIBUTING.md`'s requirement to keep branches up to date; I’m requesting changes only for this integration check.
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!11382
No description provided.