fix(libkernel): reject 0.0.0.0/8 multicast interface addresses on Windows with EADDRNOTAVAIL #25533

Merged
mauroalvare merged 1 commit from upstream-pr/25533 into main 2026-11-24 17:47:42 +00:00
mauroalvare commented 2026-11-22 07:47:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mauroalvare on 2026-11-22T07:47:53Z.


What

On Windows, reject IPv4 multicast interface addresses in 0.0.0.0/8 other than 0.0.0.0 (INADDR_ANY) with EADDRNOTAVAIL (49) in SetIpLevelOption (IP_MULTICAST_IF, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP) before calling Winsock, matching FreeBSD 11.4 (inp_set_multicast_if / inp_join_group) instead of letting Winsock interpret those addresses as 24-bit interface indices:

  • Added ZeroNetworkAddress in core/libs/prx/libkernel/Socket/src/SocketOptions.cpp under #ifdef _WIN32 and returned ErrorAddressNotAvailable before ::setsockopt for non-zero addresses in 0.0.0.0/8. Previously on Windows 11, 0.0.0.1 succeeded on both IP_MULTICAST_IF (storing 0.0.0.1 in state.multicastInterface) and IP_ADD_MEMBERSHIP, while 0.0.0.2, 0.0.0.255, 0.1.0.0, and 0.255.255.255 failed IP_MULTICAST_IF with WSAEINVAL (guest EINVAL 22).
  • Added regression checks in MulticastMembership (core/libs/tests/GuestSocketOptions.cpp) for {0,0,0,1}, {0,0,0,2}, {0,1,0,0}, and {0,255,255,255} across IP_MULTICAST_IF, IP_ADD_MEMBERSHIP, and IP_DROP_MEMBERSHIP, verifying EADDRNOTAVAIL (49) and that getsockopt(IP_MULTICAST_IF) remains 0.0.0.0.
  • Updated docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md to close the IP_MULTICAST_IF on Windows entry and document the 0.0.0.0/8 handling on Windows under [IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF].
  • Overlap check (tools/pr_overlap.py --branch fix/libkernel-win-multicast-addr): the four conflicting open PRs sharing SocketOptions.cpp / GuestSocketOptions.cpp (#12688, #12700, #12965 on FIONBIO / BlockingConnectCanRetryAfterRefusal and #18108 on Copy) do not touch SetIpLevelOption or MulticastMembership.

Tested

  • Windows 11 Pro (build 26300), WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh-15.2.0-14.0.0-r7), CMake Release (BUILD_TESTING=ON), base ccc951d99223326c85ef71f451a557fad78460e5, branch head 6c387b8aa1:
    • Negative control before the SocketOptions.cpp fix: ctest -R "^guest_socket_options$" --output-on-failure failed (Exit code 0xc0000409: a 0.0.0.0/8 address other than INADDR_ANY must fail IP_MULTICAST_IF with EADDRNOTAVAIL (49)).
    • After the fix: ctest -R "^(guest_socket_error|guest_socket_options|guest_socket_options_multicast|guest_socket_stream_options|guest_udp|guest_kernel_socket_broadcast_debug_route_bounds|guest_kernel_socket_buf_timeout_bounds|public_headers)$" --output-on-failure -V passed 8/8 (public_headers verified 413 libraries and 34819 exports; neither guest_socket_options nor guest_socket_options_multicast skipped).
    • python tools/debt_fold.py --check passed (exit 0); python tools/check_conventions.py --base origin/main passed (All conventions checks passed.).
  • Not run: full CTest suite, Linux, macOS, or console tests.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5437001255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25533). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-22T07:47:53Z. --- ### What On Windows, reject IPv4 multicast interface addresses in `0.0.0.0/8` other than `0.0.0.0` (`INADDR_ANY`) with `EADDRNOTAVAIL` (49) in `SetIpLevelOption` (`IP_MULTICAST_IF`, `IP_ADD_MEMBERSHIP`, `IP_DROP_MEMBERSHIP`) before calling Winsock, matching FreeBSD 11.4 (`inp_set_multicast_if` / `inp_join_group`) instead of letting Winsock interpret those addresses as 24-bit interface indices: - Added `ZeroNetworkAddress` in `core/libs/prx/libkernel/Socket/src/SocketOptions.cpp` under `#ifdef _WIN32` and returned `ErrorAddressNotAvailable` before `::setsockopt` for non-zero addresses in `0.0.0.0/8`. Previously on Windows 11, `0.0.0.1` succeeded on both `IP_MULTICAST_IF` (storing `0.0.0.1` in `state.multicastInterface`) and `IP_ADD_MEMBERSHIP`, while `0.0.0.2`, `0.0.0.255`, `0.1.0.0`, and `0.255.255.255` failed `IP_MULTICAST_IF` with `WSAEINVAL` (guest `EINVAL` 22). - Added regression checks in `MulticastMembership` (`core/libs/tests/GuestSocketOptions.cpp`) for `{0,0,0,1}`, `{0,0,0,2}`, `{0,1,0,0}`, and `{0,255,255,255}` across `IP_MULTICAST_IF`, `IP_ADD_MEMBERSHIP`, and `IP_DROP_MEMBERSHIP`, verifying `EADDRNOTAVAIL` (49) and that `getsockopt(IP_MULTICAST_IF)` remains `0.0.0.0`. - Updated `docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md` to close the `IP_MULTICAST_IF on Windows` entry and document the `0.0.0.0/8` handling on Windows under `[IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF]`. - Overlap check (`tools/pr_overlap.py --branch fix/libkernel-win-multicast-addr`): the four conflicting open PRs sharing `SocketOptions.cpp` / `GuestSocketOptions.cpp` (`#12688`, `#12700`, `#12965` on `FIONBIO` / `BlockingConnectCanRetryAfterRefusal` and `#18108` on `Copy`) do not touch `SetIpLevelOption` or `MulticastMembership`. ### 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 Pro (build 26300), WinLibs GCC 15.2.0 (`x86_64-ucrt-posix-seh-15.2.0-14.0.0-r7`), CMake Release (`BUILD_TESTING=ON`), base `ccc951d99223326c85ef71f451a557fad78460e5`, branch head `6c387b8aa1`: - Negative control before the `SocketOptions.cpp` fix: `ctest -R "^guest_socket_options$" --output-on-failure` failed (`Exit code 0xc0000409`: `a 0.0.0.0/8 address other than INADDR_ANY must fail IP_MULTICAST_IF with EADDRNOTAVAIL (49)`). - After the fix: `ctest -R "^(guest_socket_error|guest_socket_options|guest_socket_options_multicast|guest_socket_stream_options|guest_udp|guest_kernel_socket_broadcast_debug_route_bounds|guest_kernel_socket_buf_timeout_bounds|public_headers)$" --output-on-failure -V` passed 8/8 (`public_headers` verified 413 libraries and 34819 exports; neither `guest_socket_options` nor `guest_socket_options_multicast` skipped). - `python tools/debt_fold.py --check` passed (exit 0); `python tools/check_conventions.py --base origin/main` passed (`All conventions checks passed.`). - Not run: full CTest suite, Linux, macOS, or console tests. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-22 07:51:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T07:51:42Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_socket_options_tests built cleanly.
  • CTest (guest_socket_options, guest_socket_options_multicast):
    1/2 Test #6029: guest_socket_options .............   Passed    0.01 sec
    2/2 Test #6030: guest_socket_options_multicast ...   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/SocketOptions.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #6029: guest_socket_options .............   Passed    0.01 sec
    2/2 Test #6030: guest_socket_options_multicast ...   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libkernel/Socket/src/SocketOptions.cpp that ZeroNetworkAddress correctly identifies non-zero IPv4 addresses in 0.0.0.0/8 by checking bits != 0 and the first octet at offset 0 == 0.
    • Verified in SetIpLevelOption (SocketOptions.cpp) that both IP_MULTICAST_IF (address) and IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP (request.imr_interface) reject 0.0.0.0/8 addresses on Windows with ErrorAddressNotAvailable (EADDRNOTAVAIL, 49) before invoking ::setsockopt.
    • Verified that INADDR_ANY (0.0.0.0) evaluates to bits == 0 and is not rejected by ZeroNetworkAddress, preserving standard interface selection behavior.
    • Verified in core/libs/tests/GuestSocketOptions.cpp that MulticastMembership tests boundary addresses {0,0,0,1}, {0,0,0,2}, {0,1,0,0}, and {0,255,255,255} across IP_MULTICAST_IF, IP_ADD_MEMBERSHIP, and IP_DROP_MEMBERSHIP, and asserts getsockopt retains 0.0.0.0.
    • Verified that AGENTS.md conventions are strictly maintained: no disallowed comments were added, and docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md properly documents the behavior and closes the Windows technical debt entry.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011118051 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25533#pullrequestreview-6011118051). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-22T07:51:42Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `6c387b8aa1`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_socket_options_tests` built cleanly. - **CTest** (`guest_socket_options`, `guest_socket_options_multicast`): ``` 1/2 Test #6029: guest_socket_options ............. Passed 0.01 sec 2/2 Test #6030: guest_socket_options_multicast ... Passed 0.00 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/SocketOptions.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #6029: guest_socket_options ............. Passed 0.01 sec 2/2 Test #6030: guest_socket_options_multicast ... Passed 0.00 sec 100% tests passed, 0 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libkernel/Socket/src/SocketOptions.cpp that ZeroNetworkAddress correctly identifies non-zero IPv4 addresses in 0.0.0.0/8 by checking bits != 0 and the first octet at offset 0 == 0. - Verified in SetIpLevelOption (SocketOptions.cpp) that both IP_MULTICAST_IF (address) and IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP (request.imr_interface) reject 0.0.0.0/8 addresses on Windows with ErrorAddressNotAvailable (EADDRNOTAVAIL, 49) before invoking ::setsockopt. - Verified that INADDR_ANY (0.0.0.0) evaluates to bits == 0 and is not rejected by ZeroNetworkAddress, preserving standard interface selection behavior. - Verified in core/libs/tests/GuestSocketOptions.cpp that MulticastMembership tests boundary addresses {0,0,0,1}, {0,0,0,2}, {0,1,0,0}, and {0,255,255,255} across IP_MULTICAST_IF, IP_ADD_MEMBERSHIP, and IP_DROP_MEMBERSHIP, and asserts getsockopt retains 0.0.0.0. - Verified that AGENTS.md conventions are strictly maintained: no disallowed comments were added, and docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md properly documents the behavior and closes the Windows technical debt entry. Looks Good To Me
MarcZX10 commented 2026-11-22 07:59:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:59:35Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 6c387b8aa11650638127392a143f96fdebb757e3. I did not run commands or tests. The author reports Windows 11 tests and convention checks in the PR description; those results were not independently confirmed.

Results

Check Result Note
Code review passed Three changed files read
Tests not run Windows results reported by author
Other checks not run Full suite and other platforms unverified

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not independently run the tests, conventions checks, or overlap check. Linux, macOS, and console behavior were not tested. All changed files listed in the manifest were read: core/libs/prx/libkernel/Socket/src/SocketOptions.cpp, core/libs/tests/GuestSocketOptions.cpp, and docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md. No files were excluded in the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6011140324 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25533#pullrequestreview-6011140324). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T07:59:35Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `6c387b8aa11650638127392a143f96fdebb757e3`. I did not run commands or tests. The author reports Windows 11 tests and convention checks in the PR description; those results were not independently confirmed. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Three changed files read | | Tests | not run | Windows results reported by author | | Other checks | not run | Full suite and other platforms unverified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not independently run the tests, conventions checks, or overlap check. Linux, macOS, and console behavior were not tested. All changed files listed in the manifest were read: `core/libs/prx/libkernel/Socket/src/SocketOptions.cpp`, `core/libs/tests/GuestSocketOptions.cpp`, and `docs/dev/debt/changes/fix-libkernel-ip-multicast-if-mreqn.md`. No files were excluded in the manifest. ## To get this to a good state Nothing is required.
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!25533
No description provided.