HLE: prevent concurrent XAsyncGetResult use-after-free and XAsyncBegin overwrite leak #2551

Closed
github-bot wants to merge 1 commit from gh-pr/2551/head into gh-pr/2551/base
Owner

@⁠reeledMarek on GitHub · 2026-11-25 15:40 UTC · original
reeledMarek:fix/hle-xasync-getresult-uaf-and-begin-race → main · +106 −27 · 1 files · 1 commits · closed without merging

Problem

  1. Concurrent XAsyncGetResult use-after-free: XAsyncGetResult cloned Arc<Call> from CALLS, invoked OP_GET_RESULT unlocked, and only afterward called release(block) (OP_CLEANUP). Two threads racing XAsyncGetResult on the same completed block could execute OP_GET_RESULT concurrently while the first thread's OP_CLEANUP freed the provider context.
  2. Concurrent XAsyncBegin overwrite leak: XAsyncBegin checked call(block) and inserted into CALLS under separate lock acquisitions, allowing two racing XAsyncBegin calls on the same block to overwrite and leak the first call without OP_CLEANUP.

Fix

  • In XAsyncGetResult, validate identity and buffer size and remove the entry from CALLS atomically under one lock (leaving the entry intact on E_NOT_SUFFICIENT_BUFFER or E_INVALIDARG), then invoke OP_GET_RESULT and OP_CLEANUP on the exclusively owned Call.
  • In XAsyncBegin, serialize the existing-call check and insertion under a single CALLS lock (using try_lock on left.done so lock ordering with complete_call is never inverted) and run stale OP_CLEANUP after unlocking.

Testing

  • Added concurrent_get_result_claims_result_and_runs_cleanup_once in crates/victory-hle/src/modules/xasync.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2551) `reeledMarek:fix/hle-xasync-getresult-uaf-and-begin-race` → `main` · +106 −27 · 1 files · 1 commits · closed without merging ### Problem 1. **Concurrent `XAsyncGetResult` use-after-free:** `XAsyncGetResult` cloned `Arc<Call>` from `CALLS`, invoked `OP_GET_RESULT` unlocked, and only afterward called `release(block)` (`OP_CLEANUP`). Two threads racing `XAsyncGetResult` on the same completed block could execute `OP_GET_RESULT` concurrently while the first thread's `OP_CLEANUP` freed the provider context. 2. **Concurrent `XAsyncBegin` overwrite leak:** `XAsyncBegin` checked `call(block)` and inserted into `CALLS` under separate lock acquisitions, allowing two racing `XAsyncBegin` calls on the same block to overwrite and leak the first call without `OP_CLEANUP`. ### Fix - In `XAsyncGetResult`, validate identity and buffer size and remove the entry from `CALLS` atomically under one lock (leaving the entry intact on `E_NOT_SUFFICIENT_BUFFER` or `E_INVALIDARG`), then invoke `OP_GET_RESULT` and `OP_CLEANUP` on the exclusively owned `Call`. - In `XAsyncBegin`, serialize the existing-call check and insertion under a single `CALLS` lock (using `try_lock` on `left.done` so lock ordering with `complete_call` is never inverted) and run stale `OP_CLEANUP` after unlocking. ### Testing - Added `concurrent_get_result_claims_result_and_runs_cleanup_once` in `crates/victory-hle/src/modules/xasync.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:59 +00:00
github-bot closed this pull request 2026-11-26 05:08:59 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:36 UTC · original

Automated triage for the maintainers.

Needs work: please add evidence. In crates/victory-hle/src/modules/xasync.rs, XAsyncGetResult now takes the Call out of CALLS under one lock before OP_GET_RESULT/OP_CLEANUP. XAsyncBegin now checks for a call left behind and inserts the new one under one lock, using try_lock on left.done. I checked the lock order: complete_call holds call.done and then takes CALLS (through release). The new try_lock avoids the inversion, and I found no deadlock.

Both races, though, need the title to use one async block from two threads at once: two XAsyncGetResult calls on the same completed block, or two XAsyncBegin calls on the same block. One block carries one call, so a title that follows the API would not do this. The PR gives no sign that the title does. The new test concurrent_get_result_claims_result_and_runs_cleanup_once shows the new code's behaviour, not something the title needs. The change also alters the order of events: the call is now gone from CALLS while the provider's OP_GET_RESULT runs. What would change the verdict: a log or trace from a run showing two threads on one block, or a reference for what the runtime does in that case.

CI: the check run passed on the current head.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2551#issuecomment-7171142890) <!-- victory-triage v1 head=fbd63111d7ecafa33e040bef5173360975de6056 verdict=needs-work at=2026-11-25T18:36:16Z --> Automated triage for the maintainers. **Needs work: please add evidence.** In `crates/victory-hle/src/modules/xasync.rs`, `XAsyncGetResult` now takes the `Call` out of `CALLS` under one lock before `OP_GET_RESULT`/`OP_CLEANUP`. `XAsyncBegin` now checks for a call left behind and inserts the new one under one lock, using `try_lock` on `left.done`. I checked the lock order: `complete_call` holds `call.done` and then takes `CALLS` (through `release`). The new `try_lock` avoids the inversion, and I found no deadlock. Both races, though, need the title to use **one async block from two threads at once**: two `XAsyncGetResult` calls on the same completed block, or two `XAsyncBegin` calls on the same block. One block carries one call, so a title that follows the API would not do this. The PR gives no sign that the title does. The new test `concurrent_get_result_claims_result_and_runs_cleanup_once` shows the new code's behaviour, not something the title needs. The change also alters the order of events: the call is now gone from `CALLS` while the provider's `OP_GET_RESULT` runs. What would change the verdict: a log or trace from a run showing two threads on one block, or a reference for what the runtime does in that case. CI: the `check` run passed on the current head. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Closing per triage — concurrent same-block XAsyncGetResult/XAsyncBegin violates single-owner API usage without evidence of a title doing this. Thanks for the review!

**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2551#issuecomment-7173182497) Closing per triage — concurrent same-block `XAsyncGetResult`/`XAsyncBegin` violates single-owner API usage without evidence of a title doing this. Thanks for the review!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Marvisak--VIctory!2551
No description provided.