fix(libkernel): refuse TCP_MAXSEG before a connection and raise it to 216 as measured on a PS5 #11251

Merged
orezraey merged 1 commit from upstream-pr/11251 into main 2026-10-26 09:11:43 +00:00
orezraey commented 2026-10-25 22:40:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T22:40:49Z.


What

TCP_MAXSEG now follows a retail PS5 (firmware 13.60) in three ways:

  • it refuses any set on a socket without a peer;
  • it stores a set value raised to 216;
  • an AF_INET6 stream socket starts at 1220.

Measured with a homebrew probe from a payload process; the source and console log are in this gist (pmaxseg).

On the console:

  • Fresh AF_INET stream socket. Reads 536. Every set fails with EINVAL: 175, 176, 200, 400, 536, 537 and 1460. AnyPS5 accepted 176 to 536 here, and the debt entry said "no segment set succeeded there, so the rule here ... is not measured".
  • Fresh AF_INET6 stream socket. Reads 1220, FreeBSD's tcp_newtcpcb default. AnyPS5 read 536.
  • Connected loopback socket.
    • It reads 16344 (lo0's MTU of 16384 less 40), and the accepted end reads the same.
    • 175 fails. 176 succeeds and reads back 216. 200 then succeeds and reads 216. 400 and above fail.
    • That is FreeBSD 11.4's tcp_default_ctloutput rule (optval <= t_maxseg, optval + 40 >= V_tcp_minmss) with the stored value raised to V_tcp_minmss (216).

AnyPS5 now applies that rule only once the host socket has a peer (getpeername succeeds), stores max(value, 216), and starts AF_INET6 sockets (and sockets accepted from an AF_INET6 listener) at 1220.

Before the first set, a connected socket still reads 536 or 1220 where the console reads the negotiated segment, because the host's MSS for a peer differs between hosts. That gap now leads the debt entry, together with the unmeasured listening socket.

Before and after

TCP_MAXSEG PS5 AnyPS5 before AnyPS5 now
set on a fresh AF_INET stream socket (175 to 1460) EINVAL 176 to 536 accepted EINVAL
fresh AF_INET6 stream socket reads 1220 536 1220
set 176 on a connected socket, read back 216 176 216
set 175, or 400 and above, on a connected socket EINVAL EINVAL EINVAL
connected socket before any set reads negotiated segment (16344 on loopback) 536 or 1220 536 or 1220 (debt)

Tested

Windows 11, WinLibs GCC 15.2, full build. The 86 tests matching socket|tcp|udp|net_ pass 3 times out of 3, with select_tests excluded: it is a Python tool test that fails here for an unrelated temporary-directory reason. guest_socket_stream_options now checks:

  • a fresh socket fails 176, 300 and 536 and still reads 536;
  • an AF_INET6 socket reads 1220;
  • on the connected client, 176 and 200 read back 216 and 400 fails.

tools/check_conventions.py passes. Head ea02895cc0 on main b90d009d9f. On WSL Ubuntu with GCC 13, guest_socket_stream_options, guest_socket_options and guest_tcp pass 3 times out of 3 at the same head.

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:5009437788 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11251). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T22:40:49Z. --- ### What `TCP_MAXSEG` now follows a retail PS5 (firmware 13.60) in three ways: - it refuses any set on a socket without a peer; - it stores a set value raised to 216; - an `AF_INET6` stream socket starts at 1220. Measured with a homebrew probe from a payload process; the source and console log are in [this gist](https://gist.github.com/orezraey/236a0628ab38d8f0c1f0105c6c097beb) (`pmaxseg`). On the console: - **Fresh `AF_INET` stream socket.** Reads 536. Every set fails with `EINVAL`: 175, 176, 200, 400, 536, 537 and 1460. AnyPS5 accepted 176 to 536 here, and the debt entry said "no segment set succeeded there, so the rule here ... is not measured". - **Fresh `AF_INET6` stream socket.** Reads 1220, FreeBSD's `tcp_newtcpcb` default. AnyPS5 read 536. - **Connected loopback socket.** - It reads 16344 (lo0's MTU of 16384 less 40), and the accepted end reads the same. - 175 fails. 176 succeeds and reads back **216**. 200 then succeeds and reads 216. 400 and above fail. - That is FreeBSD 11.4's `tcp_default_ctloutput` rule (`optval <= t_maxseg`, `optval + 40 >= V_tcp_minmss`) with the stored value raised to `V_tcp_minmss` (216). AnyPS5 now applies that rule only once the host socket has a peer (`getpeername` succeeds), stores `max(value, 216)`, and starts `AF_INET6` sockets (and sockets accepted from an `AF_INET6` listener) at 1220. Before the first set, a connected socket still reads 536 or 1220 where the console reads the negotiated segment, because the host's MSS for a peer differs between hosts. That gap now leads the debt entry, together with the unmeasured listening socket. **Before and after** | `TCP_MAXSEG` | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | set on a fresh `AF_INET` stream socket (175 to 1460) | `EINVAL` | 176 to 536 accepted | `EINVAL` | | fresh `AF_INET6` stream socket reads | 1220 | 536 | 1220 | | set 176 on a connected socket, read back | 216 | 176 | 216 | | set 175, or 400 and above, on a connected socket | `EINVAL` | `EINVAL` | `EINVAL` | | connected socket before any set reads | negotiated segment (16344 on loopback) | 536 or 1220 | 536 or 1220 (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, WinLibs GCC 15.2, full build. The 86 tests matching `socket|tcp|udp|net_` pass 3 times out of 3, with `select_tests` excluded: it is a Python tool test that fails here for an unrelated temporary-directory reason. `guest_socket_stream_options` now checks: - a fresh socket fails 176, 300 and 536 and still reads 536; - an `AF_INET6` socket reads 1220; - on the connected client, 176 and 200 read back 216 and 400 fails. `tools/check_conventions.py` passes. Head `ea02895cc0` on `main` `b90d009d9f`. On WSL Ubuntu with GCC 13, `guest_socket_stream_options`, `guest_socket_options` and `guest_tcp` pass 3 times out of 3 at the same head. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:42:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:42:14Z.

Review: APPROVED


Reviewed the exact head ea02895cc071865dd32181ec74dcc4f217366503 against main b90d009d9f73354cbea239a74a8f7e2dcd138772. The linked firmware 13.60 probe source and console log support the changed cases: all tested TCP_MAXSEG sets fail before connection; connected 176 and 200 read back as 216, while 400 fails; fresh AF_INET6 reads 1220. The state update and address-family initialization match those observations, and the debt entry records the remaining connected-read/listener limitations. git diff --check and tools/check_conventions.py --base upstream/main pass. Hosted eligibility, intake, conventions, labels, and report checks pass; hosted product build/test jobs were skipped by path policy. The author reports a full Windows 11 build and 86 relevant tests passing three times; I did not independently run that guest test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645722394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11251#pullrequestreview-5645722394). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:42:14Z. **Review:** APPROVED --- Reviewed the exact head `ea02895cc071865dd32181ec74dcc4f217366503` against `main` `b90d009d9f73354cbea239a74a8f7e2dcd138772`. The linked firmware 13.60 probe source and console log support the changed cases: all tested TCP_MAXSEG sets fail before connection; connected 176 and 200 read back as 216, while 400 fails; fresh AF_INET6 reads 1220. The state update and address-family initialization match those observations, and the debt entry records the remaining connected-read/listener limitations. `git diff --check` and `tools/check_conventions.py --base upstream/main` pass. Hosted eligibility, intake, conventions, labels, and report checks pass; hosted product build/test jobs were skipped by path policy. The author reports a full Windows 11 build and 86 relevant tests passing three times; I did not independently run that guest test locally.
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!11251
No description provided.