HLE/xasync: fix pending_with cancel use-after-free and XAsyncComplete blocking wait race #300
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-24T23:25:31Z.
Problem
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.