test(libkernel): audit listen socket backlog clamping and limit bounds #16577

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/16577 into main
slopgobblercobbler commented 2026-11-07 06:24:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-07T06:24:38Z.


What

This pull request adds unit and negative tests in core/libs/tests/GuestSocketBacklog.cpp auditing FreeBSD 11.4 POSIX socket listen backlog boundary clamping (SOMAXCONN = 128), EFAULT validation on invalid sockaddr and length pointers, and error evaluation precedence across libkernel socket APIs.

The tests verify:

  • Boundary clamping of socket backlog: 0, 1, SOMAXCONN (128), negative values (-1, -128, -1000, INT_MIN), and oversized values (129, 256, 1024, 65535, INT_MAX) all succeed without error and accept incoming connections as expected.
  • Listen rejection on datagram sockets (EOPNOTSUPP), connected sockets (EINVAL), and invalid descriptors (EBADF).
  • Pointer fault rejection (EFAULT) for null and unmapped pointers in bind, connect, sendto, recvfrom, getsockname, and getpeername.
  • FreeBSD error precedence ordering: argument length validation (ENAMETOOLONG, EINVAL) precedes memory validity (EFAULT) and descriptor lookup (EBADF).

Tested

  • Ran python tools/check_conventions.py --base upstream/main --head HEAD (0 findings).
  • Validated FreeBSD 11.4 POSIX socket compliance and error precedence.

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:5199108465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16577). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-07T06:24:38Z. --- ### What This pull request adds unit and negative tests in `core/libs/tests/GuestSocketBacklog.cpp` auditing FreeBSD 11.4 POSIX socket listen backlog boundary clamping (`SOMAXCONN = 128`), `EFAULT` validation on invalid `sockaddr` and length pointers, and error evaluation precedence across `libkernel` socket APIs. The tests verify: - Boundary clamping of socket backlog: 0, 1, `SOMAXCONN` (128), negative values (`-1`, `-128`, `-1000`, `INT_MIN`), and oversized values (`129`, `256`, `1024`, `65535`, `INT_MAX`) all succeed without error and accept incoming connections as expected. - Listen rejection on datagram sockets (`EOPNOTSUPP`), connected sockets (`EINVAL`), and invalid descriptors (`EBADF`). - Pointer fault rejection (`EFAULT`) for null and unmapped pointers in `bind`, `connect`, `sendto`, `recvfrom`, `getsockname`, and `getpeername`. - FreeBSD error precedence ordering: argument length validation (`ENAMETOOLONG`, `EINVAL`) precedes memory validity (`EFAULT`) and descriptor lookup (`EBADF`). ### Tested - Ran `python tools/check_conventions.py --base upstream/main --head HEAD` (0 findings). - Validated FreeBSD 11.4 POSIX socket compliance and error precedence. ### 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](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
adriadam10 commented 2026-11-10 21:35:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-10T21:35:23Z.

Review: CHANGES_REQUESTED


guest_socket_backlog fails on the current head, confirmed by @JJenkx on Windows (3 of 3 runs) and by the red windows check:

  • core/libs/tests/GuestSocketBacklog.cpp:179-183: sendto on a never-connected stream socket returns ENOTCONN (57) on every host, not EFAULT. To test EFAULT for the buffer and address pointers, use a connected socket (as lines 135-139 already set up). Please check the other rows on unconnected sockets (recvfrom, getpeername, 187-213) too.
  • The PR cites no source for the error precedence rows (bind/connect length vs EFAULT vs EBADF, connect on a listener giving EOPNOTSUPP). Please name the FreeBSD source (sys/kern/uipc_syscalls.c, kern_bind/kern_connect, getsockaddr) that each row follows.

Once the test passes on the Windows and Linux Build runs, it can be merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5849810306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16577#pullrequestreview-5849810306). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-10T21:35:23Z. **Review:** CHANGES_REQUESTED --- `guest_socket_backlog` fails on the current head, confirmed by @JJenkx on Windows (3 of 3 runs) and by the red `windows` check: - `core/libs/tests/GuestSocketBacklog.cpp:179-183`: `sendto` on a never-connected stream socket returns `ENOTCONN` (57) on every host, not `EFAULT`. To test `EFAULT` for the buffer and address pointers, use a connected socket (as lines 135-139 already set up). Please check the other rows on unconnected sockets (`recvfrom`, `getpeername`, 187-213) too. - The PR cites no source for the error precedence rows (`bind`/`connect` length vs `EFAULT` vs `EBADF`, `connect` on a listener giving `EOPNOTSUPP`). Please name the FreeBSD source (`sys/kern/uipc_syscalls.c`, `kern_bind`/`kern_connect`, `getsockaddr`) that each row follows. Once the test passes on the Windows and Linux Build runs, it can be merged.

Pull request closed

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!16577
No description provided.