fix(libSceNet): report copied socket address lengths #4613

Merged
EagleBearerYS merged 1 commit from upstream-pr/4613 into main 2026-10-13 15:30:35 +00:00
EagleBearerYS commented 2026-10-12 16:45:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-12T16:45:33Z.


What

sceNetAccept, sceNetGetsockname, sceNetGetpeername, sceNetRecvfrom and sceNetRecvmsg stored the full address length (16 or 28) even when the caller's buffer was shorter and only part of the address was copied. FreeBSD 11.4 stores the copied length, the smaller of the two: accept, recvfrom and recvmsg, getsockname and getpeername in sys/kern/uipc_syscalls.c. libkernel's socket calls do the same since #4295.

Call (IPv4) Capacity main length This branch
sceNetGetsockname 0, 1, 8, 15, 16, 28 16 for all 0, 1, 8, 15, 16, 16
sceNetRecvfrom 0, 1, 8, 16 16 for all 0, 1, 8, 16
sceNetAccept 1 16 1
sceNetGetpeername 0, 4, 16 16 for all 0, 4, 16

Tested

Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release, -DBUILD_TESTING=ON, on main at 2a5eca11:

  • With main's Export.cpp, the new CheckDatagramAddressLengths and CheckStreamAddressLengths in guest_sce_net abort (exit 0xc0000409); guest_sce_net passes on main itself, IPv6 checks included, so the abort is the new checks. With the change they pass, 20 runs in a row. The IPv6 half runs here (28-byte addresses).
  • All 128 tests registered in core/libs/prx/libc/CMakeLists.txt and core/libs/prx/libkernel/CMakeLists.txt that build on Windows pass, and so do the network tests (guest_datagram_recv, guest_datagram_recvfrom, guest_datagram_sceNetRecv, guest_datagram_sceNetRecvfrom, guest_udp, guest_resolver, guest_posix_filesystem).

Linux (Ubuntu 24.04, GCC 13.3, Release), base 33ae282e: the new CheckDatagramAddressLengths and CheckStreamAddressLengths in guest_sce_net abort on main (getsockname with capacity 0 reports 16) and pass with the change, 20/20; the IPv6 half was skipped there for want of an IPv6 loopback. The libSceNet, libc and libkernel tests are unchanged. Again on WSL2 (Ubuntu 24.04, GCC 13.3.0, Release with CI's configure flags), merged into main at c952c2b0e, now with the IPv6 half: they abort with main's Export.cpp and pass with the change, 20 runs in a row.

tools/check_conventions.py --base origin/main passes.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4832395006 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4613). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-12T16:45:33Z. --- ### What `sceNetAccept`, `sceNetGetsockname`, `sceNetGetpeername`, `sceNetRecvfrom` and `sceNetRecvmsg` stored the full address length (16 or 28) even when the caller's buffer was shorter and only part of the address was copied. FreeBSD 11.4 stores the copied length, the smaller of the two: [accept](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_syscalls.c#L464-L465), [recvfrom and recvmsg](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_syscalls.c#L1103), [getsockname](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_syscalls.c#L1592-L1593) and [getpeername](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_syscalls.c#L1695-L1696) in `sys/kern/uipc_syscalls.c`. libkernel's socket calls do the same since #4295. | Call (IPv4) | Capacity | `main` length | This branch | |---|---|---|---| | `sceNetGetsockname` | 0, 1, 8, 15, 16, 28 | 16 for all | 0, 1, 8, 15, 16, 16 | | `sceNetRecvfrom` | 0, 1, 8, 16 | 16 for all | 0, 1, 8, 16 | | `sceNetAccept` | 1 | 16 | 1 | | `sceNetGetpeername` | 0, 4, 16 | 16 for all | 0, 4, 16 | ### Tested Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release, `-DBUILD_TESTING=ON`, on `main` at 2a5eca11: - With `main`'s `Export.cpp`, the new `CheckDatagramAddressLengths` and `CheckStreamAddressLengths` in `guest_sce_net` abort (exit `0xc0000409`); `guest_sce_net` passes on `main` itself, IPv6 checks included, so the abort is the new checks. With the change they pass, 20 runs in a row. The IPv6 half runs here (28-byte addresses). - All 128 tests registered in `core/libs/prx/libc/CMakeLists.txt` and `core/libs/prx/libkernel/CMakeLists.txt` that build on Windows pass, and so do the network tests (`guest_datagram_recv`, `guest_datagram_recvfrom`, `guest_datagram_sceNetRecv`, `guest_datagram_sceNetRecvfrom`, `guest_udp`, `guest_resolver`, `guest_posix_filesystem`). Linux (Ubuntu 24.04, GCC 13.3, Release), base 33ae282e: the new `CheckDatagramAddressLengths` and `CheckStreamAddressLengths` in `guest_sce_net` abort on `main` (getsockname with capacity 0 reports 16) and pass with the change, 20/20; the IPv6 half was skipped there for want of an IPv6 loopback. The libSceNet, libc and libkernel tests are unchanged. Again on WSL2 (Ubuntu 24.04, GCC 13.3.0, Release with CI's configure flags), merged into `main` at c952c2b0e, now with the IPv6 half: they abort with `main`'s `Export.cpp` and pass with the change, 20 runs in a row. `tools/check_conventions.py --base origin/main` passes. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
adriadam10 commented 2026-10-13 14:44:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:44:28Z.


Checked the diff against FreeBSD's uipc_syscalls.c (accept, getsockname, getpeername, recvfrom and recvmsg all report the copied length). Ran the libSceNet/libs tests on Linux (green); guest_sce_net fails with Export.cpp reverted and passes with the change. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148187772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4613#issuecomment-6148187772). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:44:28Z. --- Checked the diff against FreeBSD's `uipc_syscalls.c` (accept, getsockname, getpeername, recvfrom and recvmsg all report the copied length). Ran the libSceNet/libs tests on Linux (green); `guest_sce_net` fails with `Export.cpp` reverted and passes with the change. Merging once the full Build is green.
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!4613
No description provided.