fix(libkernel): read accept's address length in before accepting and fail with EFAULT for unwritable outputs, as FreeBSD accept1 does #18166

Merged
roboterspinne merged 2 commits from upstream-pr/18166 into main 2026-11-15 22:37:22 +00:00
roboterspinne commented 2026-11-10 17:32:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-11-10T17:32:03Z.


What

accept_nid_postfix (core/libs/prx/libkernel/Socket/src/Udp.cpp:1756-1799 on main 3545fb6d4e, which 37f53259dd merges into this branch; line numbers below refer to 3545fb6d4e) checks only that the length pointer is not null when an address buffer is given (:1757, added by #7485). After the connection has been taken off the native queue and installed as a guest descriptor, it calls GuestAddress(peer, address, length) (:1794), which reads *length and writes the name and the new length through the raw guest pointers (:543-562). So an unreadable length pointer, a length on a read-only page or an unwritable address buffer crashes the host with an access violation instead of failing with EFAULT, and a length that cannot be read is only noticed after a connection was consumed. FreeBSD 11.4's accept1 (release/11.4.0, sys/kern/uipc_syscalls.c) calls kern_accept4 without touching anamelen when uname is NULL (lines 310-311), and otherwise does copyin(anamelen, &namelen) before kern_accept4 and returns its error (313-315, 317), so a fault there comes before the descriptor is looked up and before any connection is dequeued. After accepting it does copyout(name, uname, namelen) (328) and then copyout(&namelen, anamelen) (331-332), and on either error it closes the new descriptor with fdclose and returns the error (333-334). kern_accept4 clamps namelen to sa_len (464-465), which GuestAddress already does with min(*length, bytes[0]). The sibling calls in the same file already copy through the checked helpers: getsockname and getpeername read the capacity with GuestCopyIn_nid_no_patch (:1927, :1953) and write through CopyAddressOut (:1916-1924), recvfrom uses ReportAddress (defined at :540-541), and socketpair closes what it installed when its copyout fails (:1627-1649). GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch (core/libs/prx/libc/src/General.cpp:908, :864) reject a null or unusable range instead of faulting.

  • Rule. With an address buffer, accept reads the 4-byte capacity from length with GuestCopyIn_nid_no_patch before the descriptor lookup and fails with EFAULT (14) if it cannot. A null length still fails there, so the EFAULT order merged in #7485 is unchanged. After Install, the name is built in a local 28-byte buffer with GuestAddress (clamped to the capacity and to sa_len) and written with ReportAddress: the name (nothing when the size is 0), then the size. If either copyout fails, accept closes the new descriptor with GuestSockets::Close and fails with EFAULT. Without an address buffer the length pointer is ignored, as before. Valid pointers take the same path with the same results. sceNetAccept in libSceNet is not touched.
  • Tests. guest_socket_connect_listening gains a block after the existing #7485 checks. It maps three 16 KiB direct-memory pages (sceKernelAllocateDirectMemory, sceKernelMapDirectMemory), sets the second to prot 1 and the third to prot 0 with sceKernelMprotect, and checks: accept(-1, buf, unreadable length) fails with EFAULT, not EBADF; on a fresh listener with a pending client, an unreadable length fails with EFAULT and the next accept(l, NULL, NULL) still returns that connection (a byte sent by the client arrives on it); a length on the read-only page, and an address buffer on the read-only page and on the prot-0 page, each fail with EFAULT, and the client's next recv (5 s SO_RCVTIMEO) returns 0 or ECONNRESET, which shows the accepted socket was closed, since GuestSockets::Close is the only path that closes it; a capacity of 0 with the address buffer on the prot-0 page succeeds and reports 0, and a capacity of 8 reports 8 and copies only the first 8 bytes of the name; a valid 28-byte buffer reports length 16 and AF_INET as the positive control. Every new accept on the listener has a connection already queued, so nothing blocks; the test runs in under 2 s.
  • #12965. Open #12965 (deferred cancellation in POSIX accept) moves the body of accept_nid_postfix into a static Accept() and Install into the new wrapper, and keeps the raw if (address) GuestAddress(peer, address, length). It (head 99dee99565) already conflicts with main 3545fb6d4e in Udp.cpp in three places: the first lines of accept_nid_postfix, and the first lines of send_nid_postfix and of recv_nid_postfix, where main now begins with the forwarded-socket block (ForwardsFor). A trial merge with this branch conflicts in four places in Udp.cpp: those three (in the first, the capacity copy-in replaces the null check) and the end of the try block, where this branch replaces the GuestAddress line after Install. In #12965, File::WithIoDescriptor fails a negative descriptor with EBADF before Accept() runs, and peer is local to Accept(). Resolving it therefore means doing the capacity copy-in at the top of accept_nid_postfix, before WithIoDescriptor and the restart loop, having Accept() hand out the built name, and doing the copyout and the close on failure after Install in the wrapper.
  • Overlap. pr_overlap.py --branch, run on the merge commit 37f53259dd, lists #18476, opened after this PR: one conflict in Udp.cpp at the first lines of accept_nid_postfix (:1757), where #18476 adds the path for libSceNet-forwarded sockets directly after the null check this branch replaces. It is not a duplicate (#18476 handles forwarded sockets, this PR the native path, and both read the length in before accepting); whichever lands second keeps both changes. It cannot compare #11896, #12682, #12688, #12700, #12965, #17253 and #18167, which do not merge with main as their heads stand on GitHub. Checked by hand on 37f53259dd against main 3545fb6d4e: a trial merge of this branch with #11896 (ef5ae8ee90), #12682 (32121ca48d), #12688 (8f34999f2f), #12700 (bf740fcd27) and #17253 (c4491afb31) conflicts in the same files and the same Udp.cpp hunks as main with it, and with #12965 (99dee99565) in the same files, with the fourth Udp.cpp conflict described in the #12965 bullet above. #11896, #12682 and #17253 do not change accept_nid_postfix. #12688 and #12700 wrap the ::accept call in Transfer(..., TransferKind::Accept) between the two places this branch changes; accept_nid_postfix merges without a marker and both changes can be kept. #18167, by the same author, changes recvfrom; its merge commit b5b8dabba0 and 37f53259dd merge with each other without a conflict.

Tested

Windows 11, WinLibs GCC 15.2.0, build directory configured with Ninja, Release and BUILD_TESTING=ON. The results below are from before the merge unless they name 37f53259dd: they were taken on this branch's commit rebased onto c5488026ab, and b8194198cf, the parent of c37af635f3, changes none of Udp.cpp, GuestSocketConnectListening.cpp, General.cpp, GuestArena.cpp, GuestKqueue.cpp and core/libs/prx/libkernel/CMakeLists.txt against it (empty git diff --stat for them). 37f53259dd merges main 3545fb6d4e into the branch without conflicts; git diff 3545fb6d4ed 37f53259dd is the same change to the same two files. Between b8194198cf and 3545fb6d4e main changed Udp.cpp (#18767, #18811, #18472, #18474, #17248, #19520), General.cpp, GuestArena.cpp, GuestKqueue.cpp and core/libs/prx/libkernel/CMakeLists.txt, but not GuestSocketConnectListening.cpp and not the lines of accept_nid_postfix, ReportAddress, GuestAddress, GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch. Each test was built with cmake --build build --parallel 4 --target <targets> and run directly from build/tests, with build/core/libs/libs/unpatched and build/core/libs/libs prepended to PATH:

  • Counter-check, new test with Udp.cpp of c5488026ab: guest_socket_connect_listening_tests failed with accept must read the address length before the descriptor and fail with EFAULT (14) when it cannot (errno 9). With the earlier cases left out one at a time in a local copy of the test, the old library crashed on each later case with 0xc0000005: read of 0x0000000200008000 (unreadable length, pending client), write of 0x0000000200004000 (read-only length), write of 0x0000000200004040 (address on the read-only page) and write of 0x0000000200008000 (address on the prot-0 page).
  • With the change: guest_socket_connect_listening_tests passed in three runs.
  • Related tests, every libkernel test that calls accept_nid_postfix: built guest_net_kernel_forwards_tests guest_poll_tests guest_refused_connect_tests guest_socket_event_tests guest_socket_host_write_tests guest_socket_on_non_socket_tests guest_socket_options_tests guest_socket_port_zero_tests guest_socket_read_write_tests guest_socket_send_before_connect_tests guest_socket_stream_options_tests guest_socket_timeouts_tests guest_tcp_tests guest_udp_tests guest_underscore_entry_tests guest_socket_connect_listening_tests, then ran, each in its ctest working directory, the 30 command lines that ctest --test-dir build -N -V -R '^(guest_sce_net_kernel_forwards|guest_poll|guest_refused_connect|guest_socket_events|guest_socket_host_write_.*|guest_socket_on_non_socket|guest_socket_options|guest_socket_options_multicast|guest_socket_port_zero|guest_socket_read_write|guest_socket_send_before_connect|guest_socket_stream_options|guest_socket_timeouts|guest_tcp|guest_udp|guest_underscore_entr.*|guest_socket_connect_listening)$' lists: 30/30 passed, 10.21 s in total.
  • After the merge, on 37f53259dd, in a fresh build directory with the same options and the same sixteen targets: guest_socket_connect_listening passed in three runs (ctest --repeat until-fail:3), and the same 30 runs passed 30/30 (16.93 s in total). Counter-check on 37f53259dd with Udp.cpp checked out from 3545fb6d4e: guest_socket_connect_listening failed with accept must read the address length before the descriptor and fail with EFAULT (14) when it cannot (errno 9); with Udp.cpp restored it passed again.
  • Not run here: the Linux and macOS builds, although the test is registered on every host (core/libs/prx/libkernel/CMakeLists.txt:2376), so their CI runs it. There GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch use process_vm_readv/process_vm_writev and mach_vm_read_overwrite/mach_vm_write, and the non-Windows GuestArenaBeginHostWrite_nid_postfix (core/libs/prx/libc/src/GuestArena.cpp:941-949) only reapplies the guest's own protection and never makes a prot-1 page writable. The merged core/libs/tests/GuestKqueue.cpp:197-199, registered on every host, already expects EFAULT for a write to a prot-1 page.
  • python tools/check_conventions.py --base upstream/main --head HEAD (upstream main = 3545fb6d4e, HEAD at the merge commit 37f53259dd) with this title and description passed.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5245860485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18166). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-11-10T17:32:03Z. --- ### What `accept_nid_postfix` (`core/libs/prx/libkernel/Socket/src/Udp.cpp:1756-1799` on `main` 3545fb6d4ed, which 37f53259dd merges into this branch; line numbers below refer to 3545fb6d4ed) checks only that the length pointer is not null when an address buffer is given (`:1757`, added by #7485). After the connection has been taken off the native queue and installed as a guest descriptor, it calls `GuestAddress(peer, address, length)` (`:1794`), which reads `*length` and writes the name and the new length through the raw guest pointers (`:543-562`). So an unreadable length pointer, a length on a read-only page or an unwritable address buffer crashes the host with an access violation instead of failing with `EFAULT`, and a length that cannot be read is only noticed after a connection was consumed. FreeBSD 11.4's [`accept1`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/uipc_syscalls.c#L297-L338) (release/11.4.0, `sys/kern/uipc_syscalls.c`) calls `kern_accept4` without touching `anamelen` when `uname` is `NULL` (lines 310-311), and otherwise does `copyin(anamelen, &namelen)` before `kern_accept4` and returns its error (313-315, 317), so a fault there comes before the descriptor is looked up and before any connection is dequeued. After accepting it does `copyout(name, uname, namelen)` (328) and then `copyout(&namelen, anamelen)` (331-332), and on either error it closes the new descriptor with `fdclose` and returns the error (333-334). `kern_accept4` clamps `namelen` to `sa_len` (464-465), which `GuestAddress` already does with `min(*length, bytes[0])`. The sibling calls in the same file already copy through the checked helpers: `getsockname` and `getpeername` read the capacity with `GuestCopyIn_nid_no_patch` (`:1927`, `:1953`) and write through `CopyAddressOut` (`:1916-1924`), `recvfrom` uses `ReportAddress` (defined at `:540-541`), and `socketpair` closes what it installed when its copyout fails (`:1627-1649`). `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` (`core/libs/prx/libc/src/General.cpp:908`, `:864`) reject a null or unusable range instead of faulting. - **Rule.** With an address buffer, `accept` reads the 4-byte capacity from `length` with `GuestCopyIn_nid_no_patch` before the descriptor lookup and fails with `EFAULT` (14) if it cannot. A null length still fails there, so the `EFAULT` order merged in #7485 is unchanged. After `Install`, the name is built in a local 28-byte buffer with `GuestAddress` (clamped to the capacity and to `sa_len`) and written with `ReportAddress`: the name (nothing when the size is 0), then the size. If either copyout fails, `accept` closes the new descriptor with `GuestSockets::Close` and fails with `EFAULT`. Without an address buffer the length pointer is ignored, as before. Valid pointers take the same path with the same results. `sceNetAccept` in libSceNet is not touched. - **Tests.** `guest_socket_connect_listening` gains a block after the existing #7485 checks. It maps three 16 KiB direct-memory pages (`sceKernelAllocateDirectMemory`, `sceKernelMapDirectMemory`), sets the second to prot 1 and the third to prot 0 with `sceKernelMprotect`, and checks: `accept(-1, buf, unreadable length)` fails with `EFAULT`, not `EBADF`; on a fresh listener with a pending client, an unreadable length fails with `EFAULT` and the next `accept(l, NULL, NULL)` still returns that connection (a byte sent by the client arrives on it); a length on the read-only page, and an address buffer on the read-only page and on the prot-0 page, each fail with `EFAULT`, and the client's next `recv` (5 s `SO_RCVTIMEO`) returns 0 or `ECONNRESET`, which shows the accepted socket was closed, since `GuestSockets::Close` is the only path that closes it; a capacity of 0 with the address buffer on the prot-0 page succeeds and reports 0, and a capacity of 8 reports 8 and copies only the first 8 bytes of the name; a valid 28-byte buffer reports length 16 and `AF_INET` as the positive control. Every new `accept` on the listener has a connection already queued, so nothing blocks; the test runs in under 2 s. - **#12965.** Open #12965 (deferred cancellation in POSIX `accept`) moves the body of `accept_nid_postfix` into a static `Accept()` and `Install` into the new wrapper, and keeps the raw `if (address) GuestAddress(peer, address, length)`. It (head 99dee99565) already conflicts with `main` 3545fb6d4ed in `Udp.cpp` in three places: the first lines of `accept_nid_postfix`, and the first lines of `send_nid_postfix` and of `recv_nid_postfix`, where `main` now begins with the forwarded-socket block (`ForwardsFor`). A trial merge with this branch conflicts in four places in `Udp.cpp`: those three (in the first, the capacity copy-in replaces the null check) and the end of the `try` block, where this branch replaces the `GuestAddress` line after `Install`. In #12965, `File::WithIoDescriptor` fails a negative descriptor with `EBADF` before `Accept()` runs, and `peer` is local to `Accept()`. Resolving it therefore means doing the capacity copy-in at the top of `accept_nid_postfix`, before `WithIoDescriptor` and the restart loop, having `Accept()` hand out the built name, and doing the copyout and the close on failure after `Install` in the wrapper. - **Overlap.** `pr_overlap.py --branch`, run on the merge commit 37f53259dd, lists #18476, opened after this PR: one conflict in `Udp.cpp` at the first lines of `accept_nid_postfix` (`:1757`), where #18476 adds the path for libSceNet-forwarded sockets directly after the null check this branch replaces. It is not a duplicate (#18476 handles forwarded sockets, this PR the native path, and both read the length in before accepting); whichever lands second keeps both changes. It cannot compare #11896, #12682, #12688, #12700, #12965, #17253 and #18167, which do not merge with `main` as their heads stand on GitHub. Checked by hand on 37f53259dd against `main` 3545fb6d4ed: a trial merge of this branch with #11896 (ef5ae8ee90), #12682 (32121ca48d), #12688 (8f34999f2f), #12700 (bf740fcd27) and #17253 (c4491afb31) conflicts in the same files and the same `Udp.cpp` hunks as `main` with it, and with #12965 (99dee99565) in the same files, with the fourth `Udp.cpp` conflict described in the #12965 bullet above. #11896, #12682 and #17253 do not change `accept_nid_postfix`. #12688 and #12700 wrap the `::accept` call in `Transfer(..., TransferKind::Accept)` between the two places this branch changes; `accept_nid_postfix` merges without a marker and both changes can be kept. #18167, by the same author, changes `recvfrom`; its merge commit b5b8dabba0 and 37f53259dd merge with each other without a conflict. ### 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.0, build directory configured with Ninja, Release and `BUILD_TESTING=ON`. The results below are from before the merge unless they name 37f53259dd: they were taken on this branch's commit rebased onto c5488026ab, and b8194198cf9, the parent of c37af635f3, changes none of `Udp.cpp`, `GuestSocketConnectListening.cpp`, `General.cpp`, `GuestArena.cpp`, `GuestKqueue.cpp` and `core/libs/prx/libkernel/CMakeLists.txt` against it (empty `git diff --stat` for them). 37f53259dd merges `main` 3545fb6d4ed into the branch without conflicts; `git diff 3545fb6d4ed 37f53259dd` is the same change to the same two files. Between b8194198cf9 and 3545fb6d4ed `main` changed `Udp.cpp` (#18767, #18811, #18472, #18474, #17248, #19520), `General.cpp`, `GuestArena.cpp`, `GuestKqueue.cpp` and `core/libs/prx/libkernel/CMakeLists.txt`, but not `GuestSocketConnectListening.cpp` and not the lines of `accept_nid_postfix`, `ReportAddress`, `GuestAddress`, `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch`. Each test was built with `cmake --build build --parallel 4 --target <targets>` and run directly from `build/tests`, with `build/core/libs/libs/unpatched` and `build/core/libs/libs` prepended to `PATH`: - Counter-check, new test with `Udp.cpp` of c5488026ab: `guest_socket_connect_listening_tests` failed with `accept must read the address length before the descriptor and fail with EFAULT (14) when it cannot (errno 9)`. With the earlier cases left out one at a time in a local copy of the test, the old library crashed on each later case with `0xc0000005`: `read of 0x0000000200008000` (unreadable length, pending client), `write of 0x0000000200004000` (read-only length), `write of 0x0000000200004040` (address on the read-only page) and `write of 0x0000000200008000` (address on the prot-0 page). - With the change: `guest_socket_connect_listening_tests` passed in three runs. - Related tests, every libkernel test that calls `accept_nid_postfix`: built `guest_net_kernel_forwards_tests guest_poll_tests guest_refused_connect_tests guest_socket_event_tests guest_socket_host_write_tests guest_socket_on_non_socket_tests guest_socket_options_tests guest_socket_port_zero_tests guest_socket_read_write_tests guest_socket_send_before_connect_tests guest_socket_stream_options_tests guest_socket_timeouts_tests guest_tcp_tests guest_udp_tests guest_underscore_entry_tests guest_socket_connect_listening_tests`, then ran, each in its `ctest` working directory, the 30 command lines that `ctest --test-dir build -N -V -R '^(guest_sce_net_kernel_forwards|guest_poll|guest_refused_connect|guest_socket_events|guest_socket_host_write_.*|guest_socket_on_non_socket|guest_socket_options|guest_socket_options_multicast|guest_socket_port_zero|guest_socket_read_write|guest_socket_send_before_connect|guest_socket_stream_options|guest_socket_timeouts|guest_tcp|guest_udp|guest_underscore_entr.*|guest_socket_connect_listening)$'` lists: 30/30 passed, 10.21 s in total. - After the merge, on 37f53259dd, in a fresh build directory with the same options and the same sixteen targets: `guest_socket_connect_listening` passed in three runs (`ctest --repeat until-fail:3`), and the same 30 runs passed 30/30 (16.93 s in total). Counter-check on 37f53259dd with `Udp.cpp` checked out from 3545fb6d4ed: `guest_socket_connect_listening` failed with `accept must read the address length before the descriptor and fail with EFAULT (14) when it cannot (errno 9)`; with `Udp.cpp` restored it passed again. - Not run here: the Linux and macOS builds, although the test is registered on every host (`core/libs/prx/libkernel/CMakeLists.txt:2376`), so their CI runs it. There `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` use `process_vm_readv`/`process_vm_writev` and `mach_vm_read_overwrite`/`mach_vm_write`, and the non-Windows `GuestArenaBeginHostWrite_nid_postfix` (`core/libs/prx/libc/src/GuestArena.cpp:941-949`) only reapplies the guest's own protection and never makes a prot-1 page writable. The merged `core/libs/tests/GuestKqueue.cpp:197-199`, registered on every host, already expects `EFAULT` for a write to a prot-1 page. - `python tools/check_conventions.py --base upstream/main --head HEAD` (upstream `main` = 3545fb6d4ed, HEAD at the merge commit 37f53259dd) with this title and description passed. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
PrivacyOnion commented 2026-11-10 19:37:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-10T19:37:11Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c37af635f3:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • GitHub CI: failing check(s): pipe-write (macos-15-intel), pipe-write (macos-15).
  • Build: guest_socket_connect_listening_tests built cleanly.
  • CTest (guest_socket_connect_listening):
    1/1 Test #4410: guest_socket_connect_listening ...   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4410: guest_socket_connect_listening ...Subprocess aborted***Exception:   0.62 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that when address is non-null, GuestCopyIn_nid_no_patch safely copies in the 4-byte capacity from length before descriptor lookup, correctly returning EFAULT (14) rather than EBADF (9) when length is null or points to unmapped/unreadable memory.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that when address is null, length is ignored and not dereferenced, preserving FreeBSD kern_accept4 semantics where NULL address buffers do not inspect or fault on length pointers.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that the accepted peer address is constructed in a local 28-byte buffer (unsigned char name[28]{}) via GuestAddress and written out via ReportAddress(address, length, name, capacity); on copyout failure (unwritable buffer or read-only length), GuestSockets::Close(acceptedDescriptor) is called to prevent descriptor leaks and Fail(14) (EFAULT) is returned.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified edge-case truncation behavior where capacity == 0 skips address writing and succeeds with length 0, and where capacity < sa_len (e.g. 8 bytes) properly truncates the address without buffer overruns.
    • core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory protection tests (PROT_READ, PROT_NONE), confirming that pre-accept length faults leave pending client connections in the listener queue and post-accept copyout faults cleanly tear down the connection (observed by the client as EOF or ECONNRESET (54)).
    • AGENTS.md and Conventions: Verified strict adherence to project rules, ensuring zero comments in modified code, proper conventional commit formatting, correct error return values, and complete socket/memory resource cleanup across all test cases.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5848171777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18166#pullrequestreview-5848171777). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-10T19:37:11Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c37af635f3`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **GitHub CI**: failing check(s): `pipe-write (macos-15-intel)`, `pipe-write (macos-15)`. - **Build**: `guest_socket_connect_listening_tests` built cleanly. - **CTest** (`guest_socket_connect_listening`): ``` 1/1 Test #4410: guest_socket_connect_listening ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/Udp.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4410: guest_socket_connect_listening ...Subprocess aborted***Exception: 0.62 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that when address is non-null, GuestCopyIn_nid_no_patch safely copies in the 4-byte capacity from length before descriptor lookup, correctly returning EFAULT (14) rather than EBADF (9) when length is null or points to unmapped/unreadable memory. - core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that when address is null, length is ignored and not dereferenced, preserving FreeBSD kern_accept4 semantics where NULL address buffers do not inspect or fault on length pointers. - core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified that the accepted peer address is constructed in a local 28-byte buffer (unsigned char name[28]{}) via GuestAddress and written out via ReportAddress(address, length, name, capacity); on copyout failure (unwritable buffer or read-only length), GuestSockets::Close(acceptedDescriptor) is called to prevent descriptor leaks and Fail(14) (EFAULT) is returned. - core/libs/prx/libkernel/Socket/src/Udp.cpp (accept_nid_postfix): Verified edge-case truncation behavior where capacity == 0 skips address writing and succeeds with length 0, and where capacity < sa_len (e.g. 8 bytes) properly truncates the address without buffer overruns. - core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory protection tests (PROT_READ, PROT_NONE), confirming that pre-accept length faults leave pending client connections in the listener queue and post-accept copyout faults cleanly tear down the connection (observed by the client as EOF or ECONNRESET (54)). - AGENTS.md and Conventions: Verified strict adherence to project rules, ensuring zero comments in modified code, proper conventional commit formatting, correct error return values, and complete socket/memory resource cleanup across all test cases. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 20:23:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:23:45Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 37f53259dd:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_socket_connect_listening_tests built cleanly.
  • CTest (guest_socket_connect_listening):
    1/1 Test #4814: guest_socket_connect_listening ...   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4814: guest_socket_connect_listening ...Subprocess aborted***Exception:   0.39 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified accept_nid_postfix reads the 4-byte length into capacity via GuestCopyIn_nid_no_patch prior to descriptor lookup when address is non-null, failing immediately with EFAULT (14) before consuming any pending connection on the listen queue.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that when address is nullptr, length is ignored and accept returns the accepted descriptor without dereferencing or copying address structures, matching FreeBSD accept1 and POSIX semantics.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that peer address reporting builds into a local 28-byte stack buffer (name) via GuestAddress, clamping size to capacity, and writes out via ReportAddress (GuestCopyOut_nid_no_patch) for both address and length.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that if ReportAddress fails on unwritable address or length buffers, accept_nid_postfix tears down the accepted descriptor cleanly via GuestSockets::Close before returning EFAULT (14).
    • core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory test coverage with sceKernelMprotect (prot 1 and prot 0) checking EFAULT precedence over EBADF, non-dequeue of pending clients on unreadable length, descriptor close on unwritable outputs, clamping to 0 and 8 bytes, positive AF_INET control, and full direct memory release.
    • Codebase rules & AGENTS.md: Verified zero comments added to Udp.cpp and GuestSocketConnectListening.cpp, no undefined behavior, no special-casing, and clean cross-platform LP64/LLP64 type safety.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912735481 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18166#pullrequestreview-5912735481). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:23:45Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `37f53259dd`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_socket_connect_listening_tests` built cleanly. - **CTest** (`guest_socket_connect_listening`): ``` 1/1 Test #4814: guest_socket_connect_listening ... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/Udp.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4814: guest_socket_connect_listening ...Subprocess aborted***Exception: 0.39 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified accept_nid_postfix reads the 4-byte length into capacity via GuestCopyIn_nid_no_patch prior to descriptor lookup when address is non-null, failing immediately with EFAULT (14) before consuming any pending connection on the listen queue. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that when address is nullptr, length is ignored and accept returns the accepted descriptor without dereferencing or copying address structures, matching FreeBSD accept1 and POSIX semantics. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that peer address reporting builds into a local 28-byte stack buffer (name) via GuestAddress, clamping size to capacity, and writes out via ReportAddress (GuestCopyOut_nid_no_patch) for both address and length. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that if ReportAddress fails on unwritable address or length buffers, accept_nid_postfix tears down the accepted descriptor cleanly via GuestSockets::Close before returning EFAULT (14). - core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory test coverage with sceKernelMprotect (prot 1 and prot 0) checking EFAULT precedence over EBADF, non-dequeue of pending clients on unreadable length, descriptor close on unwritable outputs, clamping to 0 and 8 bytes, positive AF_INET control, and full direct memory release. - Codebase rules & AGENTS.md: Verified zero comments added to Udp.cpp and GuestSocketConnectListening.cpp, no undefined behavior, no special-casing, and clean cross-platform LP64/LLP64 type safety. Looks Good To Me
PrivacyOnion commented 2026-11-15 20:23:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T20:23:45Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 37f53259dd:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_socket_connect_listening_tests built cleanly.
  • CTest (guest_socket_connect_listening):
    1/1 Test #4814: guest_socket_connect_listening ...   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4814: guest_socket_connect_listening ...Subprocess aborted***Exception:   0.39 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified accept_nid_postfix reads the 4-byte length into capacity via GuestCopyIn_nid_no_patch prior to descriptor lookup when address is non-null, failing immediately with EFAULT (14) before consuming any pending connection on the listen queue.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that when address is nullptr, length is ignored and accept returns the accepted descriptor without dereferencing or copying address structures, matching FreeBSD accept1 and POSIX semantics.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that peer address reporting builds into a local 28-byte stack buffer (name) via GuestAddress, clamping size to capacity, and writes out via ReportAddress (GuestCopyOut_nid_no_patch) for both address and length.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that if ReportAddress fails on unwritable address or length buffers, accept_nid_postfix tears down the accepted descriptor cleanly via GuestSockets::Close before returning EFAULT (14).
    • core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory test coverage with sceKernelMprotect (prot 1 and prot 0) checking EFAULT precedence over EBADF, non-dequeue of pending clients on unreadable length, descriptor close on unwritable outputs, clamping to 0 and 8 bytes, positive AF_INET control, and full direct memory release.
    • Codebase rules & AGENTS.md: Verified zero comments added to Udp.cpp and GuestSocketConnectListening.cpp, no undefined behavior, no special-casing, and clean cross-platform LP64/LLP64 type safety.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912735503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18166#pullrequestreview-5912735503). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:23:45Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `37f53259dd`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_socket_connect_listening_tests` built cleanly. - **CTest** (`guest_socket_connect_listening`): ``` 1/1 Test #4814: guest_socket_connect_listening ... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/Udp.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4814: guest_socket_connect_listening ...Subprocess aborted***Exception: 0.39 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified accept_nid_postfix reads the 4-byte length into capacity via GuestCopyIn_nid_no_patch prior to descriptor lookup when address is non-null, failing immediately with EFAULT (14) before consuming any pending connection on the listen queue. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that when address is nullptr, length is ignored and accept returns the accepted descriptor without dereferencing or copying address structures, matching FreeBSD accept1 and POSIX semantics. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that peer address reporting builds into a local 28-byte stack buffer (name) via GuestAddress, clamping size to capacity, and writes out via ReportAddress (GuestCopyOut_nid_no_patch) for both address and length. - core/libs/prx/libkernel/Socket/src/Udp.cpp: Verified that if ReportAddress fails on unwritable address or length buffers, accept_nid_postfix tears down the accepted descriptor cleanly via GuestSockets::Close before returning EFAULT (14). - core/libs/tests/GuestSocketConnectListening.cpp: Verified direct memory test coverage with sceKernelMprotect (prot 1 and prot 0) checking EFAULT precedence over EBADF, non-dequeue of pending clients on unreadable length, descriptor close on unwritable outputs, clamping to 0 and 8 bytes, positive AF_INET control, and full direct memory release. - Codebase rules & AGENTS.md: Verified zero comments added to Udp.cpp and GuestSocketConnectListening.cpp, no undefined behavior, no special-casing, and clean cross-platform LP64/LLP64 type safety. Looks Good To Me
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!18166
No description provided.