Re: [PATCH] rust_binder: only remove a node from the tree if it is still there
From: Nguyen Le Duy
Date: Tue Nov 24 2026 - 16:41:45 EST
(Resending with everyone in Cc. My first reply went only to Alice by mistake...)
On Tue, Nov 24, 2026 at 12:13:27PM +0000, Alice Ryhl wrote:
> Nice catch, thanks for tracking this down!
>
> Instead of still running `do_work_locked()` on a node that was already
> deleted and checking the tree in `remove_node()`, perhaps `Node::do_work()`
> should simply be a no-op if the node has been deleted?
>
> If we track `is_deleted: bool` in `NodeInner` (set when `do_work_locked()`
> removes the node from `ProcessInner::nodes`), then when the stale `Node`
> work item later runs `Node::do_work()`, it can clear the `delivery_state`
> flags and return `Ok(true)` early without entering `do_work_locked()` or
> touching `nodes` at all (and `Node::cancel()` can skip re-queueing a
> deleted node as well).
>
> Since `do_work_locked()` only removes the node when `active_inc_refs == 0`
> and `!weak`, any required `BR_RELEASE`/`BR_DECREFS` was already sent when
> the node was deleted, and no new references can be acquired afterward.
>
> What do you think?
Thank you for the review. I agree that this way is cleaner. I have sent a v2 that does it this way, with a Suggested-by tag for you.
There are two details in the patch, in case you see them differently:
- `Node::cancel()` also clears the three delivery_state flags of a deleted node before it drops the work item, as `Node::do_work()` does. Otherwise has_pushed_node would stay set without a work item behind it.
- `NodeWrapper::do_work()` has no `is_deleted` check. `Node::do_work()` does not delete the node while the wrapper is queued, and a wrapper that deletes the node is no longer queued itself, so a wrapper never runs for a deleted node.
I checked again with the Kani harnesses that found the bug, and with the reproducer in QEMU. No problems were found.
Thanks,
Nguyen Le Duy