Repository navigation
fix(libSceUserService): stage user group names before guest copy-out - #22315
oneandonlydean merged 2 commits into
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 607654eb51:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_user_service_group_io_testsbuilt cleanly. - CTest (
guest_user_service_group_io):1/1 Test #5029: guest_user_service_group_io ...... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceUserService/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5029: guest_user_service_group_io ......***Exception: SegFault 2.32 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified sceUserServiceGetUserGroupName parameter checks: size parameter is ignored by GuestCopyOut_nid_no_patch which copies sizeof(output) (129 bytes) unconditionally into guest name buffer
- Inspected buffer overflow vulnerability: guest caller specifying size < 129 (or smaller buffer with size parameter) will suffer a buffer overrun via unchecked GuestCopyOut of 129 bytes
- Checked error handling for nullptr and invalid groupIndex in Export.cpp: UserGroupSlotExists(groupIndex) properly rejects invalid indices
- Verified errno preservation across GuestCopyOut_nid_no_patch calls
- Examined docs/dev/debt/changes/user-group-name-output.md technical debt fragment format and conventions
- Concerns:
- core/libs/prx/libSceUserService/Export.cpp:1159: sceUserServiceGetUserGroupName accepts a
sizeparameter (std::size_t size) representing the capacity of the guest destination buffername, but passessizeof(output)(129 bytes) toGuestCopyOut_nid_no_patch(name, output, sizeof(output))without checkingsize < sizeof(output). If a caller passes a buffer smaller than 129 bytes (or specifiessize < 129),GuestCopyOut_nid_no_patchoverwrites 129 bytes into the guest memory, causing a guest buffer overflow / memory corruption. Eithersizemust be validated (e.g. returningUSER_SERVICE_ERROR_BUFFER_TOO_SHORTorUSER_SERVICE_ERROR_INVALID_ARGUMENTifsize < 129, similar tosceUserServiceGetUserName), or copy at moststd::min(size, sizeof(output)).
- core/libs/prx/libSceUserService/Export.cpp:1159: sceUserServiceGetUserGroupName accepts a
Requesting changes for the points above.
|
I read the new copy-out and it ignores the caller's size: it always writes 129 bytes. The old fallback was bounded by size, so a guest that passes a smaller buffer now gets an overrun. PrivacyOnion's review makes the same point. Please bound the copy by size:
The rest looks right to me: the staging, the errno restore and the INVALID_ARGUMENT on a bad pointer. |
|
@PrivacyOnion @oneandonlydean The size checks above the changed hunk already require exactly 129 bytes. I added explicit regression coverage in d2491d3 for sizes 0, 1, 16, 128, 130 and The implementation keeps its existing exact-size contract. Could you recheck the retained validation above the new copy-out? |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d2491d383e:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_user_service_group_io_testsbuilt cleanly. - CTest (
guest_user_service_group_io):1/1 Test #5030: guest_user_service_group_io ...... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceUserService/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5030: guest_user_service_group_io ......***Exception: SegFault 1.49 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified sceUserServiceGetUserGroupName parameter checks: pre-existing validation requires size == 129, returning USER_SERVICE_ERROR_BUFFER_TOO_SHORT for size < 129 and USER_SERVICE_ERROR_INVALID_ARGUMENT for size > 129 before any file I/O or guest write.
- Verified copy-out safety: output is staged into a 129-byte host buffer initialized to zero, populated via read or fallback formatting, and safely copied out via GuestCopyOut_nid_no_patch with errno preserved across the call.
- Verified resource cleanup: descriptor opened via sceKernelOpen is closed on both read success and failure before copy-out or exit.
- Verified AGENTS.md conventions: technical debt fragment docs/dev/debt/changes/user-group-name-output.md adheres to the required format and labels, and no forbidden code comments were introduced.
- Verified test coverage in GuestUserServiceGroupIo.cpp: explicit regression coverage exercises boundary sizes (0, 1, 16, 128, 130, SIZE_MAX), nullptr handling, invalid group indices, unmapped/read-only memory, and descriptor leak prevention.
Looks Good To Me
|
You are right: the size checks at the top of sceUserServiceGetUserGroupName return early for any size other than 129, so the 129-byte copy-out cannot overrun. Our request for a size bound was mistaken. The new tests for the short and long sizes are a good addition. I passed it on d2491d3. |
What
Read stored user-group names and format fallback names into a host buffer, then publish the complete fixed-size record through GuestCopyOut. Keep file closure and the existing fallback behavior for failed or empty reads.
The getter requires a 129-byte destination. Its existing checks reject smaller sizes with
USER_SERVICE_ERROR_BUFFER_TOO_SHORTand larger sizes withUSER_SERVICE_ERROR_INVALID_ARGUMENTbefore file I/O or guest writes.Tested
Windows 11, WinLibs GCC 15.2.0, Ninja, Release. Built
guest_user_service_group_io_tests;guest_user_service_group_iopassed three consecutive runs. New cases cover unmapped and read-only output buffers, stored-name and fallback paths, preserved errno, and descriptor closure.Follow-up regression coverage checks sizes 0, 1, 16, 128, 130 and
SIZE_MAX, unchanged buffer canaries and errno, no file I/O on rejected sizes, and null-pointer ordering. The updatedguest_user_service_group_iopassed on Windows with WinLibs GCC 15.2.0.Negative control: with the new tests retained and the implementation unchanged on main
e2ca7c394a, the test fails with a segmentation fault. Restoring the fix passes.git diff --checkandtools/check_conventions.py --base upstream/mainpassed. The requiredorigin/maincomparison also ran; its errors concern upstream commit subjects since the older fork main. No title, Linux, or macOS validation.Export overlap lookup found no competing implementation. Manually compared the seven conflicting shared-file PRs (#9345, #9828, #12900, #14829, #14851, #20162, #21521); they do not change this getter.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)