[PATCH v2] rust_binder: make work items of a deleted node a no-op

From: Nguyen Le Duy

Date: Tue Nov 24 2026 - 16:19:37 EST


When a node has no references left, do_work_locked() removes it from
the owner's nodes tree. However, a Node work item may still be queued
at that point. This happens when a strong zero2one increment is
scheduled through a NodeWrapper while the Node is already queued, all
references are dropped again, and the wrapper runs first and deletes
the node.

When the stale work item runs later, do_work_locked() calls
remove_node(self.ptr) again. If userspace has created a new node with
the same ptr in the meantime, this removes the new node from the tree.
The owner can then no longer look it up, so BR_RELEASE and BR_DECREFS
are never sent for it, and the next BINDER_TYPE_BINDER with that ptr
creates yet another node. Since update_node() looks nodes up by ptr,
freeing a buffer that refers to the hidden node decrements the other
one, and a later NodeRef::absorb() hits:

rust_kernel: panicked at drivers/android/binder/node.rs:822:17:
assertion `left != right` failed
left: 0
right: 0
kernel BUG at rust/helpers/bug.c:7!
Call Trace:
NodeRef::absorb
Process::insert_or_update_handle
AllocationView::transfer_binder_object
Thread::copy_transaction_data
Transaction::new
Thread::transaction

No race is needed, and with CONFIG_USER_NS=y an unprivileged user can
trigger this with a binderfs mount in its own user namespace.

Fix this by tracking in NodeInner whether the node has been deleted,
and making Node::do_work() and Node::cancel() only clear the delivery
state of a deleted node. A node is only deleted once it has no
references, so any BR_RELEASE and BR_DECREFS were already sent, and no
new reference can be taken on it. NodeWrapper::do_work() does not need
the check, since the node is never deleted while the wrapper is queued.

The delivery state is cleared by a new DeliveryState::node_done(), which
also replaces the open-coded reset that Node::do_work() already had.

Found with the Kani model checker. Tested with a reproducer on v7.4-rc3
in QEMU, x86_64 only.

Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Cc: stable@xxxxxxxxxxxxxxx
Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Nguyen Le Duy <inguyen@xxxxxxxxxx>
---
Changes in v2:
- Make the work items of a deleted node a no-op instead of checking the
tree entry in remove_node(), as suggested by Alice
- Add DeliveryState::node_done() to clear the Node's delivery state
- Link to v1: https://lore.kernel.org/r/20261122191322.929005-1-inguyen@xxxxxxxxxx

The reproducer was sent to the maintainers separately. The Kani
harnesses that found the bug pass with this patch.

I used an AI assistant (Claude) for the analysis, the reproducer, the
code and the changelog. The fix follows Alice's suggestion.

drivers/android/binder/node.rs | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs
index efdafc2..1f2bab6 100644
--- a/drivers/android/binder/node.rs
+++ b/drivers/android/binder/node.rs
@@ -124,6 +124,13 @@ impl DeliveryState {
self.has_pushed_wrapper = true;
self.has_strong_zero2one = true;
}
+
+ /// The `Node` was delivered or dropped, and the wrapper is not scheduled.
+ fn node_done(&mut self) {
+ self.has_pushed_node = false;
+ self.has_weak_zero2one = false;
+ self.has_strong_zero2one = false;
+ }
}

struct CountState {
@@ -178,6 +185,8 @@ struct NodeInner {
active_inc_refs: u8,
/// List of `NodeRefInfo` objects that reference this node.
refs: List<NodeRefInfo, { NodeRefInfo::LIST_NODE }>,
+ /// Set when `do_work_locked` removes the node from the owner's `nodes` tree.
+ is_deleted: bool,
}

use kernel::bindings::rb_node_layout;
@@ -238,6 +247,7 @@ impl Node {
has_oneway_transaction: false,
active_inc_refs: 0,
refs: List::new(),
+ is_deleted: false,
},
),
debug_id: super::next_debug_id(),
@@ -636,6 +646,7 @@ impl Node {
}
if no_active_inc_refs && !weak {
// Remove the node if there are no references to it.
+ inner.is_deleted = true;
guard.remove_node(self.ptr);
}
drop(guard);
@@ -727,9 +738,13 @@ impl DeliverToRead for Node {
return Ok(true);
}

- inner.delivery_state.has_pushed_node = false;
- inner.delivery_state.has_weak_zero2one = false;
- inner.delivery_state.has_strong_zero2one = false;
+ inner.delivery_state.node_done();
+
+ if inner.is_deleted {
+ // Nothing is pending for a deleted node, and userspace may already have reused its
+ // address for a new node, so leave the tree alone.
+ return Ok(true);
+ }

self.do_work_locked(writer, owner_inner)
}
@@ -743,6 +758,13 @@ impl DeliverToRead for Node {
return;
}

+ let inner = self.inner.access_mut(&mut owner_inner);
+ if inner.is_deleted {
+ // A deleted node has nothing to deliver, so don't requeue it.
+ inner.delivery_state.node_done();
+ return;
+ }
+
// If BINDER_THREAD_EXIT is invoked on a thread with a pending node refcount update, we
// should move ourselves to ensure the refcount update is still delivered.
if let Some(node) = ListArc::try_from_arc_borrow(self.as_arc_borrow()) {

base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
--
2.56.1