Keep pending_with state alive across cancel and complete its own call #348
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
needs-logs
old-names
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!348
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-348"
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?
@ahmetbagci8 on GitHub · 2026-11-27 19:05 UTC · original
ahmetbagci8:fix/xasync-pending-with-cancel-uaf→main· +58894 −5220 · 200 files · 635 commits · closed without mergingSummary
In
crates/victory-hle/src/modules/xasync.rs,pending_withspawns a worker thread holding raw pointers toBox<Data>and*mut AsyncBlock. IfXAsyncCancelruns whilework()is still executing:complete_callinvokesOP_CLEANUP, which freesBox<Data>viaBox::from_rawwhile the worker thread is still running — causing a use-after-free whenwork()returnsOk(bytes)and locks the destroyedMutex.XAsyncComplete(block, hr, len)by rawblockaddress instead of completing its ownArc<Call>, which can erroneously complete a newer call begun on the reusedAsyncBlock.Changes
pending_withstate inArc<Data>and clone anArcfor the worker thread soOP_CLEANUPcannot freeDatawhileworkis in flight.call(data.block)inOP_BEGINand complete that generation withcomplete_call(&target, ...)instead ofXAsyncComplete(block, ...).canceled_pending_with_does_not_complete_reused_block.Tested
cargo test -p victory-hle --lib xasync:17 passed; 0 failed; 0 ignoredcargo clippy -p victory-hle --tests: clean (0 warnings)@Kal0s-design on GitHub · 2026-11-28 16:23 UTC · original
Checked this on native Windows. The new test does catch the bug: with only the test applied on the PR's base (
b6ea434),canceled_pending_with_does_not_complete_reused_blockfails 3 of 3 runs at the lastE_PENDINGassert (left0, rightE_PENDING), so the old worker'sXAsyncComplete(block, ...)really does complete the next call begun on the same block. With the full PR, the 17xasynctests pass. It also merges cleanly on currentmain(fe7c6e5), wherepending_withis still the old version, and no CI has run on it yet.The fix looks right to me:
call(data.block)inOP_BEGINgets this generation, sinceXAsyncBegininserts it intoCALLSbefore calling the provider.complete_callon that staleArc<Call>sees a state that isn'tPendingand returns before touching the block, so the late worker doesn't read a block the title may have reused or freed.Arc<Data>keeps the result buffer alive acrossOP_CLEANUP.It's also the pattern the comment on
complete_callalready asks for ("our own completions name the call they belong to, not the block"). I looked for other threads completing by block in non-test code andpending_withwas the only one.AI-assisted: yes
@TaynanGT on GitHub · 2026-11-29 11:37 UTC · original
Thanks for validating the generation-specific cancellation regression on native Windows. Failing three times on the base and passing with the fix is useful evidence. Please keep the result-lifetime and stale-worker cases intact when reconciling the test-module overlap with #436.
@TaynanGT on GitHub · 2026-11-30 17:11 UTC · original
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed