feat(libkernel): implement setresuid and setresgid #9218

Merged
slopgobblercobbler merged 1 commit from upstream-pr/9218 into main 2026-10-22 22:10:13 +00:00
slopgobblercobbler commented 2026-10-21 15:28:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-21T15:28:58Z.


What

Implement setresuid_nid_postfix and setresgid_nid_postfix (FreeBSD syscalls 311 and 312) in core/libs/prx/libkernel/System/src/Process.cpp, test them in GuestCredentials.cpp, and update docs/dev/debt/libkernel.md.

Why

FreeBSD 11.4 provides setresuid and setresgid (sys/kern/kern_prot.c) to set the real, effective, and saved user and group IDs of the process.
AnyPS5 models a guest environment running as root with real, effective, and saved IDs set to 0.

  • Setting an ID to 0 or -1 (0xffffffffu, unchanged) is accepted without modifying credentials and returns 0.
  • Setting any other ID would change credentials (which is not modelled) and throws std::runtime_error.
  • Retains FreeBSD semantics where success returns 0 with errno left untouched.

Tested

Windows 11 x64:

  • Extended core/libs/tests/GuestCredentials.cpp with unit test coverage:
    • Valid invocations setting IDs to 0 and/or unchanged (0xffffffffu) returning 0.
    • Verification that errno is untouched on success.
    • Invalid ID attempts throwing std::runtime_error for real, effective, and saved IDs across both user and group variants.
    • Local unit test compilation and execution passing with exit code 0 (100% pass rate).
  • Passed python tools/check_conventions.py --base upstream/main --head HEAD.
  • Passed python tools/check_main_sync.py: HEAD is 1 ahead and 0 behind upstream/main, clean merge.

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4954098007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9218). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-21T15:28:58Z. --- ### What Implement `setresuid_nid_postfix` and `setresgid_nid_postfix` (FreeBSD syscalls 311 and 312) in `core/libs/prx/libkernel/System/src/Process.cpp`, test them in `GuestCredentials.cpp`, and update `docs/dev/debt/libkernel.md`. ### Why FreeBSD 11.4 provides `setresuid` and `setresgid` (`sys/kern/kern_prot.c`) to set the real, effective, and saved user and group IDs of the process. AnyPS5 models a guest environment running as root with real, effective, and saved IDs set to 0. - Setting an ID to 0 or -1 (`0xffffffffu`, unchanged) is accepted without modifying credentials and returns 0. - Setting any other ID would change credentials (which is not modelled) and throws `std::runtime_error`. - Retains FreeBSD semantics where success returns 0 with `errno` left untouched. ### Tested Windows 11 x64: - Extended `core/libs/tests/GuestCredentials.cpp` with unit test coverage: - Valid invocations setting IDs to 0 and/or unchanged (`0xffffffffu`) returning 0. - Verification that `errno` is untouched on success. - Invalid ID attempts throwing `std::runtime_error` for real, effective, and saved IDs across both user and group variants. - Local unit test compilation and execution passing with exit code 0 (100% pass rate). - Passed `python tools/check_conventions.py --base upstream/main --head HEAD`. - Passed `python tools/check_main_sync.py`: HEAD is 1 ahead and 0 behind upstream/main, clean merge. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 15:29:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T15:29:37Z.


Progress report (cecb540 → d28c74a)

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

✅ 2 implemented
Library Name
libkernel setresgid_nid_postfix
libkernel setresuid_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6319766157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9218#issuecomment-6319766157). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T15:29:37Z. --- <!-- progress-report --> ### Progress report (cecb540 → d28c74a) 📈 **System libraries**: 42.11% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `setresgid_nid_postfix` | | libkernel | `setresuid_nid_postfix` | </details>
harisibrar1 commented 2026-10-22 04:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T04:12:35Z.

Review: COMMENTED


Checked against main 6ef5a1c4c and FreeBSD 11.4 sys_setresuid/sys_setresgid (sys/kern/kern_prot.c):

  • The behaviour is consistent with main's credential model. getuid and its siblings report 0, and setreuid/setregid already accept 0 or -1 and throw otherwise. For a root caller, FreeBSD treats -1 as unchanged and 0 as a no-op, so returning 0 there is correct, and throwing for any other id avoids faking a credential change.
  • Blocking question: is either function actually exported on the PS5? Neither the PS5 SDK stubs (sce_stubs/libkernel.c, libkernel_sys.c, libkernel_web.c at a7685ce8) nor the PS5-3.20 libkernel.c/libkernel_sys.c tables list setresuid or setresgid, while all of them list setreuid and setregid. Main has no discovery stub for them either. As written, Process.cpp:773 and :784 add libkernel.prx NIDs that no title or SDK binary can import.
  • Could you cite a title import or firmware NID dump that has these exports, and name the library? If there isn't one, I think this PR should be dropped rather than add exports the console does not have.
  • Builds on Windows (WinLibs GCC 15.2.0 r7, full BUILD_TESTING=ON build) merged onto main 6ef5a1c4c; the only failing step is the existing ImageArrayWindowPastLayerLimit.cpp alignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609169155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9218#pullrequestreview-5609169155). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T04:12:35Z. **Review:** COMMENTED --- Checked against main 6ef5a1c4c and FreeBSD 11.4 `sys_setresuid`/`sys_setresgid` (sys/kern/kern_prot.c): - The behaviour is consistent with main's credential model. getuid and its siblings report 0, and setreuid/setregid already accept 0 or -1 and throw otherwise. For a root caller, FreeBSD treats -1 as unchanged and 0 as a no-op, so returning 0 there is correct, and throwing for any other id avoids faking a credential change. - Blocking question: is either function actually exported on the PS5? Neither the PS5 SDK stubs (`sce_stubs/libkernel.c`, `libkernel_sys.c`, `libkernel_web.c` at a7685ce8) nor the PS5-3.20 `libkernel.c`/`libkernel_sys.c` tables list `setresuid` or `setresgid`, while all of them list `setreuid` and `setregid`. Main has no discovery stub for them either. As written, `Process.cpp:773` and `:784` add libkernel.prx NIDs that no title or SDK binary can import. - Could you cite a title import or firmware NID dump that has these exports, and name the library? If there isn't one, I think this PR should be dropped rather than add exports the console does not have. - Builds on Windows (WinLibs GCC 15.2.0 r7, full `BUILD_TESTING=ON` build) merged onto main 6ef5a1c4c; the only failing step is the existing `ImageArrayWindowPastLayerLimit.cpp` alignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9218
No description provided.