fix(libSceSaveData.native): validate guest pointers across convert, backup, mount, and icon operations #15042
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15042"
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-02T11:45:58Z.
What
core/libs/prx/libSceSaveData.native/Export.cpp, validate caller guest input and output pointers usingGuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patchacross save data conversion, backup, mount, parameter, and icon operations (sceSaveDataGetConvertProgress,sceSaveDataConvert,sceSaveDataGetEventResult,sceSaveDataBackup,sceSaveDataGetMountInfo,sceSaveDataUmount2,sceSaveDataGetParam,sceSaveDataSetParam,sceSaveDataLoadIcon,sceSaveDataSaveIcon,sceSaveDataSaveIconByPath).sceSaveDataGetConvertProgress, stage the atomic progress value locally and copy out viaGuestCopyOut_nid_no_patch, returningSAVE_DATA_ERROR_PARAMETERon unwritable memory instead of causing an unhandled host write violation.sceSaveDataConvertandsceSaveDataBackup, copy input parameter records anddir_namestructures throughGuestCopyIn_nid_no_patch, returningSAVE_DATA_ERROR_PARAMETERon unmapped or invalid guest pointers.sceSaveDataGetEventResult, copy the queued event out viaGuestCopyOut_nid_no_patch, preserving the event on the queue and returningSAVE_DATA_ERROR_PARAMETERif destination memory is unwritable.sceSaveDataGetParam, validategot_sizewritability (preserving its prior value ifparam_bufcopy-out fails) before writingparam_buf, so an unwritablegot_sizereturnsSAVE_DATA_ERROR_PARAMETERwithout leavingparam_bufpartially written.sceSaveDataLoadIconandsceSaveDataSaveIcon, validatemount_point,SaveDataIcon, andicon->bufwithGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patchand stagesce_sys/icon0.pngtransfers in host memory before committingicon->buf/icon->data_size(preservingicon->data_sizeandicon->bufonSAVE_DATA_ERROR_PARAMETER).core/libs/tests/GuestSaveDataConvert.cpp,core/libs/tests/GuestSaveDataIcon.cpp, andcore/libs/tests/GuestSaveDataMountStatus.cppcovering unmapped/unwritable pointers across convert, backup, event result, mount info, umount2, getParam (leavingparam_bufandgot_sizeuntouched on failure), setParam, and load/save icon (iconandicon->buf).Tested
origin/main(2a3df01d6fb);git merge-tree --write-tree origin/main HEADsucceeded cleanly (347513f1fce75379dec5d6055675e4fd8c10ebf7).libSceSaveData.nativeand all SaveData test targets and ranctest --test-dir build -R "savedata" --output-on-failure: 34/34 passed (tree347513f1fce75379dec5d6055675e4fd8c10ebf7at pre-amend0ca31f183d1), andctest --test-dir build -R "^guest_savedata_(icon|mount_status|convert)" --output-on-failure: 8/8 passed on final head25b8f62457a.python tools/check_conventions.py --base origin/mainpassed (All conventions checks passed.).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 mashingaan on 2026-11-02T11:51:43Z.
Review: DISMISSED
SaveDataMountPoint::datais a fixed 16-byte array.GuestCopyIn_nid_no_patchonly validates the readable range, not NUL termination. A valid pointer to 16 nonzero bytes makes*tracePoint = localPoint.dataread past the local struct while constructingstd::string. The laterfind_slot_by_mount_point(localPoint.data)also receives an unbounded C string. Please reject an unterminated mount point with a boundedmemchrbefore either use, and add a test with all 16 bytes nonzero.This is on the new path at
core/libs/prx/libSceSaveData.native/Export.cpp:577in head85b45988b86a5ab757814a9d3651204230966c6f.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T12:07:04Z.
Review: DISMISSED
Reviewed — changes requested
The copied mount-point structure is readable, but its fixed-size string is not validated as NUL-terminated before several new C-string reads, which can read beyond the local structure.
What I ran
Reviewed all three changed files at head
85b45988b86a5ab757814a9d3651204230966c6fagainst base98346b748caaf5e8e533540f3bb9e4ceacf3d7ab. The merge preview against that base was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build was run.Results
Precheck summary and command outputs
The precheck reported diff check and conventions passed; dependency/mergeability passed; build, Python checks, and negative controls not applicable; ABI audit and test-quality helper failed to launch because those local helper files were absent from the isolated checkout. I reran the ABI audit directly and it passed with no findings. The test-quality heuristic therefore was not run.
The convention checker output was:
The ABI audit summary was:
The merge-tree command printed:
The precheck helper launch errors were:
Negative control
Findings
Blocking
SaveDataMountPoint::datais a fixed 16-byte array. The new code copies the guest structure, then passeslocalPoint.datato unbounded string operations without first proving a NUL occurs within those 16 bytes. IngetMountInfo,getParam,setParam, andumount2,*tracePoint = localPoint.datacan read beyond the local structure; in all six changed mount-point paths,find_slot_by_mount_point(localPoint.data)also consumes it as a C string. A readable mount-point structure containing 16 nonzero bytes can therefore trigger an out-of-bounds read. Please use one bounded parser that rejects an unterminated field before tracing or slot lookup, and add regression coverage for the 16-byte non-NUL case across these paths.Non-blocking
None.
Sources
SaveDataMountPointis 16 bytes at this head.getMountInfoandgetParam, icon paths,saveIconandsetParam, andumount2.find_slot_by_mount_pointcompares the input as a C string.Not verified
No local build, CTest, negative control, or console run was performed. Hosted checks had not started at the final snapshot. The author reports a Windows 11 / MinGW GCC 15.2.0 test run in the PR description; I did not reproduce it.
To get this to a good state
Reject a mount-point field with no NUL within its fixed array before any trace or lookup, and add the regression test. After the head changes, I will rerun the precheck and review all affected call sites on that new head.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-07T02:44:49Z.
Review: CHANGES_REQUESTED
Thanks, the bounded mount-point check (
copy_mount_point) addresses the earlier review points. What is left:mainincore/libs/prx/libSceSaveData.native/Export.cpp:sceSaveDataLoadIconandsceSaveDataSaveIconwere rewritten onmain(they now read/writesce_sys/icon0.pngthroughicon->buf,buf_size,data_size). Please rebase and re-apply the validation to the new bodies: copy theSaveDataIconrecord in withGuestCopyIn_nid_no_patch, and move the data to/fromicon->bufthroughGuestCopyOut_nid_no_patch/GuestCopyIn_nid_no_patch(staged in a host buffer) instead of dereferencing the guest pointer. The olddata_size = 0/ no-op versions no longer exist.iconand an unmappedicon->buf, on both load and save.getParam(Export.cpp:1026-1033) writesparam_bufand can then fail ongot_size, leaving a partial write while returning PARAMETER. Validate/stage both outputs before writing either.