Skip to content

fix(libSceUserService): refuse sceUserServiceGetNpAccountId before initialization - #23549

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Vasanthdev2004:fix/userservice-np-account-not-initialized
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Vasanthdev2004:fix/userservice-np-account-not-initialized

Conversation

@Vasanthdev2004

Copy link
Copy Markdown
Contributor

What

sceUserServiceGetNpAccountId now returns USER_SERVICE_ERROR_NOT_INITIALIZED (0x80960002) before its null-output and login checks, following the order of firmware 13.42's handler (0x3e10): the module checks its IPMI client variable first and answers 0x80960002 while it is not initialized, then 0x80960005 for a null output, before it looks at the user (disassembly and a native run of the module with stubbed imports, not measured on a console; the PS4 Pro 10.71 run in the same thread also answered 0x80960002 after sceUserServiceTerminate). sceUserServiceInitialize and sceUserServiceTerminate already maintain the initialized state, so the gate is one check at the top of the export. The debt entry is updated by fragment to record that both module gates are modelled. sce::np::User's account lookups in libSceNpManager call this export and now answer USER_SERVICE_ERROR_NOT_INITIALIZED in a process that never initialized the user service; CheckValueClasses initializes it, as a title does, so the logged-in and missing-account answers stay covered, and the other guest tests cover the not-initialized answers, including the untouched output.

Shared files with open PRs, none implementing this export: #12860 and #12900 also add pre-initialization assertions and an sceUserServiceInitialize call at the top of GuestUserService.cpp's main for GetForegroundUser, GetUserName and GetInitialUser; #9345, #9828 and #14829 touch other libSceUserService exports. Whichever of #12860 or #12900 merges first, the rebase folds their and this branch's pre-initialization assertions into one block with a single sceUserServiceInitialize call; the debt entries are distinct, so the fragments do not collide.

Tested

Windows 11, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh r7), Ninja, Release, BUILD_TESTING=ON. All 15 focused ctests pass: guest_user_service, guest_user_service_group_io, guest_user_service_user_name, guest_user_service_user_kind, guest_user_service_shell_core, guest_user_service_lifecycle, guest_user_service_kratos, guest_user_service_profiles_bounds, guest_user_service_multi_login_event_bounds, guest_user_service_login_list, guest_user_service_account_name_limits, guest_user_service_age_level_guest_bounds, guest_np_manager, guest_np_reachability, guest_np_asm_client_ext. python tools/debt_fold.py --check and python tools/check_conventions.py --base origin/main pass with no findings. Not tested on a PS5.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (attach them to this PR)
  • 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

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 719cdb5505:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_np_manager_tests, guest_user_service_account_name_limits_tests, guest_user_service_age_level_guest_bounds_tests, guest_user_service_kratos_tests, guest_user_service_profiles_bounds_tests, guest_user_service_tests built cleanly.
  • CTest (guest_np_manager, guest_user_service, guest_user_service_kratos, guest_user_service_profiles_bounds, guest_user_service_account_name_limits, guest_user_service_age_level_guest_bounds):
    1/6 Test #4860: guest_np_manager ............................   Passed    0.01 sec
    2/6 Test #5196: guest_user_service ..........................   Passed    0.01 sec
    3/6 Test #5202: guest_user_service_profiles_bounds ..........   Passed    0.01 sec
    4/6 Test #5201: guest_user_service_kratos ...................   Passed    0.01 sec
    5/6 Test #5205: guest_user_service_account_name_limits ......   Passed    0.01 sec
    6/6 Test #5206: guest_user_service_age_level_guest_bounds ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 6
    
  • Negative control: with core/libs/prx/libSceUserService/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/6 Test #4860: guest_np_manager ............................   Passed    0.01 sec
    2/6 Test #5196: guest_user_service ..........................Subprocess aborted***Exception:   0.17 sec
    3/6 Test #5202: guest_user_service_profiles_bounds ..........Subprocess aborted***Exception:   0.19 sec
    4/6 Test #5201: guest_user_service_kratos ...................Subprocess aborted***Exception:   0.20 sec
    5/6 Test #5205: guest_user_service_account_name_limits ......Subprocess aborted***Exception:   0.22 sec
    6/6 Test #5206: guest_user_service_age_level_guest_bounds ...Subprocess aborted***Exception:   0.18 sec
    17% tests passed, 5 tests failed out of 6
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified Export.cpp:sceUserServiceGetNpAccountId checks initialized.load() before null check (account_id == nullptr) and user bounds, returning USER_SERVICE_ERROR_NOT_INITIALIZED (0x80960002) as verified against PS5 FW 13.42 module disassembly and PS4 Pro FW 10.71 console behavior.
    • Verified docs/dev/debt/changes/fix-userservice-np-account-not-initialized.md follows debt fragment specifications and properly documents the behavior change.
    • Verified CMakeLists.txt links libSceUserService to guest_np_manager_tests to satisfy the sceUserServiceInitialize dependency in CheckValueClasses.
    • Verified GuestUserService.cpp and other test suites (GuestUserServiceAccountNameLimits, GuestUserServiceAgeLevelGuestBounds, GuestUserServiceKratos, GuestUserServiceProfilesBounds) accurately verify the pre-initialization gate and untouched output buffer on error.

Looks Good To Me

@MarcZX10 MarcZX10 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.

Reviewed — comments

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 719cdb5505fe7a95ec1cab9c03dc85438fa52533 using repo_read.py to inspect the prepared diff and changed code ranges. No test or build commands were run; this environment provided reader-only access.

Results

Check Result Note
Changed code review passed All nine changed files’ relevant hunks were read
Focused tests and checks not run Author reports passing results; not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported Windows 11 focused ctests, debt check, and conventions check were not run during this review. No changed files were excluded by the manifest; the review folder’s files.json was unavailable through the reader.

To get this to a good state

Nothing is required. Optionally, run the reported focused ctests and checks on this head before relying on their results independently.

@Vasanthdev2004
Vasanthdev2004 force-pushed the fix/userservice-np-account-not-initialized branch from 719cdb5 to ce92d61 Compare November 20, 2026 08:00

@MarcZX10 MarcZX10 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.

Reviewed — no blocking findings

The initialization gate and its validation order match the PR description; I did not run the reported checks, and the review is incomplete because I did not read every changed file in full.

What I ran

Inspected the prepared diff and selected code at head ce92d6134f85c2eecf855c4f263db850b2a31437 using repo_read.py. No checks were run.

Results

Check Result Note
Diff and targeted code inspection passed Gate precedes output and user checks
Reported tests and conventions checks not run Reported by the author only
Full changed-file review not run Several changed files were only partly read

Findings

Blocking

None identified in the code inspected.

Non-blocking

None.

Not verified

The manifest lists 9 changed files, all included in the prepared folder. I read selected ranges from core/libs/prx/libSceUserService/Export.cpp, core/libs/tests/GuestUserService.cpp, core/libs/tests/GuestUserServiceProfilesBounds.cpp, core/libs/tests/GuestUserServiceAccountNameLimits.cpp, core/libs/tests/GuestNpManager.cpp, and core/libs/prx/libSceNpManager/CMakeLists.txt; these were not all read in full. I did not read core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp, core/libs/tests/GuestUserServiceKratos.cpp, or docs/dev/debt/changes/fix-userservice-np-account-not-initialized.md. No tests were run, and behavior on a PS5 was not verified. The author reports 15 focused ctests and two repository checks passed on Windows 11.

To get this to a good state

Nothing is required. Optional: complete the changed-file review and run the reported checks on this head before making a formal approval decision.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12860 core/libs/tests/GuestUserService.cpp L113-114
PR 12900 core/libs/tests/GuestUserService.cpp L113
PR 25454 core/libs/tests/GuestUserService.cpp L113-114
PR 25470 core/libs/tests/GuestUserService.cpp L113-114
core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp L156-159, L195
PR 25477 core/libs/tests/GuestUserService.cpp L113-114
core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp L156-159, L195
PR 25493 core/libs/tests/GuestUserService.cpp L113-114
core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp L156-159, L195
PR 25500 core/libs/tests/GuestUserService.cpp L113-114
core/libs/tests/GuestUserServiceAgeLevelGuestBounds.cpp L156-159, L195

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 9345 core/libs/prx/libSceUserService/Export.cpp
PR 9828 core/libs/prx/libSceUserService/Export.cpp
PR 14829 core/libs/prx/libSceUserService/Export.cpp
PR 18887 core/libs/tests/GuestUserServiceKratos.cpp

@Helldiverr

Copy link
Copy Markdown
Contributor

Windows run of ce92d61, merged onto main 2b0d3ee (merge 9d63f96929). The merge is clean and the merged Export.cpp, CMakeLists.txt and test files equal the PR head, so the line numbers below are from ce92d61 unless marked main.

Host: Ryzen 9 9950X3D, Windows 11 Pro 26300, WinLibs GCC 15.2, Ninja, Release. Tests: the 15 focused ctests from the PR description (guest_user_service* ×12, guest_np_manager, guest_np_reachability, guest_np_asm_client_ext).

Existing runs:

  • The author ran Windows at ce92d61 (the 15 ctests, pass), without a negative control.
  • PrivacyOnion ran Linux at 719cdb5, which has the same patch as ce92d61 before a rebase. That run's negative control was Export.cpp reverted to main; 5 of 6 tests failed.
  • MarcZX10 read the code at 719cdb5 and ce92d61, with no findings.

This run adds the Windows negative control, mutations, and a probe of the libSceNpManager callers before initialization.

Results

Run Result
main 15/15 pass
merge, 3 runs 15/15 pass each time
PR tests with main's Export.cpp 10/15 pass. guest_user_service, _kratos, _profiles_bounds, _account_name_limits and _age_level_guest_bounds abort (0xc0000409)
check_conventions.py --base upstream/main passes
debt_fold.py --check passes

This matches PrivacyOnion's Linux control.

Mutations (on the merge, one at a time)

# Change Result
m1 gate moved after the null-output check (Export.cpp 647-649 after 652) the same 5 suites abort
m2 gate moved after the logged-in check (after 655) the same 5 suites abort
m3 gate writes 0 to a non-null output before returning (648) the same 5 suites abort
m4 libSceUserService removed from guest_np_manager_tests (libSceNpManager CMakeLists.txt 29) link error, undefined reference to sceUserServiceInitialize
m5 sceUserServiceInitialize call removed from CheckValueClasses (GuestNpManager.cpp 918) guest_np_manager fails: "the initial user must be logged in"

The tests pin the order (gate, then null output, then user) and the untouched output. The CMake change and the new initialize call are both needed.

Probe: sce::np::User before the user service is initialized

sce::np::User::IsLoggedIn, GetAccountId, HasAccountId and GetAccountIdFromRegistory in libSceNpManager call this export (main ValueClasses.cpp 238-272). The PR's tests only reach them after CheckValueClasses initializes the user service (GuestNpManager.cpp 918). I called all four for the initial user before that line, once with main's Export.cpp and once on the merge:

Call main's Export.cpp merge
IsLoggedIn true false
GetAccountId 0x80559e2b (account id missing), output 0 0x80960002, output 0
HasAccountId 0, output false 0x80960002, output untouched
GetAccountIdFromRegistory 0, output 0 0x80960002, output untouched

So in a process that never initializes the user service, these NP value-class calls now fail with the user service's 0x80960002. The PR description says this is intended. Two notes:

  • No test pins these four answers before initialization.
  • GetAccountId writes 0 to its output before it calls the user service (main ValueClasses.cpp 251). So its output is 0 on this failure, while the other two leave theirs untouched. This was already the case on main, where the failure only happened for unknown users.

Whether firmware's sce::np::User passes the user service code through like this is not measured. A line in the libSceNpManager debt entry, or asserts in CheckValueClasses before line 918, would record it.

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit d8ab3b6 into boykopovar:main Nov 27, 2026
3 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.

5 participants