Re: [PATCH] rust_binder: fix process leak on proc file creation failure
From: Alice Ryhl
Date: Fri Nov 27 2026 - 06:26:16 EST
On Fri, Nov 27, 2026 at 03:38:46PM +0530, Adhyansh Verma wrote:
> 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>
Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Thanks!
Alice