fix(libSceNet): reject nonpositive socket buffers #9544

Merged
Queuse merged 2 commits from upstream-pr/9544 into main 2026-10-22 21:54:58 +00:00
Queuse commented 2026-10-22 01:12:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-22T01:12:22Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4960555910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9544). Originally posted by [Queuse](https://github.com/Queuse) on 2026-10-22T01:12:22Z. --- ### 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](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_socket.c#L2494-L2509); PS5 validation and host buffer-limit differences remain in debt. ### 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. --> 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 <!-- 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-22 01:16:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:16:00Z.

Review: APPROVED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608149389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9544#pullrequestreview-5608149389). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T01:16:00Z. **Review:** APPROVED --- 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.
jotitadev commented 2026-10-22 04:33:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T04:33:56Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609299573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9544#pullrequestreview-5609299573). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T04:33:56Z. **Review:** COMMENTED --- 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 commented 2026-10-22 11:33:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:33:18Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339716953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9544#issuecomment-6339716953). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:33:18Z. --- 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.
Queuse commented 2026-10-22 15:26:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-22T15:26:36Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6344506856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9544#issuecomment-6344506856). Originally posted by [Queuse](https://github.com/Queuse) on 2026-10-22T15:26:36Z. --- @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 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!9544
No description provided.