fix(libSceSaveData.native): validate guest pointers across convert, backup, mount, and icon operations #15042

Merged
fogydes merged 1 commit from upstream-pr/15042 into main 2026-11-11 07:49:23 +00:00
fogydes commented 2026-11-02 11:45:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-11-02T11:45:58Z.


What

  • In core/libs/prx/libSceSaveData.native/Export.cpp, validate caller guest input and output pointers using GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch across save data conversion, backup, mount, parameter, and icon operations (sceSaveDataGetConvertProgress, sceSaveDataConvert, sceSaveDataGetEventResult, sceSaveDataBackup, sceSaveDataGetMountInfo, sceSaveDataUmount2, sceSaveDataGetParam, sceSaveDataSetParam, sceSaveDataLoadIcon, sceSaveDataSaveIcon, sceSaveDataSaveIconByPath).
  • In sceSaveDataGetConvertProgress, stage the atomic progress value locally and copy out via GuestCopyOut_nid_no_patch, returning SAVE_DATA_ERROR_PARAMETER on unwritable memory instead of causing an unhandled host write violation.
  • In sceSaveDataConvert and sceSaveDataBackup, copy input parameter records and dir_name structures through GuestCopyIn_nid_no_patch, returning SAVE_DATA_ERROR_PARAMETER on unmapped or invalid guest pointers.
  • In sceSaveDataGetEventResult, copy the queued event out via GuestCopyOut_nid_no_patch, preserving the event on the queue and returning SAVE_DATA_ERROR_PARAMETER if destination memory is unwritable.
  • In sceSaveDataGetParam, validate got_size writability (preserving its prior value if param_buf copy-out fails) before writing param_buf, so an unwritable got_size returns SAVE_DATA_ERROR_PARAMETER without leaving param_buf partially written.
  • In sceSaveDataLoadIcon and sceSaveDataSaveIcon, validate mount_point, SaveDataIcon, and icon->buf with GuestCopyIn_nid_no_patch / GuestCopyOut_nid_no_patch and stage sce_sys/icon0.png transfers in host memory before committing icon->buf / icon->data_size (preserving icon->data_size and icon->buf on SAVE_DATA_ERROR_PARAMETER).
  • Add regression tests across core/libs/tests/GuestSaveDataConvert.cpp, core/libs/tests/GuestSaveDataIcon.cpp, and core/libs/tests/GuestSaveDataMountStatus.cpp covering unmapped/unwritable pointers across convert, backup, event result, mount info, umount2, getParam (leaving param_buf and got_size untouched on failure), setParam, and load/save icon (icon and icon->buf).

Tested

  • Windows 11 (MinGW-w64 GCC 15.2.0, Release).
  • Rebased onto origin/main (2a3df01d6fb); git merge-tree --write-tree origin/main HEAD succeeded cleanly (347513f1fce75379dec5d6055675e4fd8c10ebf7).
  • Built libSceSaveData.native and all SaveData test targets and ran ctest --test-dir build -R "savedata" --output-on-failure: 34/34 passed (tree 347513f1fce75379dec5d6055675e4fd8c10ebf7 at pre-amend 0ca31f183d1), and ctest --test-dir build -R "^guest_savedata_(icon|mount_status|convert)" --output-on-failure: 8/8 passed on final head 25b8f62457a.
  • Verified python tools/check_conventions.py --base origin/main passed (All conventions checks passed.).

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5119771118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15042). Originally posted by [fogydes](https://github.com/fogydes) on 2026-11-02T11:45:58Z. --- ### What - In `core/libs/prx/libSceSaveData.native/Export.cpp`, validate caller guest input and output pointers using `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` across save data conversion, backup, mount, parameter, and icon operations (`sceSaveDataGetConvertProgress`, `sceSaveDataConvert`, `sceSaveDataGetEventResult`, `sceSaveDataBackup`, `sceSaveDataGetMountInfo`, `sceSaveDataUmount2`, `sceSaveDataGetParam`, `sceSaveDataSetParam`, `sceSaveDataLoadIcon`, `sceSaveDataSaveIcon`, `sceSaveDataSaveIconByPath`). - In `sceSaveDataGetConvertProgress`, stage the atomic progress value locally and copy out via `GuestCopyOut_nid_no_patch`, returning `SAVE_DATA_ERROR_PARAMETER` on unwritable memory instead of causing an unhandled host write violation. - In `sceSaveDataConvert` and `sceSaveDataBackup`, copy input parameter records and `dir_name` structures through `GuestCopyIn_nid_no_patch`, returning `SAVE_DATA_ERROR_PARAMETER` on unmapped or invalid guest pointers. - In `sceSaveDataGetEventResult`, copy the queued event out via `GuestCopyOut_nid_no_patch`, preserving the event on the queue and returning `SAVE_DATA_ERROR_PARAMETER` if destination memory is unwritable. - In `sceSaveDataGetParam`, validate `got_size` writability (preserving its prior value if `param_buf` copy-out fails) before writing `param_buf`, so an unwritable `got_size` returns `SAVE_DATA_ERROR_PARAMETER` without leaving `param_buf` partially written. - In `sceSaveDataLoadIcon` and `sceSaveDataSaveIcon`, validate `mount_point`, `SaveDataIcon`, and `icon->buf` with `GuestCopyIn_nid_no_patch` / `GuestCopyOut_nid_no_patch` and stage `sce_sys/icon0.png` transfers in host memory before committing `icon->buf` / `icon->data_size` (preserving `icon->data_size` and `icon->buf` on `SAVE_DATA_ERROR_PARAMETER`). - Add regression tests across `core/libs/tests/GuestSaveDataConvert.cpp`, `core/libs/tests/GuestSaveDataIcon.cpp`, and `core/libs/tests/GuestSaveDataMountStatus.cpp` covering unmapped/unwritable pointers across convert, backup, event result, mount info, umount2, getParam (leaving `param_buf` and `got_size` untouched on failure), setParam, and load/save icon (`icon` and `icon->buf`). ### Tested - Windows 11 (MinGW-w64 GCC 15.2.0, Release). - Rebased onto `origin/main` (`2a3df01d6fb`); `git merge-tree --write-tree origin/main HEAD` succeeded cleanly (`347513f1fce75379dec5d6055675e4fd8c10ebf7`). - Built `libSceSaveData.native` and all SaveData test targets and ran `ctest --test-dir build -R "savedata" --output-on-failure`: 34/34 passed (tree `347513f1fce75379dec5d6055675e4fd8c10ebf7` at pre-amend `0ca31f183d1`), and `ctest --test-dir build -R "^guest_savedata_(icon|mount_status|convert)" --output-on-failure`: 8/8 passed on final head `25b8f62457a`. - Verified `python tools/check_conventions.py --base origin/main` passed (`All conventions checks passed.`). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
mashingaan commented 2026-11-02 11:51:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-02T11:51:43Z.

Review: DISMISSED


SaveDataMountPoint::data is a fixed 16-byte array. GuestCopyIn_nid_no_patch only validates the readable range, not NUL termination. A valid pointer to 16 nonzero bytes makes *tracePoint = localPoint.data read past the local struct while constructing std::string. The later find_slot_by_mount_point(localPoint.data) also receives an unbounded C string. Please reject an unterminated mount point with a bounded memchr before 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:577 in head 85b45988b86a5ab757814a9d3651204230966c6f.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5736111276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15042#pullrequestreview-5736111276). Originally posted by [mashingaan](https://github.com/mashingaan) on 2026-11-02T11:51:43Z. **Review:** DISMISSED --- `SaveDataMountPoint::data` is a fixed 16-byte array. `GuestCopyIn_nid_no_patch` only validates the readable range, not NUL termination. A valid pointer to 16 nonzero bytes makes `*tracePoint = localPoint.data` read past the local struct while constructing `std::string`. The later `find_slot_by_mount_point(localPoint.data)` also receives an unbounded C string. Please reject an unterminated mount point with a bounded `memchr` before 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:577` in head `85b45988b86a5ab757814a9d3651204230966c6f`.
MarcZX10 commented 2026-11-02 12:07:04 +00:00 (Migrated from github.com)

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 85b45988b86a5ab757814a9d3651204230966c6f against base 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab. The merge preview against that base was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build was run.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15042
git diff --check 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab...85b45988b86a5ab757814a9d3651204230966c6f
python3 tools/check_conventions.py --base 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab --head 85b45988b86a5ab757814a9d3651204230966c6f --title 'fix(libSceSaveData.native): validate guest pointers across convert, backup, mount, and icon operations' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/pr-body.md
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab --head 85b45988b86a5ab757814a9d3651204230966c6f --json
git merge-tree --write-tree 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab 85b45988b86a5ab757814a9d3651204230966c6f

Results

Check Result Note
Diff and conventions passed No whitespace or convention findings
Export audit passed No findings; lexical audit only
Merge preview passed Clean against the stated base
Test registration passed Both changed C++ tests are registered
Manual source review failed Unterminated mount-point field reaches unbounded reads
Build and C++ tests not run Require a build
Hosted checks not run All six were queued
Precheck helper scripts failed Helpers absent from its isolated checkout; ABI audit rerun passed
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:

All conventions checks passed.

The ABI audit summary was:

{
  "status": "passed",
  "findings": []
}

The merge-tree command printed:

257e813c14d253d5fdb71eec3b03b19178781ceb

The precheck helper launch errors were:

/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/head-85b45988b86a-67942cec/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/head-85b45988b86a-67942cec/tools/pr_test_quality.py': [Errno 2] No such file or directory

Negative control

Assertion Change to code under test Result
Unterminated mount-point rejection No code mutation; requires running the C++ test Not exercised

Findings

Blocking

SaveDataMountPoint::data is a fixed 16-byte array. The new code copies the guest structure, then passes localPoint.data to unbounded string operations without first proving a NUL occurs within those 16 bytes. In getMountInfo, getParam, setParam, and umount2, *tracePoint = localPoint.data can 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

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5736296641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15042#pullrequestreview-5736296641). Originally posted by [MarcZX10](https://github.com/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 `85b45988b86a5ab757814a9d3651204230966c6f` against base `98346b748caaf5e8e533540f3bb9e4ceacf3d7ab`. The merge preview against that base was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build was run. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15042 git diff --check 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab...85b45988b86a5ab757814a9d3651204230966c6f python3 tools/check_conventions.py --base 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab --head 85b45988b86a5ab757814a9d3651204230966c6f --title 'fix(libSceSaveData.native): validate guest pointers across convert, backup, mount, and icon operations' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/pr-body.md python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab --head 85b45988b86a5ab757814a9d3651204230966c6f --json git merge-tree --write-tree 98346b748caaf5e8e533540f3bb9e4ceacf3d7ab 85b45988b86a5ab757814a9d3651204230966c6f ``` ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | No whitespace or convention findings | | Export audit | passed | No findings; lexical audit only | | Merge preview | passed | Clean against the stated base | | Test registration | passed | Both changed C++ tests are registered | | Manual source review | failed | Unterminated mount-point field reaches unbounded reads | | Build and C++ tests | not run | Require a build | | Hosted checks | not run | All six were queued | | Precheck helper scripts | failed | Helpers absent from its isolated checkout; ABI audit rerun passed | <details><summary>Precheck summary and command outputs</summary> 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: ```text All conventions checks passed. ``` The ABI audit summary was: ```json { "status": "passed", "findings": [] } ``` The merge-tree command printed: ```text 257e813c14d253d5fdb71eec3b03b19178781ceb ``` The precheck helper launch errors were: ```text /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/head-85b45988b86a-67942cec/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-15042-85b45988b86a/head-85b45988b86a-67942cec/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` </details> ## Negative control | Assertion | Change to code under test | Result | |---|---|---| | Unterminated mount-point rejection | No code mutation; requires running the C++ test | Not exercised | ## Findings ### Blocking `SaveDataMountPoint::data` is a fixed 16-byte array. The new code copies the guest structure, then passes `localPoint.data` to unbounded string operations without first proving a NUL occurs within those 16 bytes. In `getMountInfo`, `getParam`, `setParam`, and `umount2`, `*tracePoint = localPoint.data` can 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 - [`SaveDataMountPoint` is 16 bytes at this head](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/SceTypes.hpp#L1652). - [The new guest copy and unbounded trace/lookup in `getMountInfo` and `getParam`](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/prx/libSceSaveData.native/Export.cpp#L572-L608), [icon paths](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/prx/libSceSaveData.native/Export.cpp#L691-L698), [`saveIcon` and `setParam`](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/prx/libSceSaveData.native/Export.cpp#L838-L870), and [`umount2`](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/prx/libSceSaveData.native/Export.cpp#L1075-L1084). - [`find_slot_by_mount_point` compares the input as a C string](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/prx/libSceSaveData.native/SaveData.hpp#L58-L64). - [Current tests cover invalid addresses but not a readable, unterminated 16-byte point](https://github.com/boykopovar/AnyPS5/blob/85b45988b86a5ab757814a9d3651204230966c6f/core/libs/tests/GuestSaveDataMountStatus.cpp#L36-L75). ## 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.
adriadam10 commented 2026-11-07 02:44:49 +00:00 (Migrated from github.com)

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:

  • The PR conflicts with main in core/libs/prx/libSceSaveData.native/Export.cpp: sceSaveDataLoadIcon and sceSaveDataSaveIcon were rewritten on main (they now read/write sce_sys/icon0.png through icon->buf, buf_size, data_size). Please rebase and re-apply the validation to the new bodies: copy the SaveDataIcon record in with GuestCopyIn_nid_no_patch, and move the data to/from icon->buf through GuestCopyOut_nid_no_patch / GuestCopyIn_nid_no_patch (staged in a host buffer) instead of dereferencing the guest pointer. The old data_size = 0 / no-op versions no longer exist.
  • Add tests for the icon paths with an unmapped icon and an unmapped icon->buf, on both load and save.
  • getParam (Export.cpp:1026-1033) writes param_buf and can then fail on got_size, leaving a partial write while returning PARAMETER. Validate/stage both outputs before writing either.
  • Check overlap with #14908, #15650 and #15943, which touch the same file (and #15650 the same test file).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5809576557 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15042#pullrequestreview-5809576557). Originally posted by [adriadam10](https://github.com/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: - The PR conflicts with `main` in `core/libs/prx/libSceSaveData.native/Export.cpp`: `sceSaveDataLoadIcon` and `sceSaveDataSaveIcon` were rewritten on `main` (they now read/write `sce_sys/icon0.png` through `icon->buf`, `buf_size`, `data_size`). Please rebase and re-apply the validation to the new bodies: copy the `SaveDataIcon` record in with `GuestCopyIn_nid_no_patch`, and move the data to/from `icon->buf` through `GuestCopyOut_nid_no_patch` / `GuestCopyIn_nid_no_patch` (staged in a host buffer) instead of dereferencing the guest pointer. The old `data_size = 0` / no-op versions no longer exist. - Add tests for the icon paths with an unmapped `icon` and an unmapped `icon->buf`, on both load and save. - `getParam` (`Export.cpp:1026-1033`) writes `param_buf` and can then fail on `got_size`, leaving a partial write while returning PARAMETER. Validate/stage both outputs before writing either. - Check overlap with #14908, #15650 and #15943, which touch the same file (and #15650 the same test file).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!15042
No description provided.