fix(libkernel): return EFAULT from accept for an address buffer without a length pointer #7485

Merged
Bonjourcestmatt merged 1 commit from upstream-pr/7485 into main 2026-11-08 09:59:13 +00:00
Bonjourcestmatt commented 2026-10-18 09:09:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-18T09:09:55Z.


What

accept with an address buffer but no length pointer now fails with EFAULT (14) instead of EINVAL (22), and that check now comes before the descriptor lookup. FreeBSD 11.4 accept1() (sys/kern/uipc_syscalls.c, release/11.4.0) returns early when the name is NULL; otherwise it does error = copyin(anamelen, &namelen, sizeof (namelen)); if (error != 0) return (error); before calling kern_accept4(), which is where getsock_cap() rejects a bad descriptor. So a missing length pointer reports EFAULT even on an invalid descriptor. A non-listening socket still fails with EINVAL, as kern_accept4() does on SO_ACCEPTCONN being clear.

Overlap: no open PR changes accept_nid_postfix (checked the diffs of all open PRs touching Socket/src/Udp.cpp, and tools/pr_overlap.py; #7140 and #6663 only call it in tests).

Tested

  • Windows 11, WinLibs GCC 15.2.0 UCRT, Release: guest_socket_connect_listening_tests has three new checks (EFAULT with a listening socket, EFAULT before EBADF, EBADF without an address); all 22 socket ctest tests pass and the full non-GPU suite passes (756 of 756, skipped ones included); python tools/check_conventions.py --base origin/main passes.
  • I did not run the new checks against main without the fix; the first one fails there by reading the old code (it returned 22).
  • Not run: Linux and macOS, no console. Only the FreeBSD source was used as reference; the console's behaviour is unverified.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4907835896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7485). Originally posted by [Bonjourcestmatt](https://github.com/Bonjourcestmatt) on 2026-10-18T09:09:55Z. --- ### What `accept` with an address buffer but no length pointer now fails with `EFAULT` (14) instead of `EINVAL` (22), and that check now comes before the descriptor lookup. FreeBSD 11.4 `accept1()` (`sys/kern/uipc_syscalls.c`, release/11.4.0) returns early when the name is NULL; otherwise it does `error = copyin(anamelen, &namelen, sizeof (namelen)); if (error != 0) return (error);` before calling `kern_accept4()`, which is where `getsock_cap()` rejects a bad descriptor. So a missing length pointer reports `EFAULT` even on an invalid descriptor. A non-listening socket still fails with `EINVAL`, as `kern_accept4()` does on `SO_ACCEPTCONN` being clear. Overlap: no open PR changes `accept_nid_postfix` (checked the diffs of all open PRs touching `Socket/src/Udp.cpp`, and `tools/pr_overlap.py`; #7140 and #6663 only call it in tests). ### Tested - Windows 11, WinLibs GCC 15.2.0 UCRT, Release: `guest_socket_connect_listening_tests` has three new checks (EFAULT with a listening socket, EFAULT before EBADF, EBADF without an address); all 22 socket ctest tests pass and the full non-GPU suite passes (756 of 756, skipped ones included); `python tools/check_conventions.py --base origin/main` passes. - I did not run the new checks against `main` without the fix; the first one fails there by reading the old code (it returned 22). - Not run: Linux and macOS, no console. Only the FreeBSD source was used as reference; the console's behaviour is unverified. ### 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-18 10:09:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T10:09:45Z.

Review: COMMENTED


Linux run, since the description lists only Windows and notes the new checks were not run against main.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head 5052a3f3b merged onto main 9caecfd2d (clean merge).

  • guest_socket_connect_listening passes with the three new checks, as do the other socket/network tests (ctest -R "socket|udp|tcp|accept", 16 tests).
  • GuestSocketConnectListening.cpp only, on main: fails at accept with an address buffer and no length pointer must fail with EFAULT (14) (errno 22), so the first new check catches the old order.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 712/712, same as main.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5562495615 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7485#pullrequestreview-5562495615). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T10:09:45Z. **Review:** COMMENTED --- Linux run, since the description lists only Windows and notes the new checks were not run against `main`. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `5052a3f3b` merged onto `main` `9caecfd2d` (clean merge). - `guest_socket_connect_listening` passes with the three new checks, as do the other socket/network tests (`ctest -R "socket|udp|tcp|accept"`, 16 tests). - `GuestSocketConnectListening.cpp` only, on `main`: fails at `accept with an address buffer and no length pointer must fail with EFAULT (14) (errno 22)`, so the first new check catches the old order. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 712/712, same as `main`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
xXPBSXx commented 2026-10-21 02:49:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T02:49:24Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_socket_connect_listening_tests; ctest -N -R guest_socket_connect_listening lists exactly one test.

Results (3 runs each):

  • PR head: guest_socket_connect_listening passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libkernel/Socket/src/Udp.cpp with the version from the PR's merge base (cdb7ed0355), then rebuilt. The test fails 3/3 (exit 0xc0000409, a failed Require). I restored the PR's file afterwards.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306775475 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7485#issuecomment-6306775475). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T02:49:24Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_socket_connect_listening_tests`; `ctest -N -R guest_socket_connect_listening` lists exactly one test. **Results (3 runs each):** - PR head: `guest_socket_connect_listening` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libkernel/Socket/src/Udp.cpp` with the version from the PR's merge base (`cdb7ed0355`), then rebuilt. The test fails 3/3 (exit 0xc0000409, a failed Require). I restored the PR's file afterwards. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
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!7485
No description provided.