fix(libSceRandom): return INVALID from sceRandomGetRandomNumber for an unwritable buffer #14980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14980"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-11-02T07:45:46Z.
What
sceRandomGetRandomNumberpassed the caller buffer directly toHostEntropy_nid_no_patch, which executedstd::memcpyon unvalidated memory. Calling the export with an unwritable destination pointer caused an unhandled host access violation (0xc0000005).Random bytes are now staged in a local stack buffer and copied to guest memory through
GuestCopyOut_nid_no_patchpreservingerrno, returningSCE_RANDOM_ERROR_INVALID(0x817C0016) when copy-out fails as a defensive host-protection fallback.Tested
core/libs/tests/GuestRandom.cpp:sceRandomGetRandomNumber(0x10, 16) == SCE_RANDOM_ERROR_INVALID(reproduced unhandled host access violation0xc0000005on main, passing after fix)guest_random(Test #2547) passed 100% (0.02 s)python tools/check_conventions.py --base origin/mainpassed cleanly with 0 findingspython tools/pr_overlap.py --branch fix/libSceRandom-pointer-validationverified 0 overlaps across 1,915 open PRsChecklist
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)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T10:51:11Z.
Review: COMMENTED
A firmware note for the debt entry, not a blocker. The checked copy does keep the host from faulting.
Firmware 13.42's
libSceRandom.sprx(sha256700a43a95c4eb9bea260339978c00c2be5075b35d34bdfbec0a48dd07b15f1b7) at 0xd0 (PI7jIZj4pcE), read to the return, from disassembly only, not measured on a console:The module tests only for null, then stores straight through the pointer. There's no syscall,
copyoutor kernel query before the store. So for a non-null pointer it can't write, the console faults rather than returning a code, andmainalready matches that.The debt text calls the console behaviour unmeasured, but the module settles it. Could the entry say what happens instead? For example: "Firmware 13.42 checks only for null and stores directly, so the console faults on an unwritable non-null pointer; AnyPS5 returns INVALID (0x817C0016) instead." That matches how the libkernel entries word their "returns EFAULT here, where the console faults" fallbacks. The new test lines then pin a deliberate host-side fallback, which is fine once the entry says so.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T14:46:19Z.
Review: APPROVED
Thanks, @fogydes. The debt entry now says what firmware 13.42 does (null check only, direct store, so the console faults) and where AnyPS5 deliberately differs, with the evidence wording kept. The code is unchanged since my last read.
One optional wording point: the entry still calls returning
INVALIDfor a null buffer of size 0 'an assumption, not measured on hardware'. The module settles that case too. At0x11cit tests the buffer for null before the size check, so a null buffer returns0x817c0016whatever the size (read from disassembly, not measured on a console). That agrees with this library and fpPS4, not with shadPS4 or KytyPS5.