Skip to content

fix: prevent async task handle use-after-free - #299

Merged
ralfbiedert merged 1 commit into
masterfrom
fix/async-task-handle-race
Jul 22, 2026
Merged

fix: prevent async task handle use-after-free#299
ralfbiedert merged 1 commit into
masterfrom
fix/async-task-handle-race

Conversation

@ralfbiedert

Copy link
Copy Markdown
Owner

Summary

  • dispose cancellation registrations before freeing native task handles
  • prevent cancellation callbacks from calling Abort through a freed Rust TaskHandleInner
  • update the generated C# bindings snapshot

Root cause

The generated async wrapper disposed TaskHandle before the using-declared CancellationTokenRegistration. A concurrent cancellation callback could therefore enter TaskHandle.Abort while TaskHandle.Dispose freed the backing Rust Box, causing use-after-free and process-level heap corruption.

Validation

  • reproduced as a Windows 0xC0000005 crash in TaskHandle.Abort
  • fixed ordering survived 400,000 forced cancellation/completion races
  • full C# reference suite passed (185 tests)
  • reference-project binding snapshot generation passed

Dispose cancellation registrations before freeing native task handles so an in-flight cancellation callback cannot abort through a freed pointer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ralfbiedert
ralfbiedert merged commit b56f758 into master Jul 22, 2026
2 checks passed
@ralfbiedert
ralfbiedert deleted the fix/async-task-handle-race branch July 22, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant