mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rust_binder: disallow binder fd transfers
@ 2026-11-17 23:19 Carlos Llamas
  2026-11-18 11:29 ` Alice Ryhl
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Llamas @ 2026-11-17 23:19 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Christian Brauner, Carlos Llamas, Alice Ryhl
  Cc: kernel-team, linux-kernel, rust-for-linux

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>
---
 drivers/android/binder/allocation.rs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/android/binder/allocation.rs b/drivers/android/binder/allocation.rs
index 927bf47d5d20..8cd4c2a4402a 100644
--- a/drivers/android/binder/allocation.rs
+++ b/drivers/android/binder/allocation.rs
@@ -182,6 +182,13 @@ pub(crate) fn info_add_fd(
         buffer_offset: usize,
         close_on_free: bool,
     ) -> Result {
+        // SAFETY: `file` is valid; read `f_op` with `READ_ONCE` semantics.
+        let f_op = unsafe { (&raw const (*file.as_ptr()).f_op).read_volatile() };
+        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.703.gf848ed807c-goog


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] rust_binder: disallow binder fd transfers
  2026-11-17 23:19 [PATCH] rust_binder: disallow binder fd transfers Carlos Llamas
@ 2026-11-18 11:29 ` Alice Ryhl
  0 siblings, 0 replies; 2+ messages in thread
From: Alice Ryhl @ 2026-11-18 11:29 UTC (permalink / raw)
  To: Carlos Llamas
  Cc: Alice Ryhl, Greg Kroah-Hartman, Arve Hjønnevåg,
	Todd Kjos, Christian Brauner, kernel-team, linux-kernel,
	rust-for-linux

On Tue, Nov 17, 2026 at 11:19:26PM +0000, Carlos Llamas wrote:
> @@ -182,6 +182,13 @@ pub(crate) fn info_add_fd(
>          buffer_offset: usize,
>          close_on_free: bool,
>      ) -> Result {
> +        // SAFETY: `file` is valid; read `f_op` with `READ_ONCE` semantics.
> +        let f_op = unsafe { (&raw const (*file.as_ptr()).f_op).read_volatile() };
> +        if core::ptr::eq(f_op, &crate::rust_binder_fops.0) {
> +            // Binder FD transfers are not allowed.
> +            return Err(EINVAL);
> +        }

We have moved to using atomic_load instead of a volatile read when the C side
uses READ_ONCE. For example:

	// SAFETY: `file` is valid, so `f_op` is valid and aligned, and any
	// concurrent writes are atomic under LKMM.
	let f_op = unsafe { atomic_load(&raw mut (*file.as_ptr()).f_op, Relaxed) };

however the f_op field isn't read/modified with READ/WRITE_ONCE on the C
side, so I think we can use a bare access.

	let f_op = unsafe { (*file.as_ptr()).f_op };

Alice

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18 11:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 23:19 [PATCH] rust_binder: disallow binder fd transfers Carlos Llamas
2026-11-18 11:29 ` Alice Ryhl

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®