Skip to content

fix(libSceUsbStorageDialog): return INVALID_ARGUMENT from sceUsbStorageDialogGetResult for an unwritable result - #14965

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
fogydes:fix/libSceUsbStorageDialog-pointer-validation
Nov 6, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
fogydes:fix/libSceUsbStorageDialog-pointer-validation

Conversation

@fogydes

@fogydes fogydes commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

What

Validate caller result pointers in sceUsbStorageDialogGetResult via GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch preserving errno, returning COMMON_DIALOG_ERROR_INVALID_ARGUMENT (0x80B8000Au) when the buffer is unreadable or unwritable rather than causing an unhandled host access violation (0xc0000005).

Tested

Windows 11 x86_64, ctest --test-dir build -R guest_usb_storage_dialog -V (100% pass). Verified unwritable/unreadable pointer reinterpret_cast<UsbStorageDialogResult*>(0x10) returns COMMON_DIALOG_ERROR_INVALID_ARGUMENT.

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

@BunnyFl BunnyFl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A firmware note for the debt entry, not a blocker. The checked copies do keep the host from faulting.

Firmware 13.42's libSceUsbStorageDialog.sprx (sha256 ed1e0fbffb7169e0b52b10b5b649204249d701b136b42f684ffe699edd463beb) at 0x500 (ul-kdmwPExY), read to the return, from disassembly only, not measured on a console:

507: test rdi, rdi ; je 590          ; 590: 0x80b8000d (null only)
...  (initialization and status checks: 0x80b80003, 0x80b80005)
540: cmp eax, 0x4500000 ; jb 55c      ; SDK version gate
547: cmp qword [rbx], 0x50            ; direct read of result->size
553: cmp dword [rbx+8], 0x80b80007    ; direct read of result->result
577: mov [rbx+8], eax                 ; direct store
58b: mov [rbx+0xc], eax               ; direct store

The module tests only for null, then loads and stores straight through the pointer. There's no syscall or copyin/copyout first, so for a non-null pointer it can't access, the console faults rather than returning a code, and main already matches that.

Could the debt entry say so instead of "unmeasured"? For example: "Firmware 13.42 checks only for null and accesses the structure directly, so the console faults on an inaccessible non-null pointer; AnyPS5 returns COMMON_DIALOG_ERROR_INVALID_ARGUMENT instead." That matches how the libkernel entries word their "returns EFAULT here, where the console faults" fallbacks, and the new tests then pin a documented host-side fallback.

@fogydes

fogydes commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author
  • Document Firmware 13.42 disassembly details and host fallback: Fixed (cb85065). Updated docs/dev/debt/libSceUsbStorageDialog.md:5 to document that Firmware 13.42 checks only for null and accesses the structure directly (read from disassembly, not measured on a console), so the console faults on an inaccessible non-null pointer, while AnyPS5 returns COMMON_DIALOG_ERROR_INVALID_ARGUMENT instead.

@BunnyFl BunnyFl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @fogydes. The debt entry now says what firmware 13.42 does (null check only, direct access, so the console faults) and where AnyPS5 deliberately differs. It keeps the 'read from disassembly, not measured on a console' evidence. The code is unchanged since my last read and matches the module; the new tests pin the documented host-side fallback.

@bunbeans2-arch

Copy link
Copy Markdown
Contributor

A Windows run with GCC 16: Windows 11 Pro 10.0.22631, i9-9900K, MSYS2 UCRT64 GCC 16.1.0, Release, this PR (cb85065a26) merged into main f6232fc.

  • ✅ With this PR: guest_usb_storage_dialog passed 5 of 5.
  • ❌ Same tree with only libSceUsbStorageDialog/Export.cpp put back to main (this PR's test kept, Export.cpp rebuilt): guest_usb_storage_dialog crashed with a SegFault in 5 of 5 runs. So an unwritable result pointer still faults the host on main, and the new check catches it.
  • ✅ main f6232fc alone (its own test and source): guest_usb_storage_dialog passed 3 of 3.

Looks good on Windows 👍

AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@oneandonlydean
oneandonlydean merged commit 9775ae2 into boykopovar:main Nov 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants