fix(libkernel): report copied socket address lengths #4295

Merged
AaravMehta-07 merged 1 commit from upstream-pr/4295 into main 2026-10-12 12:57:26 +00:00
AaravMehta-07 commented 2026-10-12 05:06:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-12T05:06:55Z.


What

Report the copied address length from libkernel's shared GuestAddress conversion instead of reporting 16/28 bytes when the caller supplied less space. This covers accept, getsockname, getpeername, recvfrom and recvmsg without changing the address bytes or the no-sender paths.

This addresses the remaining truncation gap noted in #3942, not that issue's already-fixed TCP sender-address bug. The reference is FreeBSD 11.4 uipc_syscalls.c: kern_accept4 clamps namelen to sa_len, kern_getsockname/kern_getpeername return MIN(*alen, sa_len), and kern_recvit reports the clamped msg_namelen. Console hardware behavior has not been measured.

The existing guest tests now check zero, one-byte, short, exact, oversized and UINT32_MAX capacities, address prefixes and untouched canaries. UDP exercises IPv4/IPv6 loopback, peeking and scatter/gather receives; TCP exercises both name queries and a one-byte accept address. IPv6 is skipped only for an unavailable family/loopback address.

Open-PR searches found no matching truncation fix. #4272 changes receive write guards elsewhere in the same source file; it does not change this conversion helper.

Tested

  • Windows 11, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON: full CMake configuration and full default build passed. The 14 networking/address CTest cases passed (^guest_(tcp|udp|poll|socket.*|dup|addresses|datagram.*|sce_net)$).
  • Red/green: both augmented tests abort with the original conversion and pass with the fix. Both pass ten repeated runs after the fix.
  • Ubuntu under WSL2, GCC 15.2.0, Release, BUILD_TESTING=ON: full CMake configuration and full default build passed. All 15 networking/address tests passed (the Windows selection plus guest_select); guest_tcp and guest_udp also pass ten repeated runs.
  • check_conventions.py passed with this title/body; pr_overlap.py --branch codex/kernel-socket-address-length --repo boykopovar/AnyPS5 reported no overlap with open pull requests.
  • These are guest-export loopback integration tests, not a commercial-title or console-hardware test.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4825165546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4295). Originally posted by [AaravMehta-07](https://github.com/AaravMehta-07) on 2026-10-12T05:06:55Z. --- ### What Report the copied address length from libkernel's shared `GuestAddress` conversion instead of reporting 16/28 bytes when the caller supplied less space. This covers `accept`, `getsockname`, `getpeername`, `recvfrom` and `recvmsg` without changing the address bytes or the no-sender paths. This addresses the remaining truncation gap noted in #3942, not that issue's already-fixed TCP sender-address bug. The reference is FreeBSD 11.4 [`uipc_syscalls.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_syscalls.c): `kern_accept4` clamps `namelen` to `sa_len`, `kern_getsockname`/`kern_getpeername` return `MIN(*alen, sa_len)`, and `kern_recvit` reports the clamped `msg_namelen`. Console hardware behavior has not been measured. The existing guest tests now check zero, one-byte, short, exact, oversized and `UINT32_MAX` capacities, address prefixes and untouched canaries. UDP exercises IPv4/IPv6 loopback, peeking and scatter/gather receives; TCP exercises both name queries and a one-byte accept address. IPv6 is skipped only for an unavailable family/loopback address. Open-PR searches found no matching truncation fix. #4272 changes receive write guards elsewhere in the same source file; it does not change this conversion helper. ### Tested - Windows 11, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`: full CMake configuration and full default build passed. The 14 networking/address CTest cases passed (`^guest_(tcp|udp|poll|socket.*|dup|addresses|datagram.*|sce_net)$`). - Red/green: both augmented tests abort with the original conversion and pass with the fix. Both pass ten repeated runs after the fix. - Ubuntu under WSL2, GCC 15.2.0, Release, `BUILD_TESTING=ON`: full CMake configuration and full default build passed. All 15 networking/address tests passed (the Windows selection plus `guest_select`); `guest_tcp` and `guest_udp` also pass ten repeated runs. - `check_conventions.py` passed with this title/body; `pr_overlap.py --branch codex/kernel-socket-address-length --repo boykopovar/AnyPS5` reported no overlap with open pull requests. - These are guest-export loopback integration tests, not a commercial-title or console-hardware test. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!4295
No description provided.