fix(libkernel): check getrlimit output pointers #8986

Merged
MarcZX10 merged 7 commits from upstream-pr/8986 into main 2026-10-23 02:46:52 +00:00
MarcZX10 commented 2026-10-21 08:40:33 +00:00 (Migrated from github.com)

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


What

Check the guest output pointer in getrlimit before writing through it. Results are built in local storage and copied to guest memory with the checked guest write helper, returning -1 with guest EFAULT for inaccessible addresses instead of faulting the emulator. Resource validation still precedes pointer validation, preserving the existing EINVAL versus EFAULT precedence.

Regression coverage checks inaccessible output addresses for both a host-derived resource limit and the emulator-stored RLIMIT_NOFILE value.

Tested

  • Linux GCC 12.2: cmake --build build --target guest_getrlimit_tests guest_setrlimit_tests -j2 passed.
  • git diff --check passed.
  • ctest --test-dir build --output-on-failure -R '^guest_(getrlimit|setrlimit)$' could not reach assertions: both executables abort at AnyPS5's host CPU compatibility gate because this Xeon E5-1620 v2 lacks BMI1/BMI2, LZCNT, MOVBE, AVX2 and FMA.
  • The repository convention checker was attempted twice but its duplicate-export scan stalled in git grep; it was interrupted. The changed exports are existing functions, and the focused build passed.
  • tools/pr_overlap.py found shared-file warnings for #8537 and macOS ports #8658/#7201. I reviewed those PRs: #8537 changes setrlimit semantics and must precede this follow-up; the macOS PRs are platform-port changes, not duplicate getrlimit pointer handling.

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; no new silent stubs
  • No notes or images added to repository
  • No third-party code added
  • Generic behavior, not title-specific
  • Depends on: #8985 and #8537
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4948817392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8986). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T08:40:33Z. --- ### What Check the guest output pointer in `getrlimit` before writing through it. Results are built in local storage and copied to guest memory with the checked guest write helper, returning `-1` with guest `EFAULT` for inaccessible addresses instead of faulting the emulator. Resource validation still precedes pointer validation, preserving the existing `EINVAL` versus `EFAULT` precedence. Regression coverage checks inaccessible output addresses for both a host-derived resource limit and the emulator-stored `RLIMIT_NOFILE` value. ### Tested - Linux GCC 12.2: `cmake --build build --target guest_getrlimit_tests guest_setrlimit_tests -j2` passed. - `git diff --check` passed. - `ctest --test-dir build --output-on-failure -R '^guest_(getrlimit|setrlimit)$'` could not reach assertions: both executables abort at AnyPS5's host CPU compatibility gate because this Xeon E5-1620 v2 lacks BMI1/BMI2, LZCNT, MOVBE, AVX2 and FMA. - The repository convention checker was attempted twice but its duplicate-export scan stalled in `git grep`; it was interrupted. The changed exports are existing functions, and the focused build passed. - `tools/pr_overlap.py` found shared-file warnings for #8537 and macOS ports #8658/#7201. I reviewed those PRs: #8537 changes `setrlimit` semantics and must precede this follow-up; the macOS PRs are platform-port changes, not duplicate `getrlimit` pointer handling. ### 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 - [x] Unimplemented paths throw; no new silent stubs - [x] No notes or images added to repository - [x] No third-party code added - [x] Generic behavior, not title-specific - [x] Depends on: #8985 and #8537 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 08:41:18 +00:00 (Migrated from github.com)

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


Progress report (27c88a8 → 29d50d1)

📈 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:6311798264 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8986#issuecomment-6311798264). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T08:41:18Z. --- <!-- progress-report --> ### Progress report (27c88a8 → 29d50d1) 📈 **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>
xXPBSXx commented 2026-10-21 09:45:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T09:45:49Z.


Windows data point for 29d50d189 merged onto main 27c88a8d7 (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^guest_getrlimit$' lists exactly that one test; ctest --no-tests=error -R '^guest_getrlimit$' was run three times per tree.

  • With the PR: passes 3 of 3 (0.6-2.1 s).
  • Same tree with core/libs/prx/libkernel/System/src/Process.cpp restored to main (the new test cases kept): fails 3 of 3 with a segmentation fault (ctest reports SEGFAULT).
    Not tested: other platforms, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312971384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8986#issuecomment-6312971384). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T09:45:49Z. --- Windows data point for `29d50d189` merged onto `main` `27c88a8d7` (clean, `git merge-tree` rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. `ctest -N -R '^guest_getrlimit$'` lists exactly that one test; `ctest --no-tests=error -R '^guest_getrlimit$'` was run three times per tree. - With the PR: passes 3 of 3 (0.6-2.1 s). - Same tree with `core/libs/prx/libkernel/System/src/Process.cpp` restored to `main` (the new test cases kept): fails 3 of 3 with a segmentation fault (ctest reports `SEGFAULT`). Not tested: other platforms, a title run. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-21 10:13:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T10:13:46Z.


Linux data point for 29d50d189e (the Windows run is in the comment above): WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; merge-base f894ba69d).

  • With the PR: ctest -R '^(guest_getrlimit|guest_credentials)$' passes 3 of 3 runs (both tests).
  • With core/libs/prx/libkernel/System/src/Process.cpp restored to the merge-base (new tests kept): guest_getrlimit fails (SegFault); guest_credentials does not link (undefined reference to getresuid_nid_postfix).
    Not tested: macOS, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313498551 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8986#issuecomment-6313498551). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T10:13:46Z. --- Linux data point for `29d50d189e` (the Windows run is in the comment above): WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; merge-base `f894ba69d`). - With the PR: `ctest -R '^(guest_getrlimit|guest_credentials)$'` passes 3 of 3 runs (both tests). - With `core/libs/prx/libkernel/System/src/Process.cpp` restored to the merge-base (new tests kept): `guest_getrlimit` fails (SegFault); `guest_credentials` does not link (`undefined reference to getresuid_nid_postfix`). Not tested: macOS, a title run. AI-assisted (Claude Code).
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!8986
No description provided.