fix(libkernel): let recvfrom with an address buffer and no length pointer receive without the address, as FreeBSD 11.4 does #18167

Merged
roboterspinne merged 2 commits from upstream-pr/18167 into main 2026-11-16 05:44:43 +00:00
roboterspinne commented 2026-11-10 17:32:19 +00:00 (Migrated from github.com)

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


What

recvfrom(s, buf, len, flags, from, NULL) (an address buffer but no length pointer) fails with EFAULT before it receives anything, on the native path (core/libs/prx/libkernel/Socket/src/Udp.cpp:2066 on b8194198cf; line numbers below refer to it) and on the path forwarded to a libSceNet socket (Udp.cpp:2053; on main dc19132bac the two checks are at Udp.cpp:2107 and :2094): both run if ((!buffer && length) || (address && !addressLength)) return Fail(14);. FreeBSD 11.4, the kernel behind the PS5's recvfrom, receives such a call normally; this is read from the FreeBSD source and not measured on the console. sys_recvfrom copies in *fromlenaddr only when fromlenaddr is not NULL and otherwise sets msg_namelen = 0, keeps msg_name = from and calls recvit. kern_recvit then sets the address length to 0 because msg_namelen <= 0, so no address is copied out. recvit writes the length back only if (namelenp != NULL). The call returns the byte count and writes neither from nor a length. The check came in with 9cbefb7e04 (tracked UDP sockets) and was carried over to the forwarded path by 7a4fa3865b; neither cites a console measurement, and docs/dev/debt/libkernel.md has no entry for it.

  • Rule. recvfrom no longer rejects a non-null from with a null fromlen; it receives as usual and returns the byte count without writing from. The rest of recvfrom already handles a null length pointer: the native path writes the address only through ReportAddress (Udp.cpp:533-535), and every call to it is behind addressLength (:2071, :2078, if (!addressLength) return result; at :2098). The forwarded path hands libSceNet its own name buffer and reported (= 0, because capacity stays 0) and returns at if (!addressLength) return received; (:2059); sceNetRecvfrom with a zero length writes no address (core/libs/prx/libSceNet/Export.cpp:1615-1617, native_to_guest_address at :309). These cases still fail with EFAULT: an unreadable fromlen (the copy-in at Udp.cpp:2049, as copyin fails in sys_recvfrom); an unwritable from with a nonzero *fromlen, after the receive, through ReportAddress (:2060, :2110), as the address copyout fails in kern_recvit (covered by core/libs/tests/GuestUdp.cpp:482-484); and a null buffer with a nonzero length. That last one faults here before the receive, where FreeBSD faults only on copyout; the timing is a separate topic and stays as it is. Also unchanged: libSceNet's own sceNetRecvfrom, which rejects the same pair with NET_EINVAL (Export.cpp:1598) as an SCE API, and accept and getsockname, where FreeBSD requires the length pointer.
  • Tests. guest_sce_net_kernel_forwards (core/libs/tests/GuestNetKernelForwards.cpp) runs CheckDatagram and CheckArguments for a native socket and for a libSceNet socket, so both paths are covered. CheckDatagram gains a case after the existing capacity loop and the receive without an address: it sends a datagram, clears the receive buffer, and receives with a 16-byte from filled with 0xAA and a null length pointer; the call must return the payload size, deliver the payload, and leave from unchanged. #18474, merged after this PR was opened, added connect checks at the same place; the merge with main (b5b8dabba0) keeps both blocks unchanged and puts this case first (GuestNetKernelForwards.cpp:77-83 on b5b8dabba0, the connect checks at :84-91), because the case sends with a destination address and FreeBSD 11.4's udp_output refuses that with EISCONN once the UDP socket is connected. The old EFAULT assertion for this pair in CheckArguments (GuestNetKernelForwards.cpp:108 on b8194198cf, :135 on b5b8dabba0) would now block on the bound, empty UDP socket, so it uses MSG_DONTWAIT (0x80) and expects EAGAIN (35), as the assertion at :113 (:140) does, and requires the address buffer local unchanged. The EFAULT cases for an unreadable length pointer (:109-110, :136-137) stay.
  • Overlap. pr_overlap.py --branch, run on the merge commit b5b8dabba0, reports no shared lines or exports with the open pull requests it can compare. It cannot compare #11896, #12682, #12688, #12700, #12965 and #17253, which share core/libs/prx/libkernel/Socket/src/Udp.cpp but do not merge with main. Checked by hand on b5b8dabba0 against main dc19132bac: a trial merge of this branch with each of them conflicts in the same files as main with it (identical sets for all six), and the Udp.cpp conflicts are the same hunks with and without this branch (five for #11896, three for #12965, two for #12700, one each for #12682, #12688 and #17253), and none of them touches the two changed (address && !addressLength) lines. None of the six changes the (address && !addressLength) check in recvfrom or edits GuestNetKernelForwards.cpp, so none implements this change. #16577 (a test-only audit of listen backlogs) asserted the old behaviour (core/libs/tests/GuestSocketBacklog.cpp:189 on its branch required recvfrom with an address buffer and a null length pointer to fail with EFAULT); it was closed unmerged on 2026-11-11, and main does not contain that file. #7507 proposed the same change earlier and was closed unmerged on 2026-11-02 by its author, after #13756 (merged) reworked the recvfrom EFAULT handling; its review found that removing the check let the ReceiveAnsweredHere early return write through a null length pointer. On b8194198cf every write of the length is guarded by addressLength (Udp.cpp:2059, :2071, :2078, :2098; on b5b8dabba0 :2100, :2112, :2119, :2145), so that case cannot recur.

Tested

Windows 11, WinLibs GCC 15.2.0, build directory configured with Ninja, Release and BUILD_TESTING=ON, on this branch based on c5488026ab; the rebase onto b8194198cf changes none of the files this change touches or this text cites (git diff --stat between the two bases is empty for them), so the runs below were not repeated. Each test executable was run from build/tests with build/core/libs/libs/unpatched, build/core/libs/libs and the MinGW bin on PATH:

  • Counter-check, new test with the library of c5488026ab (the two Udp.cpp lines put back): cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests, then guest_net_kernel_forwards_tests.exe aborted with failed at line 82, errno 14, the new recvfrom(receiver, received, sizeof(received), 0, from.data(), nullptr) assertion on the native socket.
  • With the change: cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests guest_udp_tests guest_socket_address_length_tests guest_socket_timeouts_tests guest_tcp_tests guest_socket_pair_tests guest_socket_on_non_socket_tests guest_underscore_entry_tests guest_datagram_receive_tests guest_socket_host_write_tests, then the eight executables guest_net_kernel_forwards_tests (0.35 s), guest_udp_tests, guest_socket_address_length_tests, guest_socket_timeouts_tests, guest_tcp_tests, guest_socket_pair_tests, guest_socket_on_non_socket_tests and guest_underscore_entry_tests passed 8/8, and the 18 runs registered as guest_datagram_* and guest_socket_host_write_* (guest_datagram_receive_tests with recv, recvfrom, sceNetRecv, sceNetRecvfrom; guest_socket_host_write_tests with recv, recvfrom, read, sceKernelRead, sceNetRecv, sceNetRecvfrom, sceNetRecvmsg, each for UDP and with tcp) passed 18/18.
  • After the merge with main dc19132bac in b5b8dabba0, which the two runs above predate: git reported one conflict, the CheckDatagram hunk described under Tests; Udp.cpp merged without one and differs from main only in the two changed lines (git diff dc19132bac2 b5b8dabba0 --stat: 2 files changed, 11 insertions(+), 3 deletions(-)). In a fresh build directory with the same options, the ten targets above built, and the same 26 runs passed 26/26 in one ctest run (guest_sce_net_kernel_forwards, guest_udp, guest_socket_address_length, guest_socket_timeouts, guest_tcp, guest_socket_pair, guest_socket_on_non_socket, guest_underscore_entries and the 18 guest_datagram_* and guest_socket_host_write_* runs). Counter-check on b5b8dabba0 with Udp.cpp checked out from dc19132bac: guest_sce_net_kernel_forwards aborted with failed at line 82, errno 14, the new assertion; with Udp.cpp restored it passed again.
  • The FreeBSD lines were read in sys/kern/uipc_syscalls.c and sys/netinet/udp_usrreq.c fetched from release/11.4.0.
  • Not run here: the Linux and macOS builds; the changed lines are shared by all hosts.
  • python tools/check_conventions.py --base upstream/main --head HEAD (upstream main = dc19132bac, HEAD at the merge commit b5b8dabba0) 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:5245864112 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18167). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-11-10T17:32:19Z. --- ### What `recvfrom(s, buf, len, flags, from, NULL)` (an address buffer but no length pointer) fails with `EFAULT` before it receives anything, on the native path (`core/libs/prx/libkernel/Socket/src/Udp.cpp:2066` on b8194198cf; line numbers below refer to it) and on the path forwarded to a libSceNet socket (`Udp.cpp:2053`; on `main` dc19132bac2 the two checks are at `Udp.cpp:2107` and `:2094`): both run `if ((!buffer && length) || (address && !addressLength)) return Fail(14);`. FreeBSD 11.4, the kernel behind the PS5's `recvfrom`, receives such a call normally; this is read from the FreeBSD source and not measured on the console. [`sys_recvfrom`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1214-L1229) copies in `*fromlenaddr` only when `fromlenaddr` is not NULL and otherwise sets `msg_namelen = 0`, keeps `msg_name = from` and calls `recvit`. [`kern_recvit`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1097-L1100) then sets the address length to 0 because `msg_namelen <= 0`, so no address is copied out. [`recvit`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_syscalls.c#L1188-L1194) writes the length back only `if (namelenp != NULL)`. The call returns the byte count and writes neither `from` nor a length. The check came in with 9cbefb7e04 (tracked UDP sockets) and was carried over to the forwarded path by 7a4fa3865b; neither cites a console measurement, and `docs/dev/debt/libkernel.md` has no entry for it. - **Rule.** `recvfrom` no longer rejects a non-null `from` with a null `fromlen`; it receives as usual and returns the byte count without writing `from`. The rest of `recvfrom` already handles a null length pointer: the native path writes the address only through `ReportAddress` (`Udp.cpp:533-535`), and every call to it is behind `addressLength` (`:2071`, `:2078`, `if (!addressLength) return result;` at `:2098`). The forwarded path hands libSceNet its own `name` buffer and `reported` (= 0, because `capacity` stays 0) and returns at `if (!addressLength) return received;` (`:2059`); `sceNetRecvfrom` with a zero length writes no address (`core/libs/prx/libSceNet/Export.cpp:1615-1617`, `native_to_guest_address` at `:309`). These cases still fail with `EFAULT`: an unreadable `fromlen` (the copy-in at `Udp.cpp:2049`, as `copyin` fails in `sys_recvfrom`); an unwritable `from` with a nonzero `*fromlen`, after the receive, through `ReportAddress` (`:2060`, `:2110`), as the address `copyout` fails in `kern_recvit` (covered by `core/libs/tests/GuestUdp.cpp:482-484`); and a null buffer with a nonzero length. That last one faults here before the receive, where FreeBSD faults only on copyout; the timing is a separate topic and stays as it is. Also unchanged: libSceNet's own `sceNetRecvfrom`, which rejects the same pair with `NET_EINVAL` (`Export.cpp:1598`) as an SCE API, and `accept` and `getsockname`, where FreeBSD requires the length pointer. - **Tests.** `guest_sce_net_kernel_forwards` (`core/libs/tests/GuestNetKernelForwards.cpp`) runs `CheckDatagram` and `CheckArguments` for a native socket and for a libSceNet socket, so both paths are covered. `CheckDatagram` gains a case after the existing capacity loop and the receive without an address: it sends a datagram, clears the receive buffer, and receives with a 16-byte `from` filled with 0xAA and a null length pointer; the call must return the payload size, deliver the payload, and leave `from` unchanged. #18474, merged after this PR was opened, added `connect` checks at the same place; the merge with `main` (b5b8dabba0) keeps both blocks unchanged and puts this case first (`GuestNetKernelForwards.cpp:77-83` on b5b8dabba0, the `connect` checks at `:84-91`), because the case sends with a destination address and FreeBSD 11.4's [`udp_output`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/netinet/udp_usrreq.c#L1292-L1297) refuses that with `EISCONN` once the UDP socket is connected. The old `EFAULT` assertion for this pair in `CheckArguments` (`GuestNetKernelForwards.cpp:108` on b8194198cf, `:135` on b5b8dabba0) would now block on the bound, empty UDP socket, so it uses `MSG_DONTWAIT` (0x80) and expects `EAGAIN` (35), as the assertion at `:113` (`:140`) does, and requires the address buffer `local` unchanged. The `EFAULT` cases for an unreadable length pointer (`:109-110`, `:136-137`) stay. - **Overlap.** `pr_overlap.py --branch`, run on the merge commit b5b8dabba0, reports no shared lines or exports with the open pull requests it can compare. It cannot compare #11896, #12682, #12688, #12700, #12965 and #17253, which share `core/libs/prx/libkernel/Socket/src/Udp.cpp` but do not merge with `main`. Checked by hand on b5b8dabba0 against `main` dc19132bac2: a trial merge of this branch with each of them conflicts in the same files as `main` with it (identical sets for all six), and the `Udp.cpp` conflicts are the same hunks with and without this branch (five for #11896, three for #12965, two for #12700, one each for #12682, #12688 and #17253), and none of them touches the two changed `(address && !addressLength)` lines. None of the six changes the `(address && !addressLength)` check in `recvfrom` or edits `GuestNetKernelForwards.cpp`, so none implements this change. #16577 (a test-only audit of listen backlogs) asserted the old behaviour (`core/libs/tests/GuestSocketBacklog.cpp:189` on its branch required `recvfrom` with an address buffer and a null length pointer to fail with `EFAULT`); it was closed unmerged on 2026-11-11, and `main` does not contain that file. #7507 proposed the same change earlier and was closed unmerged on 2026-11-02 by its author, after #13756 (merged) reworked the `recvfrom` EFAULT handling; its review found that removing the check let the `ReceiveAnsweredHere` early return write through a null length pointer. On b8194198cf every write of the length is guarded by `addressLength` (`Udp.cpp:2059`, `:2071`, `:2078`, `:2098`; on b5b8dabba0 `:2100`, `:2112`, `:2119`, `:2145`), so that case cannot recur. ### 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`, on this branch based on c5488026ab; the rebase onto b8194198cf changes none of the files this change touches or this text cites (`git diff --stat` between the two bases is empty for them), so the runs below were not repeated. Each test executable was run from `build/tests` with `build/core/libs/libs/unpatched`, `build/core/libs/libs` and the MinGW `bin` on `PATH`: - Counter-check, new test with the library of c5488026ab (the two `Udp.cpp` lines put back): `cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests`, then `guest_net_kernel_forwards_tests.exe` aborted with `failed at line 82, errno 14`, the new `recvfrom(receiver, received, sizeof(received), 0, from.data(), nullptr)` assertion on the native socket. - With the change: `cmake --build build --parallel 4 --target guest_net_kernel_forwards_tests guest_udp_tests guest_socket_address_length_tests guest_socket_timeouts_tests guest_tcp_tests guest_socket_pair_tests guest_socket_on_non_socket_tests guest_underscore_entry_tests guest_datagram_receive_tests guest_socket_host_write_tests`, then the eight executables `guest_net_kernel_forwards_tests` (0.35 s), `guest_udp_tests`, `guest_socket_address_length_tests`, `guest_socket_timeouts_tests`, `guest_tcp_tests`, `guest_socket_pair_tests`, `guest_socket_on_non_socket_tests` and `guest_underscore_entry_tests` passed 8/8, and the 18 runs registered as `guest_datagram_*` and `guest_socket_host_write_*` (`guest_datagram_receive_tests` with `recv`, `recvfrom`, `sceNetRecv`, `sceNetRecvfrom`; `guest_socket_host_write_tests` with `recv`, `recvfrom`, `read`, `sceKernelRead`, `sceNetRecv`, `sceNetRecvfrom`, `sceNetRecvmsg`, each for UDP and with `tcp`) passed 18/18. - After the merge with `main` dc19132bac2 in b5b8dabba0, which the two runs above predate: git reported one conflict, the `CheckDatagram` hunk described under Tests; `Udp.cpp` merged without one and differs from `main` only in the two changed lines (`git diff dc19132bac2 b5b8dabba0 --stat`: `2 files changed, 11 insertions(+), 3 deletions(-)`). In a fresh build directory with the same options, the ten targets above built, and the same 26 runs passed 26/26 in one `ctest` run (`guest_sce_net_kernel_forwards`, `guest_udp`, `guest_socket_address_length`, `guest_socket_timeouts`, `guest_tcp`, `guest_socket_pair`, `guest_socket_on_non_socket`, `guest_underscore_entries` and the 18 `guest_datagram_*` and `guest_socket_host_write_*` runs). Counter-check on b5b8dabba0 with `Udp.cpp` checked out from dc19132bac2: `guest_sce_net_kernel_forwards` aborted with `failed at line 82, errno 14`, the new assertion; with `Udp.cpp` restored it passed again. - The FreeBSD lines were read in `sys/kern/uipc_syscalls.c` and `sys/netinet/udp_usrreq.c` fetched from `release/11.4.0`. - Not run here: the Linux and macOS builds; the changed lines are shared by all hosts. - `python tools/check_conventions.py --base upstream/main --head HEAD` (upstream `main` = dc19132bac2, HEAD at the merge commit b5b8dabba0) 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:09 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


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

  • 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_net_kernel_forwards_tests built cleanly.
  • CTest (guest_sce_net_kernel_forwards):
    1/1 Test #3678: guest_sce_net_kernel_forwards ....   Passed    0.22 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 #3678: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception:   0.76 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libkernel/Socket/src/Udp.cpp:2053 and :2066 that removing the (address && !addressLength) check aligns recvfrom_nid_postfix with FreeBSD 11.4 sys_recvfrom and kern_recvit, correctly permitting datagram reception without error when addressLength is null.
    • Verified that both the libSceNet forwarded path (Udp.cpp:2059) and the native socket path (Udp.cpp:2071, :2078, :2098) guard ReportAddress behind addressLength, ensuring address is never dereferenced or written when addressLength is null.
    • Verified in core/libs/tests/GuestNetKernelForwards.cpp:77-84 (CheckDatagram) that receiving with a non-null from buffer and null addressLength returns the exact payload length, delivers payload data, and leaves the caller buffer unmodified for both native and forwarded sockets.
    • Verified in core/libs/tests/GuestNetKernelForwards.cpp:115-116 (CheckArguments) that recvfrom_nid_postfix on an empty bound socket with MSG_DONTWAIT (0x80) and null addressLength fails with EAGAIN (35) instead of EFAULT (14), confirming the address buffer remains intact.
    • Verified that input validation paths remain strictly intact: null buffer with non-zero length fails with Fail(14) (EFAULT), unreadable length pointers fail with 14, lengths exceeding INT_MAX fail with Fail(40) (EMSGSIZE), and unsupported flags fail with Fail(45) (EOPNOTSUPP).
    • Verified strict compliance with AGENTS.md: zero comments added to code, no special-cased game values or title IDs, valid conventional commit title, and no unauthorized files added.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5848171394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18167#pullrequestreview-5848171394). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-10T19:37:09Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d4c7fcf10f`: - **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_net_kernel_forwards_tests` built cleanly. - **CTest** (`guest_sce_net_kernel_forwards`): ``` 1/1 Test #3678: guest_sce_net_kernel_forwards .... Passed 0.22 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 #3678: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception: 0.76 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libkernel/Socket/src/Udp.cpp:2053 and :2066 that removing the (address && !addressLength) check aligns recvfrom_nid_postfix with FreeBSD 11.4 sys_recvfrom and kern_recvit, correctly permitting datagram reception without error when addressLength is null. - Verified that both the libSceNet forwarded path (Udp.cpp:2059) and the native socket path (Udp.cpp:2071, :2078, :2098) guard ReportAddress behind addressLength, ensuring address is never dereferenced or written when addressLength is null. - Verified in core/libs/tests/GuestNetKernelForwards.cpp:77-84 (CheckDatagram) that receiving with a non-null from buffer and null addressLength returns the exact payload length, delivers payload data, and leaves the caller buffer unmodified for both native and forwarded sockets. - Verified in core/libs/tests/GuestNetKernelForwards.cpp:115-116 (CheckArguments) that recvfrom_nid_postfix on an empty bound socket with MSG_DONTWAIT (0x80) and null addressLength fails with EAGAIN (35) instead of EFAULT (14), confirming the address buffer remains intact. - Verified that input validation paths remain strictly intact: null buffer with non-zero length fails with Fail(14) (EFAULT), unreadable length pointers fail with 14, lengths exceeding INT_MAX fail with Fail(40) (EMSGSIZE), and unsupported flags fail with Fail(45) (EOPNOTSUPP). - Verified strict compliance with AGENTS.md: zero comments added to code, no special-cased game values or title IDs, valid conventional commit title, and no unauthorized files added. Requesting changes for the points above.
PrivacyOnion commented 2026-11-15 20:23:44 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_net_kernel_forwards_tests built cleanly.
  • CTest (guest_sce_net_kernel_forwards):
    1/1 Test #3976: guest_sce_net_kernel_forwards ....   Passed    0.23 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 #3976: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception:   0.38 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:2094,2107: Verified removal of (address && !addressLength) checks in recvfrom_nid_postfix allows receiving without writing destination address when addressLength is null, matching FreeBSD 11.4 sys_recvfrom behavior.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2090: Verified GuestCopyIn_nid_no_patch properly guards addressLength read, returning EFAULT (14) if addressLength is non-null but unreadable.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2095-2100: Verified forwarded path handles null addressLength cleanly by keeping capacity at 0, passing reported = 0 to forwards->recvfrom, and returning received directly without invoking ReportAddress.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2112,2119: Verified native early-return paths (ReceiveAnsweredHere and ReceiveShut) and normal receive returns guard ReportAddress with addressLength, avoiding null pointer dereference.
    • core/libs/tests/GuestNetKernelForwards.cpp:78-83: Verified CheckDatagram tests both native and libSceNet-forwarded sockets with a 16-byte address buffer and null length pointer, asserting payload reception and untouched address buffer.
    • core/libs/tests/GuestNetKernelForwards.cpp:134-135: Verified CheckArguments tests non-blocking recvfrom with MSG_DONTWAIT (0x80) on an empty socket expecting EAGAIN (35) instead of EFAULT (14) while leaving the local address buffer unmodified.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestNetKernelForwards.cpp: Verified strict compliance with AGENTS.md rules, ensuring zero comments added in source/test files and no special-casing.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912735303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18167#pullrequestreview-5912735303). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:23:44Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b5b8dabba0`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_net_kernel_forwards_tests` built cleanly. - **CTest** (`guest_sce_net_kernel_forwards`): ``` 1/1 Test #3976: guest_sce_net_kernel_forwards .... Passed 0.23 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 #3976: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception: 0.38 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:2094,2107: Verified removal of (address && !addressLength) checks in recvfrom_nid_postfix allows receiving without writing destination address when addressLength is null, matching FreeBSD 11.4 sys_recvfrom behavior. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2090: Verified GuestCopyIn_nid_no_patch properly guards addressLength read, returning EFAULT (14) if addressLength is non-null but unreadable. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2095-2100: Verified forwarded path handles null addressLength cleanly by keeping capacity at 0, passing reported = 0 to forwards->recvfrom, and returning received directly without invoking ReportAddress. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2112,2119: Verified native early-return paths (ReceiveAnsweredHere and ReceiveShut) and normal receive returns guard ReportAddress with addressLength, avoiding null pointer dereference. - core/libs/tests/GuestNetKernelForwards.cpp:78-83: Verified CheckDatagram tests both native and libSceNet-forwarded sockets with a 16-byte address buffer and null length pointer, asserting payload reception and untouched address buffer. - core/libs/tests/GuestNetKernelForwards.cpp:134-135: Verified CheckArguments tests non-blocking recvfrom with MSG_DONTWAIT (0x80) on an empty socket expecting EAGAIN (35) instead of EFAULT (14) while leaving the local address buffer unmodified. - core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestNetKernelForwards.cpp: Verified strict compliance with AGENTS.md rules, ensuring zero comments added in source/test files and no special-casing. Looks Good To Me
PrivacyOnion commented 2026-11-15 20:23:44 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_net_kernel_forwards_tests built cleanly.
  • CTest (guest_sce_net_kernel_forwards):
    1/1 Test #3976: guest_sce_net_kernel_forwards ....   Passed    0.23 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 #3976: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception:   0.38 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:2094,2107: Verified removal of (address && !addressLength) checks in recvfrom_nid_postfix allows receiving without writing destination address when addressLength is null, matching FreeBSD 11.4 sys_recvfrom behavior.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2090: Verified GuestCopyIn_nid_no_patch properly guards addressLength read, returning EFAULT (14) if addressLength is non-null but unreadable.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2095-2100: Verified forwarded path handles null addressLength cleanly by keeping capacity at 0, passing reported = 0 to forwards->recvfrom, and returning received directly without invoking ReportAddress.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:2112,2119: Verified native early-return paths (ReceiveAnsweredHere and ReceiveShut) and normal receive returns guard ReportAddress with addressLength, avoiding null pointer dereference.
    • core/libs/tests/GuestNetKernelForwards.cpp:78-83: Verified CheckDatagram tests both native and libSceNet-forwarded sockets with a 16-byte address buffer and null length pointer, asserting payload reception and untouched address buffer.
    • core/libs/tests/GuestNetKernelForwards.cpp:134-135: Verified CheckArguments tests non-blocking recvfrom with MSG_DONTWAIT (0x80) on an empty socket expecting EAGAIN (35) instead of EFAULT (14) while leaving the local address buffer unmodified.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestNetKernelForwards.cpp: Verified strict compliance with AGENTS.md rules, ensuring zero comments added in source/test files and no special-casing.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5912735326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18167#pullrequestreview-5912735326). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T20:23:44Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b5b8dabba0`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_net_kernel_forwards_tests` built cleanly. - **CTest** (`guest_sce_net_kernel_forwards`): ``` 1/1 Test #3976: guest_sce_net_kernel_forwards .... Passed 0.23 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 #3976: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception: 0.38 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:2094,2107: Verified removal of (address && !addressLength) checks in recvfrom_nid_postfix allows receiving without writing destination address when addressLength is null, matching FreeBSD 11.4 sys_recvfrom behavior. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2090: Verified GuestCopyIn_nid_no_patch properly guards addressLength read, returning EFAULT (14) if addressLength is non-null but unreadable. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2095-2100: Verified forwarded path handles null addressLength cleanly by keeping capacity at 0, passing reported = 0 to forwards->recvfrom, and returning received directly without invoking ReportAddress. - core/libs/prx/libkernel/Socket/src/Udp.cpp:2112,2119: Verified native early-return paths (ReceiveAnsweredHere and ReceiveShut) and normal receive returns guard ReportAddress with addressLength, avoiding null pointer dereference. - core/libs/tests/GuestNetKernelForwards.cpp:78-83: Verified CheckDatagram tests both native and libSceNet-forwarded sockets with a 16-byte address buffer and null length pointer, asserting payload reception and untouched address buffer. - core/libs/tests/GuestNetKernelForwards.cpp:134-135: Verified CheckArguments tests non-blocking recvfrom with MSG_DONTWAIT (0x80) on an empty socket expecting EAGAIN (35) instead of EFAULT (14) while leaving the local address buffer unmodified. - core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestNetKernelForwards.cpp: Verified strict compliance with AGENTS.md rules, ensuring zero comments added in source/test files and no special-casing. 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!18167
No description provided.