Skip to content

Fix use-after-free when move-assigning pending async_scope futures - #2534

Open
Waterpine wants to merge 3 commits into
NVIDIA:mainfrom
Waterpine:fix/async-scope-future
Open

Waterpine wants to merge 3 commits into
NVIDIA:mainfrom
Waterpine:fix/async-scope-future

Conversation

@Waterpine

Copy link
Copy Markdown

Move-assigning over a future returned by exec::async_scope::spawn_future can destroy its state while the underlying operation is still pending. The defaulted move assignment replaces the owning unique_ptr directly, bypassing the future destructor's deferred cleanup protocol. Queued work can then access the freed state.

This is reproducible on a single thread: enqueue two operations on a run_loop, move-assign the second future over the first, then drain the loop.

Replace the defaulted move assignment with an implementation that moves the destination's old state into a temporary future before taking ownership of the source state. The temporary's destructor applies the existing cleanup protocol, allowing pending work to finish safely. Self-move assignment is explicitly handled.

Testing

  • Reproduced the original heap-use-after-free with AddressSanitizer.
  • Added regression coverage for assignment before completion, dropping a pending future, and assignment after completion.
  • All 24 related test cases passed with AddressSanitizer and UndefinedBehaviorSanitizer on Linux x86-64 with GCC 13.

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test aeeeffa

nvc++ >= 26.3 configures stdexec into std::execution, so the stdexec::
namespace does not exist in the GPU CI builds. Use the STDEXEC macro
like the rest of the test suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 9504289

This branch has not been deployed

No deployments
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.

2 participants