HLE/xasync: fix pending_with cancel use-after-free and XAsyncComplete blocking wait race #300
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!300
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-300"
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?
@AscilCH on GitHub · 2026-11-24 23:25 UTC · original
AscilCH:fix/xasync-cancel-uaf-and-wait-race→main· +186 −22 · 1 files · 1 commits · openProblem
Two concurrency bugs in
crates/victory-hle/src/modules/xasync.rs:pending_withwhenXAsyncCancelraces with the worker thread:pending_withboxedDataand passedstate as usizeto the detached worker thread.XAsyncCancel(block)whilework()is running,XAsyncCancelcompletes the block withE_ABORT->OP_CLEANUP->Box::from_raw(state), freeingDataimmediately.work()later returnsOk(bytes), the worker dereferences the freedstate(use-after-free on a destroyedMutex) and callsXAsyncComplete(block, ...)which could also complete a newer call reusing the sameAsyncBlock.XAsyncGetStatus(block, true)can returnE_PENDING:result < 0 || required_size == 0,XAsyncCompletecalledrelease(block)(removingblockfromCALLSand executingOP_CLEANUP) before storingsizeandstatus.XAsyncGetStatus(block, true)in that window gotcall(block) == None, skipped waiting oncall.finished, and returnedE_PENDINGfrom a blocking wait.Fix
pending_with's state withArc<Data>, passing a clonedArcto the worker thread, and track a cancellation flag updated inOP_CANCEL/OP_CLEANUPso a canceled worker neither touches freed memory nor completes a reusedAsyncBlock.XAsyncComplete, keepblockregistered inCALLSwhileOP_CLEANUPruns, then storesize/statusand removeblockfromCALLStogether underlock(&CALLS)(preserving acyclic lock ordercall.done->CALLS).blocking_get_status_does_not_return_e_pending_during_cleanupandpending_with_cancel_does_not_use_after_free_or_complete_reused_block.Verification
rustfmt --edition 2024 --check crates/victory-hle/src/modules/xasync.rs(changed hunks): cleancargo test -p victory-hle --locked xasync -- --test-threads=1: 9 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic tests only, no game data.)
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.