xasync: cancelling a pending_with call frees its state while the worker thread still uses it (use-after-free) #214

Open
opened 2026-11-26 11:59:04 +00:00 by github-bot · 0 comments
Owner

@⁠kekonn on GitHub · 2026-11-26 11:53 UTC · original

What goes wrong

crates/victory-hle/src/modules/xasync.rs, pending_with (line 838 and on).

  1. XAsyncCancel (726) → complete_call(E_ABORT) → release → the provider's OP_CLEANUP (851) runs drop(Box::from_raw(state)).
  2. The thread spawned in OP_BEGIN (856) holds only state as usize. When the work returns, it does &*(state as *const Data) and locks it (864-865). That memory has already been freed.
  3. It then calls XAsyncComplete(block, hr, len) (867), which looks the call up by block address. If the title has begun another call on the same block since the cancel, the worker completes that call with the dialog's result and size.

The SAFETY comment at 853 ("cleanup waits for completion") does not hold: nothing makes OP_CLEANUP wait for the worker.

When

This runs on the default path. The only caller is xgameui.rs (~66): the title calls XGameUiShowTextEntryAsync, then cancels the block while the host dialog is still open. The cfg(test) stand-in returns at once and the tests never cancel, so this is untested.

Proposed fix (~20 lines, only in pending_with)

  • Hold the state in an Arc (Arc::into_raw / Arc::from_raw in OP_CLEANUP and on the refused-begin path). In OP_BEGIN, give the worker its own clone.
  • In OP_BEGIN, also take the worker's own Arc<Call> with call(data.block); the call is filed in CALLS before OP_BEGIN runs (~599). The worker finishes with complete_call(&me, block, hr, len) instead of XAsyncComplete by block, as XAsyncSchedule's Work { call, block } already does (612-627). complete_call returns early once done is set, so a cancelled call is left alone and a newer call on the block is never touched.
  • Unit test: a pending closure blocked on a channel, then XAsyncCancel, then begin a new call on the same block, then release the closure; assert the new call is still E_PENDING.

Upstream: no open PR touches xasync.rs or xgameui.rs.
Status: a fix is being prepared in kekonn/VIctory-7900XTX on branch claude/gifted-clarke-uxuqw8.


Generated by Claude Code

**@⁠kekonn** on GitHub · 2026-11-26 11:53 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/214) ### What goes wrong `crates/victory-hle/src/modules/xasync.rs`, `pending_with` (line 838 and on). 1. `XAsyncCancel` (726) → `complete_call(E_ABORT)` → `release` → the provider's `OP_CLEANUP` (851) runs `drop(Box::from_raw(state))`. 2. The thread spawned in `OP_BEGIN` (856) holds only `state as usize`. When the work returns, it does `&*(state as *const Data)` and locks it (864-865). That memory has already been freed. 3. It then calls `XAsyncComplete(block, hr, len)` (867), which looks the call up **by block address**. If the title has begun another call on the same block since the cancel, the worker completes *that* call with the dialog's result and size. The SAFETY comment at 853 ("cleanup waits for completion") does not hold: nothing makes `OP_CLEANUP` wait for the worker. ### When This runs on the default path. The only caller is `xgameui.rs` (~66): the title calls `XGameUiShowTextEntryAsync`, then cancels the block while the host dialog is still open. The cfg(test) stand-in returns at once and the tests never cancel, so this is untested. ### Proposed fix (~20 lines, only in `pending_with`) - Hold the state in an `Arc` (`Arc::into_raw` / `Arc::from_raw` in `OP_CLEANUP` and on the refused-begin path). In `OP_BEGIN`, give the worker its own clone. - In `OP_BEGIN`, also take the worker's own `Arc<Call>` with `call(data.block)`; the call is filed in `CALLS` before `OP_BEGIN` runs (~599). The worker finishes with `complete_call(&me, block, hr, len)` instead of `XAsyncComplete` by block, as `XAsyncSchedule`'s `Work { call, block }` already does (612-627). `complete_call` returns early once `done` is set, so a cancelled call is left alone and a newer call on the block is never touched. - Unit test: a pending closure blocked on a channel, then `XAsyncCancel`, then begin a new call on the same block, then release the closure; assert the new call is still `E_PENDING`. **Upstream:** no open PR touches `xasync.rs` or `xgameui.rs`. **Status:** a fix is being prepared in kekonn/VIctory-7900XTX on branch `claude/gifted-clarke-uxuqw8`. --- _Generated by [Claude Code](https://claude.ai/code)_ ```
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:59:04 +00:00
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/avatarmanz--VIctory-7900XTX#214
No description provided.