Skip to content

fix(executor): uaf#850

Merged
George-Miao merged 1 commit intocompio-rs:masterfrom
George-Miao:fix/executor/uaf
Apr 10, 2026
Merged

fix(executor): uaf#850
George-Miao merged 1 commit intocompio-rs:masterfrom
George-Miao:fix/executor/uaf

Conversation

@George-Miao
Copy link
Copy Markdown
Member

@George-Miao George-Miao commented Apr 9, 2026

This PR solves an UAF bug found by @fantix, and optimizes waking-up logic when a task has finished running and the JoinHandle is remotely polling at the same time.

Copilot AI review requested due to automatic review settings April 9, 2026 15:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a use-after-free in compio-executor task wake/scheduling teardown, and adjusts remote JoinHandle polling/waker-setting interactions to avoid races while also reducing unnecessary wake/spin behavior.

Changes:

  • Reworks task teardown to null out Shared earlier and waits for in-flight remote scheduling before dropping Shared to prevent UAF.
  • Tweaks remote polling waker-setting critical section to correctly handle “completed while setting waker” interleavings.
  • Adds an enable_log feature for opt-in test logging and updates the dev shell inputs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
flake.nix Adds cargo-flamegraph (and reorders python315) in the dev shell inputs.
compio-executor/tests/executor.rs Gates test log initialization behind feature = "enable_log" and inlines EnvFilter path.
compio-executor/src/task/remote.rs Refines remote waker-setting logic to handle completion/cancellation during the critical section.
compio-executor/src/task/mod.rs Removes busy-spin on SETTING_WAKER, changes wake conditions, nulls shared in Task::drop, and renames/repurposes teardown waiting API.
compio-executor/src/queue.rs Updates executor teardown to call drop() then wait_for_scheduling() per drained task.
compio-executor/Cargo.toml Introduces enable_log feature mapping to compio-log/enable_log; removes the prior dev-dep feature usage.
Comments suppressed due to low confidence (1)

compio-executor/src/task/mod.rs:321

  • wait_for_scheduling assumes that new schedulers will “see the null pointer and return early”, but this function no longer nulls header.shared itself. To make this invariant harder to violate, consider either (a) moving the shared.store(null, Release) back into wait_for_scheduling, or (b) documenting/enforcing the precondition (e.g., a debug_assert!(header.shared.load(Relaxed).is_null())) so future call sites don’t accidentally reintroduce UAF risk.
    /// Wait for wakers to finish scheduling, if any. This is necessary for
    /// `Executor` to drop `Shared` since scheduling requires it.
    pub(crate) fn wait_for_scheduling(&self) {
        let header = self.header();

        // Wait for any ongoing scheduling to complete.
        // We MUST do this to prevent use-after-free when we drop Shared.
        // This is safe in Executor::drop context because:
        // 1. All tasks have been cleared, so no new scheduling from task execution
        // 2. Only external wakers (from other threads) might still be scheduling
        // 3. Those wakers will see the null pointer and return early
        // 4. We only need to wait for ones that already loaded the pointer
        while header.state.load::<Strong>().is_scheduling() {
            crate::hint::spin_loop();
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@George-Miao George-Miao force-pushed the fix/executor/uaf branch 4 times, most recently from b34c77c to 5416095 Compare April 9, 2026 23:27
@George-Miao George-Miao added bug Something isn't working package: executor Related to compio-executor ci github action and other ci-related change labels Apr 9, 2026
@George-Miao George-Miao self-assigned this Apr 9, 2026
@George-Miao George-Miao force-pushed the fix/executor/uaf branch 5 times, most recently from 5fb1b78 to 85cbe06 Compare April 9, 2026 23:33
@George-Miao George-Miao added this pull request to the merge queue Apr 10, 2026
Merged via the queue into compio-rs:master with commit f6f1f4d Apr 10, 2026
75 checks passed
@George-Miao George-Miao deleted the fix/executor/uaf branch April 10, 2026 08:00
@github-actions github-actions bot mentioned this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci github action and other ci-related change package: executor Related to compio-executor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants