Skip to content

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

Open
kattkaries wants to merge 2 commits into
boykopovar:mainfrom
kattkaries:fix/net-bind-connect-guest-address
Open

kattkaries wants to merge 2 commits into
boykopovar:mainfrom
kattkaries:fix/net-bind-connect-guest-address

Conversation

@kattkaries

Copy link
Copy Markdown

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 exact diff does not change our validation lines. #9834 implements HTTP transport. No open PR found implements this pointer-validation fix. The full pr_overlap tool was run. Its CMake insertion conflict with #10949 was resolved by moving our test registration; the rerun reports no direct overlaps. It could not compare six PRs that conflict with main (#5836, #7201, #9932, #9948, #11272, #11341); their actual branch diffs were inspected and do not change these address-read functions or introduce this helper.

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: afc780e. Rebased main: 263eee0. Final tested head: c96633e. 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. Windows, macOS and console behavior were not tested. 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

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5836 core/libs/prx/libSceNet/CMakeLists.txt
core/libs/prx/libSceNet/Export.cpp
PR 7201 core/libs/prx/libSceNet/Export.cpp
PR 9932 core/libs/prx/libSceNet/Export.cpp
PR 9948 core/libs/prx/libSceNet/Export.cpp
PR 11341 core/libs/prx/libSceNet/Export.cpp

@MarcZX10 MarcZX10 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.

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.

@BunnyFl

BunnyFl commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

A Windows run of c96633ea5f merged onto main 74acfad65b with no conflicts: Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON, each test run three times with ctest -V.

  • All eight guest_net_address_fault_* tests (bind and connect, each with 0, 1, 4 and 8) pass in all three runs.
  • Control: with only libSceNet/Export.cpp put back to main's version (this PR's test kept), all eight fail in all three runs: the 0, 1 and 4 cases with a segmentation fault, the 8 cases with exit 0xc0000409.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants