Netoff: block ConnectEx when network is disabled #462

Open
github-bot wants to merge 1 commit from github-bot/gh-462 into main AGit
Owner

@⁠SandimL on GitHub · 2026-11-24 00:35 UTC · original
SandimL:fix/connectex-network-off → main · +126 −1 · 1 files · 1 commits · open

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

  • OpenAI Codex (GPT-5) investigated issue #444, implemented the hook and regression test, ran the checks above, and drafted this description. The author reviewed the diff and test results.
**@⁠SandimL** on GitHub · 2026-11-24 00:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/462) `SandimL:fix/connectex-network-off` → `main` · +126 −1 · 1 files · 1 commits · open 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** - OpenAI Codex (GPT-5) investigated issue #444, implemented the hook and regression test, ran the checks above, and drafted this description. The author reviewed the diff and test results.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:22:33 +00:00
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-24 01:09 UTC · original

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 #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

**@⁠Kalmarv** on GitHub · 2026-11-24 01:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7118817573) 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 #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
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-24 02:13 UTC · original

Tested 17172b5 (this PR's head).

  • AMD Ryzen 7 9800X3D, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2124), Windows 11 10.0.26100, Rust 1.100.0, debug.
  • cargo test -p xcl --lib hle::netoff::tests -- --nocapture: 2 passed, 0 failed.
  • Negative control: with only the ("ws2_32.dll", "WSAIoctl", …) entry taken out of install_system_hooks (array back to 18), the_systems_own_network_functions_refuse fails at assert_eq!(connect_ex, connect_ex_detour as usize), so the test does catch the gap from #444. It fails there before ConnectEx is called, so nothing leaves the machine in that case.
  • The newer retail title with this PR in a local merge (main 508a0c7 + #451, #300, #468, this PR, #267; release), XCL_NETWORK=0, through its menus into the world load, 150 s until the title's own watchdog stop (#505, not related): the netoff install line is logged as on main, and no ConnectEx refusal was logged, so the title did not call ConnectEx in that time. The firewall also blocked xcl.exe, so nothing reached the network either way.

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.)

**@⁠SpaghettiMaster545** on GitHub · 2026-11-24 02:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7119891966) **Tested** `17172b5` (this PR's head). - AMD Ryzen 7 9800X3D, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2124), Windows 11 10.0.26100, Rust 1.100.0, debug. - `cargo test -p xcl --lib hle::netoff::tests -- --nocapture`: 2 passed, 0 failed. - Negative control: with only the `("ws2_32.dll", "WSAIoctl", …)` entry taken out of `install_system_hooks` (array back to 18), `the_systems_own_network_functions_refuse` fails at `assert_eq!(connect_ex, connect_ex_detour as usize)`, so the test does catch the gap from #444. It fails there before `ConnectEx` is called, so nothing leaves the machine in that case. - The newer retail title with this PR in a local merge (`main` 508a0c7 + #451, #300, #468, this PR, #267; release), `XCL_NETWORK=0`, through its menus into the world load, 150 s until the title's own watchdog stop (#505, not related): the netoff install line is logged as on `main`, and no `ConnectEx` refusal was logged, so the title did not call `ConnectEx` in that time. The firewall also blocked `xcl.exe`, so nothing reached the network either way. 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.)
Author
Owner

@⁠pvfreis on GitHub · 2026-11-24 03:19 UTC · original

Test report for 17172b593a (this PR's head), against its merge base on main a6f5f7a74c. 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.

**@⁠pvfreis** on GitHub · 2026-11-24 03:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7120979327) Test report for 17172b593ae1324591d43ace8192458934cca70e (this PR's head), against its merge base on main a6f5f7a74cc620c1f88a9e3669a633d10c3c8212. 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.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:27 UTC · original

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.

**@⁠MesshM** on GitHub · 2026-11-24 04:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7122043006) 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.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-24 10:40 UTC · original

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.

**@⁠raylitebull** on GitHub · 2026-11-24 10:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7129086599) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 14:15 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 14:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/462#issuecomment-7165002398) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/netoff.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/462/head:github-bot/gh-462'
git switch 'github-bot/gh-462'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-462'
git switch 'github-bot/gh-462'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-462'
git switch 'github-bot/gh-462'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-462'
git switch 'main'
git merge --squash 'github-bot/gh-462'
git switch 'main'
git merge --ff-only 'github-bot/gh-462'
git switch 'main'
git merge 'github-bot/gh-462'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.