Skip to content

feat(libkernel): implement setresuid and setresgid - #9218

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
slopgobblercobbler:feat/libkernel-setresuid-setresgid
Oct 22, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
slopgobblercobbler:feat/libkernel-setresuid-setresgid

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

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

Follow FreeBSD 11.4 sys_setresuid and sys_setresgid (sys/kern/kern_prot.c):
accept real, effective, and saved user and group IDs for the guest process,
which is assumed to run as root with IDs 0. Setting an ID to 0 or -1 (unchanged)
is accepted without changing credentials and returns 0; any other value throws.
Cover both in guest_credentials test and update libkernel debt documentation.
@github-actions

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestCredentials.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/System/src/Process.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8344 docs/dev/debt/libkernel.md
PR 8373 docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
PR 8921 docs/dev/debt/libkernel.md
PR 9060 docs/dev/debt/libkernel.md
PR 9109 docs/dev/debt/libkernel.md
PR 9133 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 9561 docs/dev/debt/libkernel.md
PR 9573 docs/dev/debt/libkernel.md
PR 9669 core/libs/prx/libkernel/System/src/Process.cpp
docs/dev/debt/libkernel.md
PR 9693 docs/dev/debt/libkernel.md

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 6ef5a1c 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 6ef5a1c; 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.

@oneandonlydean oneandonlydean self-assigned this Oct 22, 2026
@oneandonlydean
oneandonlydean merged commit 8964c12 into boykopovar:main Oct 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants