Repository navigation
fix(libSceUsbd): refuse a transfer that sceUsbdAllocTransfer did not return - #22965
Merged
oneandonlydean merged 1 commit intoDec 3, 2026
Merged
Conversation
…return The transfer fill and accessor calls wrote and read the transfer through the caller's pointer. Transfers are host allocations here, so a pointer that sceUsbdAllocTransfer did not return, or one sceUsbdFreeTransfer had already freed, was written as host memory. Each call now checks the pointer against the allocated transfers first and throws for any other, as the library already does for unknown devices and handles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
approved these changes
Nov 18, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 09a93376e3:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_usbd_testsbuilt cleanly. - CTest (
guest_usbd):1/1 Test #5130: guest_usbd ....................... Passed 2.36 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceUsbd/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5130: guest_usbd .......................Subprocess aborted***Exception: 0.18 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- core/libs/prx/libSceUsbd/Export.cpp: Verified RequireAllocatedTransfer correctly guards all 8 transfer filling/access functions (sceUsbdFillInterruptTransfer, sceUsbdFillBulkTransfer, sceUsbdFillIsoTransfer, sceUsbdFillControlTransfer, sceUsbdControlTransferGetData, sceUsbdControlTransferGetSetup, sceUsbdSetIsoPacketLengths, sceUsbdGetIsoPacketBuffer) with mutex lock and throws on null or unallocated transfers
- core/libs/prx/libSceUsbd/Export.cpp: Checked mutex locking semantics in sceUsbdFillIsoTransfer, sceUsbdSetIsoPacketLengths, and sceUsbdGetIsoPacketBuffer to ensure state.mutex is held during RequireAllocatedTransfer and IsoCapacity queries without double-locking or TOCTOU races
- docs/dev/debt/changes/fix-usbd-allocated-transfers.md: Verified technical debt fragment follows repository conventions, categorizes under Functional, cites the functions, and documents console behavior and closing condition
- core/libs/tests/GuestUsbd.cpp: Verified test coverage exercises unallocated, freed, and null transfers across all modified functions, and verifies that legitimate allocated transfers continue to function properly
Looks Good To Me
MarcZX10
reviewed
Nov 23, 2026
MarcZX10
left a comment
Contributor
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this change; the prepared bundle and all three changed files were read, but no checks were run in this review.
What I ran
- Read the prepared diff and source context at head
09a93376e32736204d52f21ad151ef32e92388ebusingrepo_read.py. - No tests or other checks were run.
Results
| Check | Result | Note |
|---|---|---|
| Changed source review | passed | All three changed files read |
| Tests | not run | No test execution available |
Findings
Blocking
None.
Non-blocking
None.
Not verified
- The author reports
guest_usbdpassed on Linux at the reviewed head, and reports Windows testing on a pre-squash commit; neither result was independently verified. - Console behavior and the reported convention and debt checks were not verified.
- Files read:
core/libs/prx/libSceUsbd/Export.cpp,core/libs/tests/GuestUsbd.cpp, anddocs/dev/debt/changes/fix-usbd-allocated-transfers.md. No changed files were excluded;files.jsonwas not available through the reader.
To get this to a good state
Nothing is required.
ycbuzi
added a commit
to ycbuzi/AnyPS5
that referenced
this pull request
Nov 23, 2026
Contributor
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
Contributor
Author
|
@ycbuzi thank you for the full-suite runs on both Windows Server images. I added them to Tested. |
Open
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sceUsbdAllocTransferreturns a hostcallocallocation and records it with its iso packet capacity.sceUsbdFreeTransferfrees it and drops the record. The calls that fill or read a transfer wrote and read its fields through the caller's pointer without looking at that record. A pointer thatsceUsbdAllocTransferdidn't return, or one already freed, was therefore written as host memory: a stray pointer crashed the host, and a freed one corrupted the host heap.Changes:
sceUsbdFillInterruptTransfer,sceUsbdFillBulkTransfer,sceUsbdFillIsoTransfer,sceUsbdFillControlTransfer,sceUsbdControlTransferGetData,sceUsbdControlTransferGetSetup,sceUsbdSetIsoPacketLengthsandsceUsbdGetIsoPacketBuffercheck the pointer against the allocated transfers before touching any field.sceUsbdGetDeviceListand a handle not returned bysceUsbdOpen. A null transfer still throws "null transfer".sceUsbdFillIsoTransferandsceUsbdSetIsoPacketLengthsalready treated an unknown transfer as having no iso packets, so an iso fill of one already threw. The check now runs before the capacity check, in the same locked block.Allocated transfers behave as before.
sceUsbdSubmitTransferandsceUsbdCancelTransferare left alone, since #21530 and #21195 edit them.Tested
Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release):
guest_usbd's transfer filler check gains a stackUsbdTransfer, a freed transfer and a null one, passed to all eight calls. Each call throws, and the stack transfer's fields stay zero. An allocated transfer is filled normally after the refusals.guest_usbdpasses, 3 runs, on6d27fa0a3e, the pre-squash commit with this tree.mainwith only the new test (69de86f3d5) failsguest_usbdwitha transfer sceUsbdAllocTransfer did not return was accepted, 3 of 3 runs.git merge-treeagainstmainis clean, and with fix(libSceUsbd): probe guest memory in the device list, event, transfer and configuration calls #21530 and fix(libSceUsbd): return SCE_USBD_ERROR_INVALID_ARG from sceUsbdCancelTransfer for a null transfer #21195, which edit both files. fix(libSceUsbd): retain devices during active USB operations #9803 already conflicts withmainin both files; this branch adds no conflict hunk to either.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for this fragment.Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:guest_usbdpasses, 3 runs, on09a93376e3(this PR's head).Negative control: the same tree with
main'sExport.cppfailsguest_usbdwith an abort froma transfer sceUsbdAllocTransfer did not return was accepted.Independent full-suite runs by @ycbuzi (report) of
09a93376e3merged intomain, WinLibs GCC 15.2.0: Windows Server 2025, 6765 of 6765 in each of 2 runs; Windows Server 2022, 2 and 3 failures of 6765 in 2 runs, 2 of which also fail onmainthere.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)