fix(libkernel): return EFAULT for invalid getresid pointers #8977

Merged
MarcZX10 merged 4 commits from upstream-pr/8977 into main 2026-10-23 01:05:42 +00:00
MarcZX10 commented 2026-10-21 08:12:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T08:12:46Z.


What

Validate each non-null getresuid and getresgid output pointer before writing the modeled root ID. Invalid or unwritable guest pointers now return -1 with guest EFAULT instead of crashing the host process.

Adds regression cases for invalid pointers to core/libs/tests/GuestCredentials.cpp.

Why

PR #8894 adds these calls and currently writes through raw pointers. Since guest memory can contain invalid addresses, these writes need the same guest-address validation and protected host-write path used elsewhere.

Tested

  • Passed GCC 12.2 syntax-only compilation of Process.cpp and GuestCredentials.cpp on Linux.
  • Passed python3 tools/check_conventions.py --base upstream/main.
  • Passed git diff --check upstream/main...HEAD.
  • Full CMake configuration and executable test were blocked locally because SDL2's CMake package (SDL2Config.cmake) is unavailable in this environment.

Checklist

  • Based on current main, with #8894 included as a dependency
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Generic behavior, not specific to one title
  • Depends on: #8894
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4948492701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8977). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T08:12:46Z. --- ### What Validate each non-null `getresuid` and `getresgid` output pointer before writing the modeled root ID. Invalid or unwritable guest pointers now return `-1` with guest `EFAULT` instead of crashing the host process. Adds regression cases for invalid pointers to `core/libs/tests/GuestCredentials.cpp`. ### Why PR #8894 adds these calls and currently writes through raw pointers. Since guest memory can contain invalid addresses, these writes need the same guest-address validation and protected host-write path used elsewhere. ### Tested - Passed GCC 12.2 syntax-only compilation of `Process.cpp` and `GuestCredentials.cpp` on Linux. - Passed `python3 tools/check_conventions.py --base upstream/main`. - Passed `git diff --check upstream/main...HEAD`. - Full CMake configuration and executable test were blocked locally because SDL2's CMake package (`SDL2Config.cmake`) is unavailable in this environment. ### Checklist - [x] Based on current `main`, with #8894 included as a dependency - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Generic behavior, not specific to one title - [x] Depends on: #8894 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 08:13:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T08:13:35Z.


Progress report (f894ba6 → 30167da)

📈 System libraries: 50.59% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel getresgid_nid_postfix
libkernel getresuid_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311305449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8977#issuecomment-6311305449). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T08:13:35Z. --- <!-- progress-report --> ### Progress report (f894ba6 → 30167da) 📈 **System libraries**: 50.59% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `getresgid_nid_postfix` | | libkernel | `getresuid_nid_postfix` | </details>
ycbuzi commented 2026-10-21 13:05:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T13:05:42Z.


Windows run of 30167dace1 merged onto main 27c88a8d75 (fbfbe1cbc8, clean), the executable test the description lists as blocked. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON, Ryzen 9 7900.

Built libkernel and guest_credentials_tests with no errors or warnings; ctest --repeat until-fail:3 on guest_credentials: passes all three repeats.

Negative control on the same merge: with afc7e26ce9 (the Process.cpp change) reverted and the test commit kept, guest_credentials fails with SegFault, FATAL: unhandled exception 0xc0000005. So the new invalid-pointer cases fail without the fix and pass with it. Not run: Linux, a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316790956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8977#issuecomment-6316790956). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T13:05:42Z. --- Windows run of 30167dace1 merged onto `main` 27c88a8d75 (fbfbe1cbc8, clean), the executable test the description lists as blocked. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`, Ryzen 9 7900. Built `libkernel` and `guest_credentials_tests` with no errors or warnings; `ctest --repeat until-fail:3` on `guest_credentials`: passes all three repeats. Negative control on the same merge: with afc7e26ce9 (the `Process.cpp` change) reverted and the test commit kept, `guest_credentials` fails with `SegFault`, `FATAL: unhandled exception 0xc0000005`. So the new invalid-pointer cases fail without the fix and pass with it. Not run: Linux, a title.
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!8977
No description provided.