[PATCH] rust_binder: fix process leak on proc file creation failure

From: Adhyansh Verma

Date: Fri Nov 27 2026 - 05:09:22 EST


In rust_binder_open(), Process::open() allocates and initializes a new
Process struct, registering it into the binder context's process list
(Context::manager.all_procs) via Context::register_process(). Because
Context holds an Arc<Process> in all_procs, and Process holds an
Arc<Context>, a cyclic reference is established.

Immediately following Process::open(), rust_binder_open() attempts to
create the proc file via BinderfsProcFile::new(). If this call fails
(e.g. under memory pressure when allocating the proc file dentry or
inode), rust_binder_open() returns err.to_errno() immediately.

Because open() returned an error, VFS drops the struct file and will
never invoke the ->release() file operation (rust_binder_release()).
Consequently, Process::deferred_release() is never scheduled, and
Context::deregister_process() is never called to remove the Process
from all_procs.

As a result, the cyclic reference prevents the Process from being
dropped, permanently leaking the Process struct, credentials, and task
references in kernel memory, while leaving a stale entry in all_procs.

Fix this by explicitly calling process.ctx.deregister_process(&process)
on the BinderfsProcFile::new() failure path to break the reference
cycle and allow the Process to be freed when exiting rust_binder_open().

Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Adhyansh Verma <adhyanshverma2010@xxxxxxxxx>
---
drivers/android/binder/rust_binder_main.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
index 56c78647523..7ca70dae659 100644
--- a/drivers/android/binder/rust_binder_main.rs
+++ b/drivers/android/binder/rust_binder_main.rs
@@ -401,7 +401,10 @@ unsafe impl<T> Sync for AssertSync<T> {}
match unsafe { BinderfsProcFile::new(inode, process.task.pid()) } {
Ok(Some(file)) => process.inner.lock().binderfs_file = Some(file),
Ok(None) => { /* pid already exists */ }
- Err(err) => return err.to_errno(),
+ Err(err) => {
+ process.ctx.deregister_process(&process);
+ return err.to_errno();
+ }
}

// SAFETY: This file is associated with Rust binder, so we own the `private_data` field.
--
2.56.1