Skip to content

XCL_NETWORK=0: the system's WSASendMsg refuses too - #612

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/netoff-wsasendmsg
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/netoff-wsasendmsg

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

With XCL_NETWORK=0 the system's sendto and WSASendTo are hooked (db1ddb2, #305), but WSASendMsg is not, and it carries its destination in the message. On main 508a0c7 a datagram sent with it to an address the hooked sendto refuses still arrives. This hooks it with sendto's rule: no address or loopback goes to the original, anything else is refused with WSAENETUNREACH.

Follow-up to #305 (closed), found with the scratch test from #444.

What is in it

  • crates/xcl/src/hle/netoff.rs: ws2_32!WSASendMsg in the table of install_system_hooks, its detour wsa_send_msg and the call to the original.
  • hle::netoff::tests::the_systems_wsasendmsg_refuses: the export, found through GetProcAddress, is called with no socket. For 8.8.8.8 the hook answers 10051 before it looks at the socket. For 127.0.0.1 the call reaches the system, which answers something else. No socket is opened and nothing is sent.

Tested

  • RTX 5070 Ti, NVIDIA 610.74, Ryzen 9 9950X, Windows 11 Pro 26200; Rust 1.99.0, MSVC stable, debug.
  • cargo test --workspace -- --test-threads=4 on bbf3174 (this PR, on main 508a0c7): 681 passed, 0 failed, 41 ignored (the xcl library: 641 passed, 21 ignored). SKIPPED GPU tests: 2, both no wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).
  • The new test:
    • main 508a0c7 with only the test added: fails (left: 10093, right: 10051, the system's own answer);
    • this change: passes.
  • A scratch test, not in the PR, loopback only: a UDP socket listens on 127.0.0.1 and is sent to as ::ffff:127.0.0.1, which the hooks treat as any other host.
    • main 508a0c7 with the hooks: sendto and WSASendTo are refused (10051); WSASendMsg returns 0 and the datagram arrives.
    • this change with the hooks: all three are refused (10051); WSASendMsg to 127.0.0.1 itself still arrives.
  • @MesshM's run on AMD (comment): Radeon RX 9060 XT 16 GB, driver 32.0.32029.2010, Ryzen 7 5700X, Windows 11 Pro 26200, Rust 1.100.0, debug. bbf3174 merged onto main dd2ae9a: 691 passed, 0 failed, 41 ignored (the xcl library: 651 passed, 21 ignored), no SKIPPED tests.

Regression run

Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes.

main:

xcl-smoke v1
commit: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1512 (PresentX 1513)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14267 MB

PR:

xcl-smoke v1
commit: bbf31746947d2cbd98dd243f68eb42f96f48fdc6
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1509 (PresentX 1509)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14267 MB

Not tested

  • The WSASendMsg that WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, WSAID_WSASENDMSG) hands out. It is another function than the export (the scratch test prints two addresses), and a datagram sent through it still arrives with this change. Refusing it needs a hook on WSAIoctl, which Netoff: block ConnectEx when network is disabled #462 (open) adds for ConnectEx; it is not in this PR.
  • A title that sends datagrams, and any datagram to another machine.
  • An overlapped WSASendMsg through the hook: the calls above are synchronous.
  • Intel GPUs. Wine.
  • macOS / Linux: not built.
  • Netoff: block ConnectEx when network is disabled #462 (open) also adds a line to the hook table and changes its length, so whichever merges second needs a rebase.

AI use

  • Claude Code, Claude Fable 5.2: wrote the change, the test and this description; the runs above are its own.

🤖 Generated with Claude Code

WSASendMsg carries the destination in its message, so a datagram sent with
it needs neither sendto nor connect, which are hooked. With XCL_NETWORK=0
on main a datagram sent with it to an address the hooked sendto refuses
still arrived. It is hooked like sendto now: no address or loopback goes
to the original, anything else is refused (WSAENETUNREACH).

Not covered: the WSASendMsg that WSAIoctl hands out for WSAID_WSASENDMSG
is another function (the provider's), not this export.

Test: the export found through GetProcAddress refuses 8.8.8.8 with no
socket; it fails on main, where the system answers 'not a socket'.

Co-Authored-By: Claude <noreply@anthropic.com>
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of bbf31746947d2cbd98dd243f68eb42f96f48fdc6 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the_systems_wsasendmsg_refuses and the_systems_own_network_functions_refuse pass.

Review: On x64 WSAMSG starts with name (8-byte pointer) and namelen (INT at +8), which is what wsa_send_msg reads; a null name (a connected socket) and loopback go to the original. A question rather than a finding: older code gets WSASendMsg through WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) with WSAID_WSASENDMSG rather than the export. That pointer comes from the provider, so it would not go through this hook unless the WSAIoctl path hands out the hooked function (as ConnectEx needs too, see #444/#462). I did not check whether netoff already does that.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@MesshM, thanks for the RDNA4 run.

On the question: yes, that is a second path, and this PR does not cover it. I checked it on main 508a0c7 and on this branch with a loopback-only scratch test:

  • The pointer that WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, WSAID_WSASENDMSG) hands out is a different address from the ws2_32 export.
  • A datagram sent through it to an address the hooked sendto refuses still arrives, with and without this change.

Netoff has no hook on WSAIoctl on main. #462 adds one for ConnectEx; the WSASendMsg pointer can be answered in the same place once that is merged, and I will follow up then. It is under Not tested in the description.

🤖 Claude Fable 5.2

@tiagonleal

tiagonleal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Windows / NVIDIA test of #612 (bbf3174694) and #619 (2970626721) merged together onto main 47efa2e (both clean), with #570 rebased on top.

Tested

Not tested: a retail run of this combined tree; AMD / Intel.

Run and written with Claude Code (Claude Opus 5.5).

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (bbf3174)

Hardware / environment

  • Commit bbf31746947d2cbd98dd243f68eb42f96f48fdc6 (PR XCL_NETWORK=0: the system's WSASendMsg refuses too #612), clean detached checkout.
  • Windows 10.0.26200.9974. CPU identified by Windows as AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD, with 12 logical processors available to the process.
  • Rust 1.100.0 (0ef1bc386 2026-11-09), host x86_64-pc-windows-msvc. DXC 1.9.2609.5 (01b62ad47).
  • The build and CPU-only run ran directly under Cargo, outside Invoke-ArcTest.ps1, with zero Arc GPU mutex hold.

Commands and results

  • cargo test --workspace --no-run exited 0 and built 15 test executables. It emitted a fetch_update deprecation warning. This command only compiled tests.
  • With XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1, cargo test -p xcl --lib hle::netoff::tests:: exited 0 with 3 passed, 0 failed, 0 ignored, and 0 skipped. The skip count is the number of case-sensitive log lines beginning with SKIPPED . The harness reported 659 tests filtered out.

Observed behavior

  • The new regression test resolved the system WSASendMsg export and verified that the hook refused the non-loopback destination with WSAENETUNREACH (10051). For 127.0.0.1, the same invalid socket produced a different error. The test checks the error returned by the hook using an invalid socket.
  • Both existing module tests passed. They cover IPv4 and IPv6 loopback classification and the behavior of hooked WinHTTP, WinINet, and Winsock lookup exports. The PR adds no integration tests.

Not tested

The full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr612-focused.log and published.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review (OpenAI GPT-6); I checked this path against the diff and Microsoft Winsock documentation. I did not run tests or the game.

/// WSASendMsg has its destination in the message (WSAMSG begins with the address and its
/// length), so a datagram sent with it needs neither `sendto` nor `connect`. As in `sendto`:
/// no address (a connected socket) or loopback goes to the original.
unsafe extern "system" fn wsa_send_msg(s: usize, msg: *const c_void, flags: u32, sent: *mut u32, ov: *mut c_void, cb: *const c_void) -> i32 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a regression resolve and call the WSASendMsg pointer returned by WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, WSAID_WSASENDMSG)? The current test calls the ws2_32 export through GetProcAddress, but Microsoft documents that the extension pointer can invoke the provider directly without passing through Ws2_32. That leaves a path for non-loopback traffic to bypass this export hook while XCL_NETWORK=0. Please cover the returned pointer and ensure off-loopback sends remain refused. WSASendMsg, provider extension mechanism. AI-assisted review (OpenAI GPT-6); I checked this path against Microsoft documentation and did not run tests.

@Kalmarv

Kalmarv commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@gut0to thanks. Confirmed by reading, not run: neither this PR (bbf3174) nor main (8b957be) hooks WSAIoctl, so a WSASendMsg taken from SIO_GET_EXTENSION_FUNCTION_POINTER / WSAID_WSASENDMSG calls the provider directly and skips this hook while XCL_NETWORK=0.

It is the same gap as #444: ConnectEx is only reachable through that pointer, and it still connects. Both are fixed in one place by hooking WSAIoctl and handing back a refusing detour for WSAID_WSASENDMSG and WSAID_CONNECTEX, with a test that resolves each pointer and checks that an off-loopback call is refused. That fix belongs with #444, as its own PR. This PR stays the ws2_32 export, which it closes as described. I'll link the #444 PR here when it is up.

AI use: Claude Code, Claude Opus 5.5 checked the code paths and wrote this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants