mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Carlos Llamas <cmllamas@google.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Todd Kjos" <tkjos@android.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Alice Ryhl" <aliceryhl@google.com>
Cc: kernel-team@android.com, linux-kernel@vger.kernel.org,
	 rust-for-linux@vger.kernel.org
Subject: [PATCH v2] rust_binder: disallow binder fd transfers
Date: Sat, 21 Nov 2026 18:28:02 +0000	[thread overview]
Message-ID: <20261121182803.2600723-1-cmllamas@google.com> (raw)
In-Reply-To: <--in-reply-to=20261118112933.477541-1-aliceryhl@google.com>

Transferring a binder device fd via BINDER_TYPE_FD or BINDER_TYPE_FDA
has no valid use case and can create direct reference cycles that
prevent Process::release() from running when a queued transaction is
left unread. Moreover, a binder file is bound to the opening process's
task, credentials, and mmap state, so transferring it to another
process breaks binder's per-process ownership model.

Disallow binder device fd transfers by returning EINVAL in
Allocation::info_add_fd().

Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
v2: switch to atomic_load instead of volatile as suggested by Alice.

v1:
https://lore.kernel.org/all/20261117231927.2200674-1-cmllamas@google.com/

 drivers/android/binder/allocation.rs | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/android/binder/allocation.rs b/drivers/android/binder/allocation.rs
index 927bf47d5d20..f998744f075d 100644
--- a/drivers/android/binder/allocation.rs
+++ b/drivers/android/binder/allocation.rs
@@ -9,7 +9,11 @@
     bindings,
     fs::file::{File, FileDescriptorReservation},
     prelude::*,
-    sync::{aref::ARef, Arc},
+    sync::{
+        aref::ARef,
+        atomic::{atomic_load, Relaxed},
+        Arc,
+    },
     transmute::{AsBytes, FromBytes},
     uaccess::UserSliceReader,
     uapi,
@@ -182,6 +186,13 @@ pub(crate) fn info_add_fd(
         buffer_offset: usize,
         close_on_free: bool,
     ) -> Result {
+        // SAFETY: `file` is valid and any concurrent `f_op` writes are atomic.
+        let f_op = unsafe { atomic_load(&raw mut (*file.as_ptr()).f_op, Relaxed) };
+        if core::ptr::eq(f_op, &crate::rust_binder_fops.0) {
+            // Binder FD transfers are not allowed.
+            return Err(EINVAL);
+        }
+
         self.get_or_init_info().file_list.files_to_translate.push(
             FileEntry {
                 file,
-- 
2.56.1.809.ga0b61035b5-goog


           reply	other threads:[~2026-11-21 18:28 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <--in-reply-to=20261118112933.477541-1-aliceryhl@google.com>]

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=20261121182803.2600723-1-cmllamas@google.com \
    --to=cmllamas@google.com \
    --cc=aliceryhl@google.com \
    --cc=arve@android.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rust-for-linux@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®