Skip to content

Netoff: block ConnectEx when network is disabled - #462

Open
SandimL wants to merge 1 commit into
xcl-dev:mainfrom
SandimL:fix/connectex-network-off
Open

SandimL wants to merge 1 commit into
xcl-dev:mainfrom
SandimL:fix/connectex-network-off

Conversation

@SandimL

@SandimL SandimL commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #444.

What is in it

  • crates/xcl/src/hle/netoff.rs: hook ws2_32!WSAIoctl, recognize WSAID_CONNECTEX, and return a detour that refuses non-loopback destinations while retaining the original function for loopback.
  • Add a regression through the same WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) path a title uses.

Tested

  • AMD Radeon RX 6750 XT (12243 MiB), Windows build 26300, Rust 1.100.0.
  • cargo check -p xcl: passed.
  • cargo test -p xcl --lib hle::netoff::tests -- --nocapture: 2 passed, 0 failed.
  • cargo test -p xcl --lib: 634 passed, 2 failed, 21 ignored. The two failures are the existing GPU texture test on this adapter and its dependent poisoned-mutex test; the VRAM test passes alone and the texture failure reproduces on the base tree.
  • Release smoke runs below used the same local smoke-game title for 20 seconds with XCL_NETWORK=0; the required --hello argument was supplied because that test title requires it.

Regression run

  • main:
xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: AMD Radeon RX 6750 XT
title: smoke-game
seconds: 20
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 1
device removals: 0
crashes: 0
peak commit: 2412 MB
  • this PR:
xcl-smoke v1
commit: 17172b593ae1324591d43ace8192458934cca70e
gpu: AMD Radeon RX 6750 XT
title: smoke-game
seconds: 20
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 1
device removals: 0
crashes: 0
peak commit: 2135 MB

Not tested

  • A retail title using ConnectEx.
  • Successful ConnectEx loopback to a real listener; the detour forwards loopback to the captured original function, while the regression covers the refusal path.
  • Connections to another machine; the regression uses only the local test title and does not send traffic to an external host.

AI use

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested 17172b5 merged onto main 7ebf1b8 (merge 642740b, no conflicts). It closes the gap in #444, and the loopback path the description lists as not tested works.

  • The scratch test from XCL_NETWORK=0: ConnectEx still connects (main a6f5f7a) #444 (ConnectEx through WSAIoctl to a listener on 127.0.0.1, reached as ::ffff:127.0.0.1, which the hooks treat as any other host) fails on main 7ebf1b8 and passes on the merge: ConnectEx is refused with 10051 and nothing arrives at the listener.
  • One more row for this PR: ConnectEx to 127.0.0.1 itself still connects with the hooks, through the detour and the captured original. That is the "successful ConnectEx loopback to a real listener" under Not tested.
  • The PR's own test does test the change: with the WSAIoctl line left out of the hook table, the_systems_own_network_functions_refuse fails. It cannot run on main, where connect_ex_detour does not exist.
                               before the hooks                 with the hooks
connect                         r=0 err=0 REACHED         r=-1 err=10051 refused
ConnectEx                       r=1 err=0 REACHED          r=0 err=10051 refused
ConnectEx 127.0.0.1             r=1 err=0 REACHED              r=1 err=0 REACHED
WSAConnectByNameW               r=1 err=0 REACHED          r=0 err=11001 refused
getaddrinfo                     r=0 err=0 REACHED          r=11001 err=0 refused
GetAddrInfoExW                  r=0 err=0 REACHED          r=11001 err=0 refused
GetAddrInfoExA                  r=0 err=0 REACHED          r=11001 err=0 refused

On main the ConnectEx row reads r=1 err=0 REACHED in both columns; the other rows are the same.

Tested

Ryzen 9 9950X, Windows 11 26200, debug. CPU only, loopback only; no GPU test was run.

  • cargo test -p xcl --lib -- netoff:: on the merge 642740b: 2 passed, 0 failed; with the WSAIoctl hook left out 1 passed, 1 failed.
  • cargo test -p xcl --lib -- gap_tests --nocapture (the scratch test, not part of the PR): merge 1 passed, 0 failed; main 7ebf1b8 0 passed, 1 failed.
  • scripts/pr_check.py from main on the description: ok.

Not tested

  • The whole suite on the merge, and anything on a GPU.
  • A title, or a connection to another machine.
  • A socket of a second Winsock provider: the detour keeps one original ConnectEx pointer for the process.

🤖 Claude Fable 5.2

@SpaghettiMaster545

Copy link
Copy Markdown

Tested 17172b5 (this PR's head).

One remark on the test, checked by reading it: the refused destination is 8.8.8.8. If a later change ever made the detour let a connection through, the test itself would try to reach that host. #444's scratch test used ::ffff:127.0.0.1 for that reason: a local listener that the hooks do not count as loopback, so a regression would show up as REACHED without leaving the machine.

Not tested

  • AMD GPUs; a title that calls ConnectEx itself (the retail title did not in those 150 s).

(Claude Code, Claude Opus 5.5: ran the commands above and wrote this report.)

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report for 17172b5 (this PR's head), against its merge base on main a6f5f7a. Whole suite on NVIDIA, no regression.

Tested

  • RTX 3060 12 GB (driver 617.14), Ryzen 9 5900XT, Windows 11 26H2 (10.0.26300), Rust 1.100.0 stable MSVC, debug
  • cargo build --workspace --locked --offline, then cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4, for both commits:
    • main a6f5f7a: 675 passed, 1 failed, 41 ignored
    • PR 17172b5: 675 passed, 1 failed, 41 ignored
    • per-test results identical; hle::netoff::tests::the_systems_own_network_functions_refuse and only_loopback_goes_through pass on both
  • SKIPPED on this adapter (both): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • The 1 failure is the same on both and not from this PR: test_title_runs_and_game_folder_is_untouched (e2e.rs:225, presents 0), because these runs are in an isolated non-interactive session where CreateSwapChainForHwnd returns 0x887A0022. An interactive run of main at 7ebf1b8 on this machine passed it (677 passed, 0 failed, 41 ignored).

Not tested

  • the negative control (dropping the WSAIoctl hook): already done by SpaghettiMaster545 above
  • a retail title / smoke run; AMD and Intel GPUs
  • ConnectEx on a socket from a non-Microsoft Winsock provider. Reading the diff: O_CONNECT_EX keeps one original pointer for all sockets, so with two providers that hand out different ConnectEx pointers, loopback calls would go to whichever was stored last. Not seen in practice, just a question.

Tested and written with Claude Code (Claude Opus 5.5); the runs are real, on the hardware above.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 17172b593ae1324591d43ace8192458934cca70e on AMD RDNA4. I merged it onto current main 64b3f35 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: 701 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 660 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the netoff tests pass, including the WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) regression.

Review: Handing out a detour for WSAID_CONNECTEX that refuses non-loopback destinations closes the path #444 describes. The same WSAIoctl path also gives out WSAID_WSASENDMSG (and WSAID_WSARECVMSG), which this hook passes through; #612 hooks the WSASendMsg export, but a title that gets it through WSAIoctl would get the provider's function. Extending the GUID check to WSAID_WSASENDMSG would cover both. I found nothing to change in what this PR does.

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.

@raylitebull

Copy link
Copy Markdown
Member

Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Blocks WSAIoctl ConnectEx under XCL_NETWORK=0, closing an offline-mode gap. Recommend merging, @ivall.

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.

XCL_NETWORK=0: ConnectEx still connects (main a6f5f7a)

6 participants