HLE: retain pending_with state across cancellation and prevent stale block completions #2522
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2522
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2522"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@reeledMarek on GitHub · 2026-11-25 15:16 UTC · original
reeledMarek:fix/hle-xasync-pending-uaf→main· +122 −42 · 1 files · 1 commits · openProblem
xasync::pending_withstored its shared closure/result buffer in a rawBox<Data>freed inOP_CLEANUP, while spawning a background thread that held the raw pointer and completed the call viaXAsyncComplete(block, ...).If the caller cancels the block with
XAsyncCancelbefore the worker thread finishes:XAsyncCancelimmediately triggersOP_CLEANUP, freeingDatawhile the worker still holds the pointer — causing a heap use-after-free when the worker writes its result bytes.XAsyncComplete(block, ...)matches by block address rather than the originalArc<Call>, so if the caller reuses the block for a new async call after cancellation, the late worker completes the unrelated new call.Fix
Datain anArc<Data>soOP_BEGINclones a strong reference for the worker thread, keeping the state alive even ifOP_CLEANUPruns on cancellation.Arc<Call>duringOP_BEGINand complete viacomplete_callonly whenis_current(¤t, block)is still true.Testing
canceled_pending_with_keeps_state_alive_and_leaves_reused_block_aloneincrates/victory-hle/src/modules/xasync.rs.cargo test -p xtask --lockedpasses asset policy.d27a5c1fa9to76f4d98999@Marvisak on GitHub · 2026-11-25 15:52 UTC · original · edited 2026-11-26 07:22 UTC
Automated triage for the maintainers.
Merge candidate. Thanks for the rebase.
pending_withincrates/victory-hle/src/modules/xasync.rsnow keeps its state in anArc.OP_BEGINhands the worker its own strong reference, so a cancel that runsOP_CLEANUPfirst can no longer free the state under the worker. The worker completes through theArc<Call>it captured (is_current+complete_call), notXAsyncCompleteby block address, so a late worker leaves a reused block's new call alone. That fitsmain'sXAsyncCancel→complete_call(E_ABORT)→releasepath. The new test covers both cancel-then-reuse cases.CI:
checkpassing; merges cleanly.Generated by Claude Code
@reeledMarek on GitHub · 2026-11-26 05:56 UTC · original
Rebased cleanly onto current
main(63bcca4, resolving the test-append conflict with30a5202).76f4d98999to367cd009b6@fuzeofficlal on GitHub · 2026-11-26 09:34 UTC · original · requested changes
Verified
76f4d989locally on Windows 11 x64 (git merge-treeonto63bcca43is clean):cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean (9.46s).cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed (0.56s).cargo test -p victory-hle --locked: 155 passed, 0 failed (153lib including all 14modules::xasync::tests+1fidelityfx +1no_dll_planting,4.53s).The
Arc<Data>worker reference fixes the lifetime onceOP_BEGINhas run, but two startup race conditions remain betweenXAsyncBegin(xasync.rs:604-606) andOP_BEGIN(xasync.rs:855-870):xasync.rs:558-563, 604-606, 855-865):XAsyncBeginpublishescallintoCALLS(:604) before callingprovider(OP_BEGIN)(:606). IfXAsyncCancelruns in that window,releaseinvokesOP_CLEANUPand drops the soleArc<Data>reference beforeOP_BEGINcallsArc::increment_strong_count(state).Callidentity race (xasync.rs:604-606, 866-883): becauseOP_BEGINre-looks upcall(data.block)by raw block address, a cancel + block-reuse in that startup window can causecurrentto bind to the newCallinstead of the canceled one.Please keep the provider context alive across
OP_BEGINstartup and bind the worker directly to the initiatingArc<Call>(and synchronize on the old worker's completion checkpoint instead ofsleep(50ms)in the reuse test).@reeledMarek on GitHub · 2026-11-26 10:37 UTC · original
Thanks @fuzeofficlal — addressed both startup races and the test synchronization:
register_callreturning the newly registeredArc<Call>.pending_with(viapending_with_handle), clonedworker_state = Arc::clone(&state)before publishing the call intoCALLSand bound the spawned worker directly to the returnedArc<Call>, eliminating both the startupOP_CLEANUPUAF window and thecall(data.block)re-lookup identity race.sleep(50ms)incanceled_pending_with_keeps_state_alive_and_leaves_reused_block_alonewithfirst_worker.unwrap().join().unwrap()to deterministically synchronize after the old worker's full completion path.@fuzeofficlal on GitHub · 2026-11-26 11:01 UTC · original · approved these changes
Reviewed
367cd009and confirmed both startup/reuse races from the previous round are cleanly fixed:pending_with_handleclonesworker_statebefore publishing the call throughregister_call, binds the worker thread directly to itsArc<Call>viacomplete_callinstead of re-looking up the block address inCALLS, and joins both worker handles deterministically incanceled_pending_with_keeps_state_alive_and_leaves_reused_block_alone.Verified locally on Windows 11 x64 (
367cd009):cargo run --locked -p xtask -- policy(191 files ok) andcargo clippy --workspace --all-targets -- -D warnings(default and--all-features): clean.cargo test -p victory-hle --lib modules::xasync: 14 passed, 0 failed.cargo test -p victory-hle --all-targets: 153 lib + 2 integration tests passed, 0 failed.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.