Skip to content

fix(libSceNet): reject nonpositive socket buffers - #9544

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Queuse:codex/net-buffer-validation
Oct 22, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Queuse:codex/net-buffer-validation

Conversation

@Queuse

@Queuse Queuse commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Reject nonpositive SO_SNDBUF and SO_RCVBUF values with EINVAL before changing the host socket or cached guest size. Previously zero/negative sizes reached the host, producing host-specific success or errors. This follows FreeBSD 11.4 sosetopt; PS5 validation and host buffer-limit differences remain in debt.

Tested

Windows 11 x86-64, WinLibs GCC 15.2.0 UCRT, Release. guest_net_buffer_validation fails on unchanged main and passes here. IPv4/IPv6 TCP/UDP tests reject zero, negative values and INT_MIN through both sceNet and kernel setters, verify guest and native buffer sizes stay unchanged, and check later valid sets, invalid pointers/lengths and descriptor precedence. The three new focused network tests pass together (3/3). Conventions and test-registration audit pass. No Linux, PS5 or title run.

Maintenance validation (2026-10-22): merged main b7d1d47a5f into f555d351c8. Conventions and whitespace checks pass. The focused target builds on Windows x86-64, MSYS2 UCRT64 GCC 16.2.0, Ninja, Release. Runtime validation is blocked: the host lacks required AVX2, FMA, BMI1/BMI2, LZCNT and MOVBE. Both guest_net_boolean_readback and the unchanged guest_sce_net fixture abort in the unchanged main startup guard before assertions. A collaborator needs to run the Build workflow for the refreshed head on a compatible runner. Earlier runtime results remain tied to their stated revisions. Overlap: #6879 only adds a system header to libSceNet, and #7201 changes macOS resolver handling; neither changes these socket options. The current #8362 head merges cleanly with #9544 and #9542 after its author moved the debt entry. Order with #6044 and #5836 is awaiting author confirmation; no agreement is assumed. Retain #9523 before #9542 and #9525 before #9543.

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

@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 the full diff against current main. The nonpositive guard runs after descriptor, level, pointer/length and option validation, before calling native setsockopt or updating the guest cached size; the test covers IPv4/IPv6, stream/datagram, sceNet and kernel paths, native/cached state preservation and valid follow-up calls. The overlap scanner found no current open-PR overlap. Hosted eligibility, conventions, intake, labels and report checks pass; product build jobs were skipped by path policy. Windows results and the focused 3/3 tests are reported by the author; I did not run a local build. Approved.

@github-actions

github-actions Bot commented Oct 22, 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
docs/dev/debt/libSceNet.md
PR 6044 core/libs/prx/libSceNet/CMakeLists.txt
PR 6879 core/libs/prx/libSceNet/Export.cpp
PR 7201 core/libs/prx/libSceNet/Export.cpp
PR 8254 core/libs/prx/libSceNet/CMakeLists.txt
core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md
PR 9060 core/libs/prx/libSceNet/Export.cpp
docs/dev/debt/libSceNet.md
PR 9651 docs/dev/debt/libSceNet.md

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

Linux run, since the description lists only Windows 11. On Linux the host accepts every nonpositive size, so the failure on main is a silent buffer change rather than an error.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04 (kernel 7.0.0-38), GCC 15.2, Release, BUILD_TESTING=ON. Head 4e7559ae9 merged --no-commit onto main ab347d144 (clean).

  • guest_net_buffer_validation passes, 3 of 3 runs. The other 20 libSceNet tests (guest_sce_net, net_dontwait_*, net_blocking_send, net_epoll_lifetime) pass with it.

  • Red→green: dropping only the new value < 1 line from sceNetSetsockopt and keeping the test aborts at line 58 (sceNetSetsockopt(..., invalid) == 0x80410116): the call returns 0 instead of EINVAL.

  • Why it returns 0 on Linux: the host setsockopt(SO_SNDBUF/SO_RCVBUF) never rejects a size. Measured on the same box with plain host sockets (IPv4 TCP/UDP, IPv6 TCP), after setting 32768 (read back as 65536):

    value setsockopt SO_SNDBUF read back SO_RCVBUF read back
    0 ok 4608 2304
    -1, -4096, INT_MIN ok 8388608 8388608

    Linux takes the int as unsigned and clamps it to wmem_max/rmem_max (4 MiB here, doubled), so without this PR a guest that passes -1 on Linux gets the largest host buffer, and 0 gets the smallest. The nativeBuffer() == originalNative checks in the test cover exactly that case, so the test guards it on Linux too.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@MarcZX10

Copy link
Copy Markdown
Contributor

I compared this against open #8362 on the exact shared debt file. The implementations/tests touch different functionality, but both branches add their debt entry at the same insertion point in docs/dev/debt/libSceNet.md; a pairwise three-way merge currently conflicts in that file. Please coordinate the merge order with #8362’s author and record the agreed order in the overlap note / Depends on if one PR must land first. The individual PR merges cleanly with current main, but its sync check is 1 ahead / 119 behind, so please also refresh it onto current main before merge.

MarrasFederico added a commit to MarrasFederico/AnyPS5 that referenced this pull request Oct 22, 2026
@Queuse

Queuse commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 I rechecked the updated #8362 head against this branch after merging current main (b7d1d47a5). The pairwise three-way merge is clean, including the debt file. @MarrasFederico's moved entry removes the insertion conflict, so neither PR needs to wait for the other. Thanks for sorting that out.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants