fix(libSceNpUniversalDataSystem): copy context, event, record and property outputs through GuestCopy #19606
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19606"
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 gnavarro24 on 2026-11-13T15:47:28Z.
What
Twenty-two exports in
core/libs/prx/libSceNpUniversalDataSystemwrote through an output pointer, read a guest string, or read an input struct directly, so an unwritable output, an unreadable string, or an unreadable struct faulted inside the library:sceNpUniversalDataSystemCreateContext,CreateHandle,GetMemoryStat,GetStorageStatwrote their output (context,handle,stat) with a raw*ptr = valueinstead ofGuestCopyOut_nid_no_patch.sceNpUniversalDataSystemInitializeandsceNpUniversalDataSystemIntInitializereadparam->size/param->pool_size(or->memory) directly off the guest-supplied init struct instead ofGuestCopyIn_nid_no_patch.sceNpUniversalDataSystemCreateEventreadevent_namewithevent_name[0]and an implicitstd::stringconstruction, and wrote both of its outputs (new_event,prop_ptr) directly; it now reads the name withCopyGuestString_nid_no_patchand writes both outputs throughGuestCopyOut_nid_no_patch, releasing the newly created event if the second write fails so no event is left created-but-unreachable.sceNpUniversalDataSystemEventEstimateSizeandEventToStringwrote their outputs directly (EventToStringalsomemcpy'd straight into the guest buffer); both now also validateeventagainst the existingevents()registry before dereferencing it, the same checkPostEventalready did — previously a destroyed or forged event handle faulted here instead of being rejected.sceNpUniversalDataSystemCreateEventPropertyArray/CreateEventPropertyObjectand theSetObject/SetArrayvariants of both the array and object property API wrote theirnew_array/new_object/value_ptroutput directly; all now go throughGuestCopyOut_nid_no_patch, and the created/cloned value is only added to its parent after that write succeeds, so a rejected call leaves no orphaned child.sceNpUniversalDataSystemIntCreateRecordArray/CreateRecordObject/CreateRecordDataand theIntRecordArraySetObject/SetArray/IntRecordObjectSetObject/SetArrayinternal record functions had the samerecord/valuePtroutput-write and (forIntInitialize) input-struct-read issue; fixed the same way, releasing the record on a failed create.python3 tools/guest_pointer_audit.py libSceNpUniversalDataSystemgoes from 49 direct guest pointer accesses in 36 exported functions to 29 in 25, all of them either the now-validatedeventreads inEventEstimateSize/EventToString(the audit does not see the newevents().Contains()check) or thearray/object/valueopaque-handle parameters of the publicEventPropertyArraySet*/EventPropertyObjectSet*functions, which this PR does not touch — see Known gap below.Known gap: unlike the
Int*record functions inRecord.cpp, which validate an array/object handle withFindArray/FindObjectbefore dereferencing it, the publicsceNpUniversalDataSystemEventPropertyArraySet*/EventPropertyObjectSet*functions still dereference theirarray/object/valuehandle without checking it is a live one, so a stale, destroyed or forged handle still crashes the host. Closing this needs the same handle-registry validationRecord.cppalready has, which is a larger, separate change; recorded indocs/dev/debt/libSceNpUniversalDataSystem.mdfor a follow-up PR.Tested
Linux x86-64 (Ubuntu 24.04, GCC 13.3.0, Ninja, Release,
-DBUILD_TESTING=ON), branch head onmainb975a42ca5. All affected test executables pass:np_uds_events_tests,guest_np_uds_queries_tests,guest_np_uds_records_tests,guest_np_trophy_unlocks_tests,guest_np_trophy_data_tests(with its required library-path argument) andguest_np_trophy_stats_tests(these last three link againstlibSceNpUniversalDataSystemand exercise it throughlibSceNpTrophy2).guest_np_uds_queries_testsandguest_np_uds_records_tests, which hold the new cases, each ran 3/3.New cases cover every changed export, each passing
0x10(an unmapped guest address) as the output pointer, string, struct or handle under test with every other argument valid, checkingerrno(set toEBUSYfirst) is preserved and, where applicable, that the refused call left no state change (the output variable untouched, the registered size of an array/object unchanged, a destroyed event's handle rejected instead of dereferenced):GuestNpUniversalDataSystemQueries.cpp:Initialize,GetMemoryStat,GetStorageStat,CreateContext,CreateHandle,CreateEvent(unwritablenew_event, unwritableprop_ptr, unreadableevent_name),EventEstimateSize(unwritablesize, and a destroyed/unknown event handle),EventToString(unwritablebuf, unwritablestring_size, and a destroyed/unknown event handle),CreateEventPropertyArray/CreateEventPropertyObjectand theirSetObject/SetArrayvalue_ptroutput.GuestNpUniversalDataSystemRecords.cpp:IntInitialize(unreadable param),IntCreateRecordArray/CreateRecordObject/CreateRecordData(unwritablerecord), andIntRecordArraySetObject/SetArray/IntRecordObjectSetObject/SetArray(unwritablevaluePtr), each confirming the rejected call did not still add its copy.Negative control: the seven implementation files from
mainwith the new test cases kept —guest_np_uds_queries_testsandguest_np_uds_records_testsboth end withSegmentation fault(exit 139) in each of 3 runs.python3 tools/check_conventions.py --base origin/mainpasses andgit diff --check origin/mainis clean.tools/pr_overlap.py --branch fix/libSceNpUniversalDataSystem-guest-copyreports no overlap. The only other open PRs naming this library (#13606, #14427) touch different files (LegacyExports.cpp,UdsEvent.cpp);git merge-treeconfirms this branch merges cleanly with #13606 despite both editingdocs/dev/debt/libSceNpUniversalDataSystem.md.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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:33:04Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
21da2bec01:tools/check_conventions.pypassed;git diff --checkclean.guest_np_uds_queries_tests,guest_np_uds_records_testsbuilt cleanly.guest_np_uds_records,guest_np_uds_queries):core/libs/prx/libSceNpUniversalDataSystem/src/Context.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/Event.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyArray.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/EventPropertyObject.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/Handle.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/Record.cpp,core/libs/prx/libSceNpUniversalDataSystem/src/System.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me