fix(libkernel): return EFAULT for invalid group pointers #8985

Merged
MarcZX10 merged 6 commits from upstream-pr/8985 into main 2026-10-23 01:05:40 +00:00
MarcZX10 commented 2026-10-21 08:32:55 +00:00 (Migrated from github.com)

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


What

Handle guest pointer failures in setgroups and getgroups without dereferencing guest addresses in the host process. setgroups now copies the requested IDs through checked guest-memory access before updating the stored list; getgroups copies the list out through checked guest-memory access. Invalid guest memory returns -1 with guest EFAULT.

Adds regression cases for invalid input and output pointers to GuestCredentials.cpp.

Why

These credential calls currently read or write caller-provided pointers directly. An unmapped address can terminate the emulator instead of returning the guest error.

Tested

  • cmake --build build --target guest_credentials_tests -j2 passed on Linux (GCC 12.2).
  • python3 tools/check_conventions.py --base upstream/main --head HEAD passed.
  • git diff --check upstream/main...HEAD passed.
  • The focused ctest executable was built but could not reach its assertions on this host: the existing libkernel startup CPU check rejects this Xeon because it lacks PS5-required BMI1/BMI2, LZCNT, MOVBE, AVX2, and FMA.

Checklist

  • Based on current main; distinct from other group credential work
  • One topic per PR; follow-ups go in a new pull request
  • No comments in code except technical debt
  • Generic behavior, not specific to one title
  • Depends on: #8977 (which depends on #8894)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

This branch is stacked on #8977 so it can share the checked guest-memory platform imports. The #8977 and #8894 commits in its history retain their original authors. The overlap checker also reports #8658 and #7201 because they edit Process.cpp for separate macOS process argument and resource-usage support; those changes are unrelated, but merging any of those branches will require coordinating a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4948728743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8985). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T08:32:55Z. --- ### What Handle guest pointer failures in `setgroups` and `getgroups` without dereferencing guest addresses in the host process. `setgroups` now copies the requested IDs through checked guest-memory access before updating the stored list; `getgroups` copies the list out through checked guest-memory access. Invalid guest memory returns `-1` with guest `EFAULT`. Adds regression cases for invalid input and output pointers to `GuestCredentials.cpp`. ### Why These credential calls currently read or write caller-provided pointers directly. An unmapped address can terminate the emulator instead of returning the guest error. ### Tested - `cmake --build build --target guest_credentials_tests -j2` passed on Linux (GCC 12.2). - `python3 tools/check_conventions.py --base upstream/main --head HEAD` passed. - `git diff --check upstream/main...HEAD` passed. - The focused `ctest` executable was built but could not reach its assertions on this host: the existing libkernel startup CPU check rejects this Xeon because it lacks PS5-required BMI1/BMI2, LZCNT, MOVBE, AVX2, and FMA. ### Checklist - [x] Based on current `main`; distinct from other group credential work - [x] One topic per PR; follow-ups go in a new pull request - [x] No comments in code except technical debt - [x] Generic behavior, not specific to one title - [x] Depends on: #8977 (which depends on #8894) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes This branch is stacked on #8977 so it can share the checked guest-memory platform imports. The #8977 and #8894 commits in its history retain their original authors. The overlap checker also reports #8658 and #7201 because they edit `Process.cpp` for separate macOS process argument and resource-usage support; those changes are unrelated, but merging any of those branches will require coordinating a rebase.
github-actions[bot] commented 2026-10-21 08:33:43 +00:00 (Migrated from github.com)

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


Progress report (27c88a8 → 67db9d3)

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

✅ 2 implemented
Library Name
libkernel getresgid_nid_postfix
libkernel getresuid_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311664807 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8985#issuecomment-6311664807). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T08:33:43Z. --- <!-- progress-report --> ### Progress report (27c88a8 → 67db9d3) 📈 **System libraries**: 51.03% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `getresgid_nid_postfix` | | libkernel | `getresuid_nid_postfix` | </details>
clairtonmichel commented 2026-10-21 08:52:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-21T08:52:30Z.


Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):

  • Built cleanly with zero errors.
  • Named SHM test suite (guest_named_shm_lifecycle, descriptor_reuse, permissions, io_descriptor_reuse, etc.) passed successfully (9/10 green).
  • Edge case caught: guest_named_shm_concurrency failed because unlink of a read-only shared object did not return EACCES as expected. Permission enforcement on unlinking read-only shm needs a quick check by the author.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311996725 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8985#issuecomment-6311996725). Originally posted by [clairtonmichel](https://github.com/clairtonmichel) on 2026-10-21T08:52:30Z. --- Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5): - Built cleanly with zero errors. - Named SHM test suite (`guest_named_shm_lifecycle`, `descriptor_reuse`, `permissions`, `io_descriptor_reuse`, etc.) passed successfully (9/10 green). - Edge case caught: `guest_named_shm_concurrency` failed because `unlink` of a read-only shared object did not return `EACCES` as expected. Permission enforcement on unlinking read-only shm needs a quick check by the author.
ycbuzi commented 2026-10-21 13:05:44 +00:00 (Migrated from github.com)

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


Windows run of 67db9d371f merged onto main 27c88a8d75 (3e8551ea12, clean), on a CPU the start-up check accepts, so guest_credentials reaches its assertions. 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. The head carries #8977's commits; the negative control for those is on #8977. Not run: a negative control for 91b2911ca1 alone (reverting it, or picking the test commit onto #8977 without it, conflicts), Linux, a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6316791868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8985#issuecomment-6316791868). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T13:05:44Z. --- Windows run of 67db9d371f merged onto `main` 27c88a8d75 (3e8551ea12, clean), on a CPU the start-up check accepts, so `guest_credentials` reaches its assertions. 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. The head carries #8977's commits; the negative control for those is on #8977. Not run: a negative control for 91b2911ca1 alone (reverting it, or picking the test commit onto #8977 without it, conflicts), 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!8985
No description provided.