fix(libSceNet): validate bind and connect guest addresses #11559
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11559"
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 kattkaries on 2026-10-26T19:24:52Z.
What
sceNetBindandsceNetConnectread guest socket addresses directly, so unreadable addresses could crash the host. They also accepted unreadable trailing bytes without validating them. Both now snapshot up tosizeof(sockaddr_storage)bytes throughGuestSocketReadGuest_nid_no_patchbefore conversion. Connect reads the datagram disconnect family from the same snapshot, so a failed address read cannot disconnect a UDP association. Failed reads return0x8041010eand set errno 14. Existing descriptor, null, short-address and already-bound checks retain their order and errors.The eight new tests cover wholly unreadable addresses, a split family header, a split address body, and unreadable trailing bytes, for IPv4 and IPv6 UDP sockets. They check error results, valid-call recovery, and association preservation, including unreadable AF_UNSPEC addresses.
Reference: FreeBSD 11.4
getsockaddrcopies the supplied address before socket operations: https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_syscalls.c . This motivates checked reads; no console validation is claimed. Snapshots are capped at host sockaddr_storage size; this change does not establish console behavior for oversized address lengths.Open-PR review: #11472 fixes sendmsg/sendto guest reads and explicitly excludes bind/connect; it shares Export.cpp and CMakeLists.txt. #7490 adds a listening-socket check later in sceNetConnect; its diff does not change this PR's validation lines. #9834 implements HTTP transport. The original local pr_overlap run found a CMake insertion conflict with #10949; moving this PR's test registration resolved it, and that rerun reported no direct overlaps.
The overlap bot's report updated on 2 November 2026 could not compare ten PRs because they conflict with main: #5836, #9948, #12682, #12683, #12688, #12700, #12918, #12965, #14213 and #14310. Their patches in the shared libSceNet files were reviewed manually. None changes this PR's bind/connect address-validation lines or introduces ReadGuestAddress. The shared CMake changes also concern other registrations or link dependencies. #14310 adds a kernel forwarding call to sceNetBind but does not change its implementation. This is a patch review, not a combined build or runtime test of those PRs.
Tested
Ubuntu 24.04 container on Linux, GCC 13.3.0, CMake 3.28.3, Release full-build configuration with BUILD_TESTING=ON. Initial reproduction base:
afc780e68. Rebased main:263eee0a7. Final tested head:c96633ea5f. All 22 focused checks passed again after the rebase and CMake registration move.Before changing Export.cpp, all eight new cases failed on main: six segfaulted, and two aborted because unreadable trailing bytes did not return EFAULT. The final tests additionally cover zero lengths and failed AF_UNSPEC disconnect attempts.
After the fix, 22/22 tests passed, zero skipped:
Conventions and git diff --check pass. Only the relevant runtime targets were built; the entire project/test suite was not built/run.
Independent Windows verification by @BunnyFl (results): head
c96633ea5fmerged onto main74acfad65bwithout conflicts, Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. All eight guest_net_address_fault_* tests passed in each of three runs with ctest -V. As a control, with only libSceNet/Export.cpp restored to main's version and this PR's tests retained, all eight failed in each of three runs: cases 0, 1 and 4 with a segmentation fault, and case 8 with exit 0xc0000409. These Windows runs were reported by @BunnyFl, not rerun by the PR author.macOS and console behavior remain untested. No title tested.
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 MarcZX10 on 2026-10-27T00:21:15Z.
Review: APPROVED
Reviewed exact head
c96633ea5f585e9ead63dd5f630de730f9e9e6b2. The bind/connect paths snapshot the guest address before conversion or socket operations, and the UDP AF_UNSPEC disconnect decision uses that same checked snapshot. The focused tests exercise unreadable page-boundary inputs and recovery/association behavior. The PR reports 22 focused Linux checks passing after rebase; I did not rerun them here, and Windows/macOS/console behavior remains untested as stated. No actionable correctness issue found in the reviewed change.