fix(libSceNet): validate bind and connect guest addresses #11559

Merged
kattkaries merged 2 commits from upstream-pr/11559 into main 2026-11-08 18:31:00 +00:00
kattkaries commented 2026-10-26 19:24:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kattkaries on 2026-10-26T19:24:52Z.


What

sceNetBind and sceNetConnect read guest socket addresses directly, so unreadable addresses could crash the host. They also accepted unreadable trailing bytes without validating them. Both now snapshot up to sizeof(sockaddr_storage) bytes through GuestSocketReadGuest_nid_no_patch before conversion. Connect reads the datagram disconnect family from the same snapshot, so a failed address read cannot disconnect a UDP association. Failed reads return 0x8041010e and 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 getsockaddr copies 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:

cmake --build build --target guest_net_address_fault_tests guest_sce_net_tests guest_net_buffer_validation_tests net_dontwait_tests net_blocking_send_tests --parallel 6
ctest --test-dir build -R '^(guest_net_address_fault_.*|guest_sce_net|guest_net_buffer_validation|net_dontwait_.*|public_headers)$' --output-on-failure
python3 tools/check_conventions.py --base origin/main

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 c96633ea5f merged onto main 74acfad65b without 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

  • 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:5023358677 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11559). Originally posted by [kattkaries](https://github.com/kattkaries) on 2026-10-26T19:24:52Z. --- ### What `sceNetBind` and `sceNetConnect` read guest socket addresses directly, so unreadable addresses could crash the host. They also accepted unreadable trailing bytes without validating them. Both now snapshot up to `sizeof(sockaddr_storage)` bytes through `GuestSocketReadGuest_nid_no_patch` before conversion. Connect reads the datagram disconnect family from the same snapshot, so a failed address read cannot disconnect a UDP association. Failed reads return `0x8041010e` and 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 `getsockaddr` copies 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](https://github.com/boykopovar/AnyPS5/pull/11559#issuecomment-6425723155) 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: ```sh cmake --build build --target guest_net_address_fault_tests guest_sce_net_tests guest_net_buffer_validation_tests net_dontwait_tests net_blocking_send_tests --parallel 6 ctest --test-dir build -R '^(guest_net_address_fault_.*|guest_sce_net|guest_net_buffer_validation|net_dontwait_.*|public_headers)$' --output-on-failure python3 tools/check_conventions.py --base origin/main ``` 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](https://github.com/boykopovar/AnyPS5/pull/11559#issuecomment-6430700317)): head c96633ea5f merged onto main 74acfad65b without 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. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-27 00:21:15 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5660813583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11559#pullrequestreview-5660813583). Originally posted by [MarcZX10](https://github.com/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.
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!11559
No description provided.