Re: [PATCH] rust: rbtree: call rb_erase() before KBox::from_raw() in remove_current()
From: Alice Ryhl
Date: Tue Dec 01 2026 - 08:50:34 EST
On Fri, Nov 27, 2026 at 08:05:53PM +0800, Bilal Hashim wrote:
> In CursorMut::remove_current(), KBox::from_raw(this) is currently called
> before bindings::rb_erase(&mut (*this).links, ...). Constructing and
> moving a KBox asserts exclusive (noalias) ownership over the allocation,
> which invalidates the raw pointer `this` and aliases with the subsequent
> bindings::rb_erase() call that mutates the rb_node links in C.
>
> Move bindings::rb_erase() before KBox::from_raw(this), matching the order
> already used in CursorMut::remove_neighbor().
>
> Tested with LLVM=-22 and Rust KUnit doctests in QEMU (372/372 passed,
> including all 11 rbtree doctests).
>
> Signed-off-by: Bilal Hashim <AeeSec@xxxxxxx>
Note that `KBox` doesn't actually emit `noalias` today, but it is of
course still semantically wrong.
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Alice