Skip to content

XGameRuntime: unregistering an association callback cancels it - #1753

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:xgameruntime/association-context-uaf
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:xgameruntime/association-context-uaf

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Addresses XCL-BT-041 from #1488.

XUserUnregisterForDeviceAssociationChanged dropped the registration, ignored wait, and left the callbacks it had already handed to the title's queue untouched: one queued behind the call still ran the title's callback with the title's context, which the title is free to free once the call returns (wait = true is the documented way to know it is safe). A running callback was not waited for either.

This tracks each queued callback's state (Queued / Running / Done): the unregister marks a queued one done — the queue's later call then skips the title's callback and just releases the record — and with wait it waits for a running one to finish before returning.

What is in it

  • crates/xcl/src/hle/xgameruntime/mod.rs: AssociationCall carries its token and a Queued/Running/Done state with a condvar; ASSOCIATION_CALLS holds the live records; association_call skips a call that was unregistered (or whose queue was terminated) and signals when it is done; XUserUnregisterForDeviceAssociationChanged(token, wait) cancels queued calls and waits for running ones; notify_association passes the token.
  • Test an_unregistered_association_callback_does_not_run (manual queue: queued, unregistered, dispatched → not called; a later registration still runs). Fails on main with left: 1, right: 0 (the callback was unregistered: its context may be gone).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 960 passed, 0 failed, 43 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib xgameruntime: 74 passed, 0 failed

Regression run

main (c4d37be, clean tree, no local changes):

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14618 MB

PR (d7ced4d, clean tree, no local changes):

xcl-smoke v1
commit: d7ced4d6ad1913c0b28280dc287755eac9e3b41c
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1644 (PresentX 1644)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14486 MB

Not tested

  • a title that unregisters from inside a running association callback (the unregister would wait for it from that thread: wait = false is the one for that)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: checked XCL-BT-041 against the queue and xasync callback paths, wrote the state machine and the test (and confirmed it fails without the fix), rebased onto c4d37be, ran the test suite and scripts/smoke.ps1 regression runs with Scripts: smoke blocks print the game folder's name #677's title hashing, and drafted this PR description.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 8cd4248 (on its base c160d86).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record: 858 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: an_unregistered_association_callback_does_not_run.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 859 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Two tests were skipped with --skip on NVIDIA. Both fail on main 7f7e768 too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. heap_window_out_of_memory_falls_back_to_the_switch_form skips when XCL_HEAP_WINDOWS is unset (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record skips because Developer Mode is off on this PC (it cannot disable the driver cache). The AMD run does not set XCL_REQUIRE_GPU, so there both just print SKIPPED.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

XUserUnregisterForDeviceAssociationChanged dropped the registration and
ignored both the wait flag and the callbacks already handed to the
title's queue: a callback queued behind it still ran, with the title's
context - which the title is free to free once the call returns - and
`wait = true` returned without waiting for a running one.

Track each queued callback (queued / running / done): the unregister
marks a queued one done (the queue's later call skips it) and, with
`wait`, waits for a running one to finish before returning.

Assisted-by: OpenCode (Gemini 4 Neon)
@b3IKK
b3IKK force-pushed the xgameruntime/association-context-uaf branch from 8cd4248 to d7ced4d Compare November 24, 2026 21:32
@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto c4d37be and re-ran both with the current scripts/smoke.ps1 (#677's hashed itle: line): 960 passed, 0 failed, 43 ignored.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1418 #1583 solves the same problem (for #1389) in a different way: #1607, group D58. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@JJAutoCompare

Copy link
Copy Markdown

PR #1753 compatibility verification

Tested XGameRuntime association callback cancellation at d7ced4d6ad1913c0b28280dc287755eac9e3b41c.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8–32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5. D3D12 SDK layers absent. rustc 1.100.0 (0ef1bc386 2026-11-09). Unoptimized dev and test profiles with debug info disabled.
  • cargo build --workspace and cargo test --workspace --no-run succeeded outside the GPU lock.
  • cargo test -p xcl xgameruntime -- --nocapture reported 74 unit tests passed, 0 failed, 0 ignored. The matching libHttpClient integration test also reported a pass after returning early because XCL_SAMPLE_DLLS was unset. Two unit tests returned early for missing system xgameruntime.dll and audio endpoint.
  • an_unregistered_association_callback_does_not_run passed in both runs. Dispatching the manual completion queue after unregistering with wait=true left the callback count at zero. A separate registration received one callback when dispatched.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 ran once under the shared Arc lock. Cargo exited 101. Summed across 20 result lines in pr1753-suite.log: 941 passed, 19 failed, 43 ignored. The log contains 22 SKIPPED lines. Raw pass totals include tests that returned early.

Failures and skips

  • GPU unit tests accounted for 18 failures: 14 compute PSO creation errors (0x80070057) and four result mismatches involving FMA, mip sampling, f16 lane preservation, and a pixel-shader wave reduction. The built-in test title had one failure: RSSetDepthBiasX left the test pixel blue where green was expected.
  • The 22 skip lines comprise 17 for unavailable wave64, three for refused wave32 per-lane forms, one for driver-cache control, and one for unavailable heap windows.

Not tested

Retail-title smoke runs, a main baseline, other GPUs, and game-data cases requiring the unset XCL_SAMPLE_* inputs. The callback regression test exercises queued cancellation. Waiting for a callback already in flight was untested.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1753-suite.log and published this report.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows run on d7ced4d. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC.

cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 960 passed, 0 failed, 43 ignored, with 23 runtime skips in Cargo’s pass count. The queued-callback regression passed.

I also tested a callback that had already started on another thread. With wait=false, unregister returned while the callback was still running. With wait=true, unregister returned after the callback finished. The callback context stayed alive until both threads joined. The scratch fixture passed 1 of 1 with cargo test --offline --locked -j 4 -p xcl --lib local_unregister_waits_only_when_requested_for_running_callback -- --nocapture --test-threads=1, then passed in 20 of 20 fresh test processes. This covers unregister from a separate thread on a synthetic manual queue.

AI use: Codex (GPT-6, exact variant unspecified) wrote the scratch fixture, ran the tests and drafted this report.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…cl-dev#1753, Windows verbatim + Linux twin)

Windows hle/xgameruntime/mod.rs is the upstream hunk verbatim
(reference-only on Linux): AssociationCall gains token + Queued/
Running/Done state + condvar, ASSOCIATION_CALLS liveset tracks
in-flight callbacks; association_call skips canceled/non-queued
records, unregister marks queued ones Done and with wait=true joins
running ones. Upstream test ported verbatim.

Linux twin hle/xuser_linux.rs mirrors the same state machine on
xtaskqueue_linux (win64 ABI, submit_now bool path) with a
Linux-shaped twin test (manual queue + dispatch + token+1 pin).

Triage per keeper (land ONE, xcl-dev#1753 preferred): xcl-dev#1583 closes with
citation (its +2 is a comment on its own competing stopped/in_flight
registry, which stays out); xcl-dev#1418 stays out (Entry/manager +
running_threads + unknown-token-false + re-entrant self-skip is the
competing design; xcl-dev#1753 keeps the existing always-true unregister).
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
… upstream xcl-dev#1237 + xcl-dev#494 + xcl-dev#1382 loopback)

Port live heads e2a4b1d (xcl-dev#1237), bf21fd8 (xcl-dev#494), 2b765d2 (xcl-dev#1382), all
still OPEN vs upstream/main. Windows hunks already verbatim
reference-only; this is the Linux twin (win64 ABI).

xcl-dev#1237: InitialNotification<T> + notify_initial via queue_from/submit_now
on PORT_COMPLETION + udp/connectivity call fns; both Registers reject
null callback (E_INVALIDARG) and queue the current value.
xcl-dev#494: network_off() reads XCL_NETWORK directly (hle_linux has no netoff
yet) + connectivity_level() 1/3; GetConnectivityHint uses it.
xcl-dev#1382 portable: url_host_and_is_plain_loopback via IpAddr::is_loopback
+ subnet vectors; request_url/security_info/issuer stay Windows-only
(WinHTTP/crypt32 handles, no Linux consumer — same precedent as xcl-dev#843).

Already-landed on Linux, verified no change: xcl-dev#1247, xcl-dev#1753, xcl-dev#2021,
xcl-dev#1588 + Watch xcl-dev#2521/xcl-dev#2524/xcl-dev#2623.

Failing-first: new symbols 0 at HEAD; old Registers accepted cb==0 and
queued nothing. Gates: both checks 0 errors, xtaskqueue_linux 16/16,
lib 760/0/1 t=4, title 12 GPU-only, retail SIGSEGV +0x2237320 HOLDS.

@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 inspected the unregister state transition and callback completion path; I did not run tests.

for call in running {
let mut st = call.state.lock().unwrap();
while *st != CallState::Done {
st = call.done.wait(st).unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the title unregisters this token from inside its own callback with wait = true, this waits for Done, but the only code that sets Done for a running callback executes after the callback returns. That self-unregister therefore deadlocks the queue thread. Could the running state record its thread (or otherwise detect reentrant unregister) and skip waiting for the current callback, with a regression test?

@futurepro62

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by JJAutoCompare, thehollowedone, since none of them covers AMD. Tested exact head d7ced4d6 (on its base c4d37be).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 955 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: an_unregistered_association_callback_does_not_run.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 960 passed, 0 failed, 43 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 8b957bec too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

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.

8 participants