fix(relinker): trap the inlined SDK __syscall6 stubs #11137

Merged
kaiffeetasse merged 2 commits from upstream-pr/11137 into main 2026-11-01 21:49:26 +00:00
kaiffeetasse commented 2026-10-25 19:26:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kaiffeetasse on 2026-10-25T19:26:23Z.


What

--trap-sdk-syscall-stubs recognizes the generic and numbered wrapper stubs and the three inline mmap/mprotect sequences from SDK libc/mman.c, but not the inlined __syscall6 wrappers from SDK libc/mount.c. Both payloads named in #8624 stop on mount (ftpsrv v0.21.1 at code offset 0x709a, websrv v0.35 at 0xae6a) and, once that one is recognized, on nmount (0x70ec / 0xaebc) and unmount (0x713c / 0xaf0c).

This adds an exact sequence for each of the three wrappers, with its syscall number pinned in the pattern like the mman sequences, so a stub that carries another number is not matched. Their argument preparation differs, so one pattern cannot cover them. The decoded-instruction-boundary check, the full-sequence requirement and the UD2 substitution are unchanged: mount, nmount and unmount are not implemented, and a call still faults. The technical-debt entry and the option description say so.

#9549 edits the same trap condition line; whichever of the two lands second needs a trivial rebase. There is no dependency on it, and no other open PR implements these sequences (#8729 was closed).

Tested

Linux, Ubuntu 24.04, GCC 13.3, relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON):

  • ctest --test-dir build-relinker -R "syscall|sdk_mman": 4 of 4 pass (sdk_mman_syscall, guest_syscall_trap, syscall_number, syscall_scanner). The fixture set gains the three sequences, a near-match mutation check over every byte, and a check that rewrites each stub's syscall-number field to 0, 1, 21, 22 and 378 and requires every number other than the stub's own to be rejected.
  • python3 tools/check_conventions.py --base origin/main: all checks pass.
  • Conversion of every PS5 ELF asset in the current ps5-payload-dev releases, --trap-sdk-syscall-stubs --skip-sce-module: 22 of 22 exit 0 (elfldr v0.25/v0.26, ftpsrv v0.21/v0.21.1 binary and installer, websrv v0.34/v0.35, shsrv v0.19/v0.20, gdbsrv v0.8/v0.9, klogsrv v0.8/v0.9, launchpad v0.1/v0.2, plutotv v0.2/v0.3, svtplay v0.3/v0.4, tv4play v0.2/v0.3). On the same build recognizing only mount, 10 of 22 convert and every failure is the next wrapper of the family. Trapped sites: ftpsrv 239, websrv 236.
  • Not tested: executing a converted payload, the Windows and macOS outputs beyond the relinker build, and what the console does with these three syscalls.

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: #8624
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007917763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11137). Originally posted by [kaiffeetasse](https://github.com/kaiffeetasse) on 2026-10-25T19:26:23Z. --- ### What `--trap-sdk-syscall-stubs` recognizes the generic and numbered wrapper stubs and the three inline `mmap`/`mprotect` sequences from SDK `libc/mman.c`, but not the inlined `__syscall6` wrappers from SDK `libc/mount.c`. Both payloads named in #8624 stop on `mount` (ftpsrv v0.21.1 at code offset 0x709a, websrv v0.35 at 0xae6a) and, once that one is recognized, on `nmount` (0x70ec / 0xaebc) and `unmount` (0x713c / 0xaf0c). This adds an exact sequence for each of the three wrappers, with its syscall number pinned in the pattern like the mman sequences, so a stub that carries another number is not matched. Their argument preparation differs, so one pattern cannot cover them. The decoded-instruction-boundary check, the full-sequence requirement and the `UD2` substitution are unchanged: `mount`, `nmount` and `unmount` are not implemented, and a call still faults. The technical-debt entry and the option description say so. #9549 edits the same trap condition line; whichever of the two lands second needs a trivial rebase. There is no dependency on it, and no other open PR implements these sequences (#8729 was closed). ### Tested Linux, Ubuntu 24.04, GCC 13.3, relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`): - `ctest --test-dir build-relinker -R "syscall|sdk_mman"`: 4 of 4 pass (`sdk_mman_syscall`, `guest_syscall_trap`, `syscall_number`, `syscall_scanner`). The fixture set gains the three sequences, a near-match mutation check over every byte, and a check that rewrites each stub's syscall-number field to 0, 1, 21, 22 and 378 and requires every number other than the stub's own to be rejected. - `python3 tools/check_conventions.py --base origin/main`: all checks pass. - Conversion of every PS5 ELF asset in the current ps5-payload-dev releases, `--trap-sdk-syscall-stubs --skip-sce-module`: **22 of 22 exit 0** (elfldr v0.25/v0.26, ftpsrv v0.21/v0.21.1 binary and installer, websrv v0.34/v0.35, shsrv v0.19/v0.20, gdbsrv v0.8/v0.9, klogsrv v0.8/v0.9, launchpad v0.1/v0.2, plutotv v0.2/v0.3, svtplay v0.3/v0.4, tv4play v0.2/v0.3). On the same build recognizing only `mount`, 10 of 22 convert and every failure is the next wrapper of the family. Trapped sites: ftpsrv 239, websrv 236. - Not tested: executing a converted payload, the Windows and macOS outputs beyond the relinker build, and what the console does with these three syscalls. ### Checklist - [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: none - [x] Fixes: #8624 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 19:33:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:33:09Z.

Review: APPROVED


Reviewed exact head d34554e71cdbc483cb8d5e561a1b815b80fba76a. The three byte patterns and masked syscall-number immediate offsets align with their fixtures (mount 13..16, nmount 15..18, unmount 13..16); matching still requires the complete pattern and a decoded instruction boundary. The change only turns the recognized unimplemented wrappers into the existing UD2 trap under the opt-in flag, and the usage/debt text states that execution remains unsupported.

Local validation on this head:

  • Relinker-only Release configure and relinker build: passed.
  • Built sdk_mman_syscall_tests and syscall_scanner_tests; CTest sdk_mman_syscall, guest_syscall_trap, syscall_number, and syscall_scanner: 4/4 passed.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check upstream/main...HEAD: passed.
  • A merge-tree comparison with the current #9549 head is clean; I found no merge-order dependency in that comparison.

GitHub conventions, intake and labels pass; no hosted build job is listed. The PR reports additional payload conversion runs; I did not rerun those external payload sweeps. No blocking issue found in this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644891773 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11137#pullrequestreview-5644891773). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:33:09Z. **Review:** APPROVED --- Reviewed exact head `d34554e71cdbc483cb8d5e561a1b815b80fba76a`. The three byte patterns and masked syscall-number immediate offsets align with their fixtures (`mount` 13..16, `nmount` 15..18, `unmount` 13..16); matching still requires the complete pattern and a decoded instruction boundary. The change only turns the recognized unimplemented wrappers into the existing `UD2` trap under the opt-in flag, and the usage/debt text states that execution remains unsupported. Local validation on this head: - Relinker-only Release configure and `relinker` build: passed. - Built `sdk_mman_syscall_tests` and `syscall_scanner_tests`; CTest `sdk_mman_syscall`, `guest_syscall_trap`, `syscall_number`, and `syscall_scanner`: 4/4 passed. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check upstream/main...HEAD`: passed. - A merge-tree comparison with the current #9549 head is clean; I found no merge-order dependency in that comparison. GitHub conventions, intake and labels pass; no hosted build job is listed. The PR reports additional payload conversion runs; I did not rerun those external payload sweeps. No blocking issue found in this change.
klosixgaming-arch commented 2026-10-25 21:45:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-25T21:45:54Z.

Review: COMMENTED


Reviewed head d34554e71c by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine.

What it does. --trap-sdk-syscall-stubs learns the three inlined __syscall6 wrappers from the SDK's libc/mount.c (mount, nmount, unmount), replacing them with UD2 like the existing mman patterns. The conversion results in the description are the strongest part: 22 of 22 real payload assets convert, and 10 of 22 convert when only mount is recognised.

My main concern is the mask. Each pattern masks the four-byte syscall-number immediate (maskOffset, maskLength), so the stub matches whatever number it carries. The justification is that an SDK build that renumbers a call should still match. But the mmap and mprotect patterns bake their numbers in, and the three known numbers are right there in the fixtures (0x15, 0x17a, 0x16). With the number masked, any inlined __syscall6 stub with the same prologue and register setup is trapped, including a different syscall that happens to have the same argument shape. That is opt-in (--trap-sdk-syscall-stubs) and it traps rather than runs, so the damage is limited, but the match is wider than the debt entry's wording suggests. Either pin the numbers or say in the entry that the number is deliberately not matched, and why a renumbering is expected.

Test gaps:

  1. The "different number still matches" check sets the first masked byte to 0x16 and zeroes the rest. For the unmount fixture, whose number already is 0x16, that produces the identical bytes, so for that fixture the check cannot fail.
  2. The checks show 3 successful jobs and an UNSTABLE merge state, so CI had not finished when I looked. Please let it complete.

The overlap note about #9549 editing the same condition is already acknowledged in the PR. Leaving a comment rather than approving because of the widened match and the incomplete CI.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645480471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11137#pullrequestreview-5645480471). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-25T21:45:54Z. **Review:** COMMENTED --- Reviewed head `d34554e71c` by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine. **What it does.** `--trap-sdk-syscall-stubs` learns the three inlined `__syscall6` wrappers from the SDK's `libc/mount.c` (`mount`, `nmount`, `unmount`), replacing them with `UD2` like the existing mman patterns. The conversion results in the description are the strongest part: 22 of 22 real payload assets convert, and 10 of 22 convert when only `mount` is recognised. **My main concern is the mask.** Each pattern masks the four-byte syscall-number immediate (`maskOffset`, `maskLength`), so the stub matches whatever number it carries. The justification is that an SDK build that renumbers a call should still match. But the mmap and mprotect patterns bake their numbers in, and the three known numbers are right there in the fixtures (0x15, 0x17a, 0x16). With the number masked, any inlined `__syscall6` stub with the same prologue and register setup is trapped, including a different syscall that happens to have the same argument shape. That is opt-in (`--trap-sdk-syscall-stubs`) and it traps rather than runs, so the damage is limited, but the match is wider than the debt entry's wording suggests. Either pin the numbers or say in the entry that the number is deliberately not matched, and why a renumbering is expected. **Test gaps:** 1. The "different number still matches" check sets the first masked byte to `0x16` and zeroes the rest. For the `unmount` fixture, whose number already is `0x16`, that produces the identical bytes, so for that fixture the check cannot fail. 2. The checks show 3 successful jobs and an `UNSTABLE` merge state, so CI had not finished when I looked. Please let it complete. The overlap note about #9549 editing the same condition is already acknowledged in the PR. Leaving a comment rather than approving because of the widened match and the incomplete CI. AI-assisted: yes. Written with AI assistance and reviewed by me.
klosixgaming-arch commented 2026-10-26 07:21:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-26T07:21:18Z.

Review: APPROVED


Re-reviewed head 60cd4d2fb4 by reading the diff since my first review. I did not build or run it.

Both of my points are addressed. The mask is gone: MatchesSdkInlineStub is back to an exact std::equal, and the mount, nmount and unmount patterns carry 0x15, 0x17A and 0x16, like the mman ones. The fixture check now rewrites each stub's four-byte number to 0, 1, 0x15, 0x16 and 0x17A and requires every value other than its own to be rejected, so it can fail for unmount now. Approving. I have not looked at CI, so please let it finish.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648623649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11137#pullrequestreview-5648623649). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-26T07:21:18Z. **Review:** APPROVED --- Re-reviewed head `60cd4d2fb4` by reading the diff since my first review. I did not build or run it. Both of my points are addressed. The mask is gone: `MatchesSdkInlineStub` is back to an exact `std::equal`, and the `mount`, `nmount` and `unmount` patterns carry 0x15, 0x17A and 0x16, like the mman ones. The fixture check now rewrites each stub's four-byte number to 0, 1, 0x15, 0x16 and 0x17A and requires every value other than its own to be rejected, so it can fail for `unmount` now. Approving. I have not looked at CI, so please let it finish. AI-assisted: yes. Written with AI assistance and reviewed by me.
MarcZX10 commented 2026-10-29 23:27:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T23:27:44Z.

Review: APPROVED


Re-checked — new head, looks good

The rebased scanner recognizes the three exact SDK inline syscall wrappers while retaining full-pattern and instruction-boundary matching; I found no blocking issue in the new head.

What I ran

Reviewed head fcf6fffda81e2dc77f107d5f3bfea714630379d2 against refreshed main f46f453a56f91d77e29ce0cbd7fe5bfb2fb69834; the merge preview is clean. Environment: Linux x86_64. No local build or CTest run.

gh pr checks 11137 --repo boykopovar/AnyPS5
git diff --check upstream/main...refs/review/pr-11137-current
git merge-tree --write-tree upstream/main refs/review/pr-11137-current
python3 tools/check_conventions.py --base upstream/main

Results

Check Result
Diff whitespace Pass; exit 0, no output.
Merge preview against refreshed main Clean.
Conventions Pass.
Hosted checks Conventions and labels pass. The product build workflow is gated with action_required; it did not run.
Relinker tests The author reports 4/4 focused CTests and conversion of 22/22 payload assets on this head; I did not independently run them.
Unedited output from checks I ran
$ gh pr checks 11137 --repo boykopovar/AnyPS5
conventions	pass	17s	https://github.com/boykopovar/AnyPS5/actions/runs/40971642299/job/123789572950
labels	pass	5s	https://github.com/boykopovar/AnyPS5/actions/runs/40971642211/job/123789572842
$ git diff --check upstream/main...refs/review/pr-11137-current
(exit 0; no output)
$ git merge-tree --write-tree upstream/main refs/review/pr-11137-current
2416e315d65d8d0064394c1bbc84f3ba95473eb9
$ python3 tools/check_conventions.py --base upstream/main
All conventions checks passed.
$ gh run view 40971646807 --repo boykopovar/AnyPS5 --json status,conclusion,headSha,jobs
{"conclusion":"action_required","headSha":"fcf6fffda81e2dc77f107d5f3bfea714630379d2","status":"completed"}

Negative control

Assertion Change made to code under test Did the test fail?
A wrapper with a syscall number different from its pinned number is rejected The author reports mutating each fixture’s syscall-number bytes to alternate values. Yes, according to the PR’s reported 4/4 focused test run; not independently reproduced here.

Findings

Blocking

None found in the reviewed diff.

Non-blocking

The product build workflow is gated, and I did not execute the relinker tests locally. The PR reports those tests and payload conversions on this exact head.

Sources

Not verified

I did not build or run CTest locally, execute converted payloads, or verify syscall behavior on console hardware. Windows and macOS builds were not run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5706267795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11137#pullrequestreview-5706267795). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T23:27:44Z. **Review:** APPROVED --- # Re-checked — new head, looks good The rebased scanner recognizes the three exact SDK inline syscall wrappers while retaining full-pattern and instruction-boundary matching; I found no blocking issue in the new head. ## What I ran Reviewed head `fcf6fffda81e2dc77f107d5f3bfea714630379d2` against refreshed `main` `f46f453a56f91d77e29ce0cbd7fe5bfb2fb69834`; the merge preview is clean. Environment: Linux x86_64. No local build or CTest run. ```sh gh pr checks 11137 --repo boykopovar/AnyPS5 git diff --check upstream/main...refs/review/pr-11137-current git merge-tree --write-tree upstream/main refs/review/pr-11137-current python3 tools/check_conventions.py --base upstream/main ``` ## Results | Check | Result | |---|---| | Diff whitespace | Pass; exit 0, no output. | | Merge preview against refreshed `main` | Clean. | | Conventions | Pass. | | Hosted checks | Conventions and labels pass. The product build workflow is gated with `action_required`; it did not run. | | Relinker tests | The author reports 4/4 focused CTests and conversion of 22/22 payload assets on this head; I did not independently run them. | <details> <summary>Unedited output from checks I ran</summary> ```text $ gh pr checks 11137 --repo boykopovar/AnyPS5 conventions pass 17s https://github.com/boykopovar/AnyPS5/actions/runs/40971642299/job/123789572950 labels pass 5s https://github.com/boykopovar/AnyPS5/actions/runs/40971642211/job/123789572842 $ git diff --check upstream/main...refs/review/pr-11137-current (exit 0; no output) $ git merge-tree --write-tree upstream/main refs/review/pr-11137-current 2416e315d65d8d0064394c1bbc84f3ba95473eb9 $ python3 tools/check_conventions.py --base upstream/main All conventions checks passed. $ gh run view 40971646807 --repo boykopovar/AnyPS5 --json status,conclusion,headSha,jobs {"conclusion":"action_required","headSha":"fcf6fffda81e2dc77f107d5f3bfea714630379d2","status":"completed"} ``` </details> ## Negative control | Assertion | Change made to code under test | Did the test fail? | |---|---|---| | A wrapper with a syscall number different from its pinned number is rejected | The author reports mutating each fixture’s syscall-number bytes to alternate values. | Yes, according to the PR’s reported 4/4 focused test run; not independently reproduced here. | ## Findings ### Blocking None found in the reviewed diff. ### Non-blocking The product build workflow is gated, and I did not execute the relinker tests locally. The PR reports those tests and payload conversions on this exact head. ## Sources - [Scanner patterns and matching logic at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/fcf6fffda81e2dc77f107d5f3bfea714630379d2/core/relinker/relinker/src/analysis/SyscallScanner.cpp) - [Focused fixture and mutation tests at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/fcf6fffda81e2dc77f107d5f3bfea714630379d2/core/relinker/relinker/tests/SdkMmanSyscallTests.cpp) ## Not verified I did not build or run CTest locally, execute converted payloads, or verify syscall behavior on console hardware. Windows and macOS builds were not run.
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!11137
No description provided.