Skip to contentSkip to conversation

rust_binder: disallow binder fd transfers

PATCH In review Carlos Llamas 1 participant 2 messages Nov 21 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Carlos Llamas

author maintainer
#1 lore raw

PATCH v2 1/1 rust_binder: disallow binder fd transfers

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().

---
v2: switch to atomic_load instead of volatile as suggested by Alice.

v1:
https://lore.kernel.org/all/[email protected]/

 drivers/android/binder/allocation.rs | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/android/binder/allocation.rs +12 -1
index 927bf47d5d20..f998744f075d 100644
@@ -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,
Signature · 1 line
2.56.1.809.ga0b61035b5-goog

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#3 lore raw
Quoted 21 lines · On Sat, Nov 21, 2026 at 06:35:16PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] rust_binder: missing Fixes trailer for Allocation::info_add_fd() fix
--

commit a963eb2d22cc916873581ff387f2fed49b4fb5e1
Author: Carlos Llamas <[email protected]>

Quoted 12 lines

rust_binder: disallow binder fd transfers

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().

Quoted 10 lines
Quoted 1 line

[Severity: Low]
Should this include a Fixes tag for the commit that introduced Allocation::info_add_fd()?

Fixes eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

This is _not_ a bug introduced by Rust binder. A 'Fixes:' tag here is incorrect. We are restricting a behavior that has always existed.