mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adhyansh Verma <adhyanshverma2010@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Carlos Llamas <cmllamas@google.com>
Cc: "Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	linux-kernel@vger.kernel.org,
	"Adhyansh Verma" <adhyanshverma2010@gmail.com>
Subject: [PATCH] rust_binder: fix process leak on proc file creation failure
Date: Fri, 27 Nov 2026 15:38:46 +0530	[thread overview]
Message-ID: <20261127100846.67589-1-adhyanshverma2010@gmail.com> (raw)

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@gmail.com>
---
 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


             reply	other threads:[~2026-11-27 10:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 10:08 Adhyansh Verma [this message]
2026-11-27 11:26 ` Alice Ryhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127100846.67589-1-adhyanshverma2010@gmail.com \
    --to=adhyanshverma2010@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=cmllamas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tkjos@android.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®