Skip to content

fix(libSceNet): ignore the address of sceNetSendto on a connected stream socket, as libkernel's sendto does - #2350

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28633
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28633

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28633, originally opened by Dr-Coconut.

Source commit: fa81b157f1f5db643709c539a89d3b8993146cff. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

libkernel's sendto ignores the address on a connected stream socket once its length passes (2 to 255 bytes) and it can be read, as FreeBSD 11.4's tcp_usr_send only connects to it on a socket that is not yet connected. sceNetSendto (and sceNetSendmsg, which calls it) converted and checked the address anyway, so an address of the other family failed with EAFNOSUPPORT and a short one with EINVAL. libkernel's debt entry for calls it forwards to a libSceNet socket lists this ("a destination on a connected stream is not ignored").

On a stream socket whose host socket has a peer, sceNetSendto with an address now fails a length above 255 with ENAMETOOLONG and below 2 with EINVAL, reads the address (EFAULT if it cannot), and then sends as it does without one. Other sockets are unchanged. The check calls getpeername inline rather than through a helper, because boykopovar#28534 adds a PeerConnected helper to the same file.

GuestSceNet.cpp gets CheckConnectedStreamSendto: on a connected IPv4 TCP client, sceNetSendto with an AF_INET6 address and with an IPv4 address of another host and port, and sceNetSendmsg with the AF_INET6 name, all reach the peer; lengths 1 and 256 fail with EINVAL and ENAMETOOLONG, and an unreadable address with EFAULT. The fragment adds a libSceNet entry and drops the sentence from the libkernel entry.

Tested

Commit fa81b15 on main 4a7fd1c, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/46832768421

  • Windows (GitHub-hosted windows-latest, image windows-2025-vs2026, WinLibs GCC 15.2.0 15.2.0posix-14.0.0-ucrt-r7) and Linux (GitHub-hosted ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change: guest_sce_net passes, and so do the eight guest_net_address_fault_* tests.
  • Both, with libSceNet's Export.cpp restored to main and the new case kept: guest_sce_net fails at line 2247, the sceNetSendto with the AF_INET6 address, with EAFNOSUPPORT (47); the controls pass.

Not run on macOS. No title tested. tools/check_conventions.py passes and tools/debt_fold.py --check accepts the fragment. tools/pr_overlap.py --branch reported no overlap among the open pull requests it could merge; it could not compare eight that conflict with main. Compared by hand: boykopovar#12682, boykopovar#12688, boykopovar#12700 and boykopovar#12965 rework blocking transfers and connects on Windows; boykopovar#5836 adds peer-socket types; boykopovar#16826 keeps close-on-exec in fcntl; boykopovar#18108 changes socket options; boykopovar#23975 adds a DNS override. None of them changes how sceNetSendto treats an address on a connected stream socket.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Sending data on an already connected stream socket now works when a destination address is supplied; the data is sent over the existing connection.
    • Invalid destination lengths and unreadable addresses now return appropriate errors.
  • Tests
    • Added coverage for connected stream sends, including destination address and input validation cases.
  • Documentation
    • Added notes describing connected stream socket behavior.

…eam socket, as libkernel's sendto does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Connected stream sendto

Layer / File(s) Summary
Connected sendto validation and coverage
core/libs/prx/libSceNet/Export.cpp, core/libs/tests/GuestSceNet.cpp, docs/dev/debt/changes/fix-libscenet-sendto-connected-stream.md
For a connected stream socket, sceNetSendto validates the supplied destination and uses the connected socket to send. The test checks sceNetSendto and sceNetSendmsg delivery and errors for invalid destination inputs. The debt note describes related socket-hook details.

Possibly related PRs

  • Thimo188/AnyPS5#2271: Adds multicast address refusal in sceNetBind and sceNetConnect in the same file, and may share helper or merge-order considerations.

Change: Bug fix

Merge Risk: Minimal · up to fa81b

This change makes sendto on a connected stream socket ignore the supplied destination after validating it, and it adds test coverage. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to fa81b

libSceNet accepts more destination values on an already-connected stream, but those values cannot redirect the send. The host socket still determines the recipient, and libSceNet rejects an invalid length or unreadable address before sending.

Security review details

Security Blast Radius

  • inferred — The PR broadens which calls can write to an existing stream, not which remote endpoints those calls can reach. A caller that can use the descriptor could already send to its connected peer by omitting the destination.

Trust Boundaries and Controls

  • observed — The guest supplies the descriptor, destination pointer, and length. libSceNet resolves the descriptor and bounds the guest-memory read before sending; the host socket, not the supplied address, controls the recipient on the connected branch.

Resilience and Maintainability Implications

  • inferred — If a close interrupts the send after the peer check, the in-flight operation still holds the original native handle; it does not look up a replacement socket by the guest descriptor or retry using the discarded destination.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 3
  • Waived: $0.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f94cb91b-8f9f-4b35-88f2-6b7c8bdbceaa
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and fa81b15.

Files selected for processing: 3

  • core/libs/prx/libSceNet/Export.cpp
  • core/libs/tests/GuestSceNet.cpp
  • docs/dev/debt/changes/fix-libscenet-sendto-connected-stream.md

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

Labels

docs Documentation prx Other PRX libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants