* [PATCH] rust_binder: decrement requested_thread_count on BR_SPAWN_LOOPER write failure
@ 2026-11-28 15:37 Adhyansh Verma
2026-11-29 10:35 ` Alice Ryhl
0 siblings, 1 reply; 2+ messages in thread
From: Adhyansh Verma @ 2026-11-28 15:37 UTC (permalink / raw)
To: Alice Ryhl, Greg Kroah-Hartman, Carlos Llamas
Cc: Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Miguel Ojeda, rust-for-linux, linux-kernel
In Thread::read(), when more threads are needed for the binder thread pool,
self.process.needs_thread() is called to request a new looper thread.
needs_thread() checks that requested_thread_count is 0, and if so,
increments it to 1.
Subsequently, writer.write(&BR_SPAWN_LOOPER) writes the command to the
userspace read buffer. If this write fails (for example, if userspace
provided an invalid or faulting address), the error is propagated using
the '?' operator. However, requested_thread_count is never decremented on
failure.
Because userspace never received the BR_SPAWN_LOOPER command, it will
never register a new thread via BC_REGISTER_LOOPER (which is the only
place where requested_thread_count is decremented). Consequently,
requested_thread_count remains permanently set to 1. Any subsequent calls
to needs_thread() will see requested_thread_count != 0 and return false,
permanently starving the process binder thread pool from spawning looper
threads.
This mirrors the C Binder driver (drivers/android/binder.c), which
explicitly decrements proc->requested_threads if put_user(BR_SPAWN_LOOPER)
fails.
Introduce undo_needs_thread() on Process to decrement
requested_thread_count if the BR_SPAWN_LOOPER write fails.
Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Adhyansh Verma <adhyanshverma2010@gmail.com>
---
drivers/android/binder/process.rs | 7 +++++++
drivers/android/binder/thread.rs | 5 ++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index 1f4cb43f1de..a6d49e7dd84 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -1269,6 +1269,13 @@ pub(crate) fn needs_thread(&self) -> bool {
ret
}
+ pub(crate) fn undo_needs_thread(&self) {
+ let mut inner = self.inner.lock();
+ if inner.requested_thread_count > 0 {
+ inner.requested_thread_count -= 1;
+ }
+ }
+
pub(crate) fn request_death(
self: &Arc<Self>,
reader: &mut UserSliceReader,
diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
index 4ce6fc53320..d36ecd12dfe 100644
--- a/drivers/android/binder/thread.rs
+++ b/drivers/android/binder/thread.rs
@@ -1658,7 +1658,10 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
req.read_size as usize,
)
.writer();
- writer.write(&BR_SPAWN_LOOPER)?;
+ if let Err(err) = writer.write(&BR_SPAWN_LOOPER) {
+ self.process.undo_needs_thread();
+ return Err(err);
+ }
}
Ok(())
}
--
2.56.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] rust_binder: decrement requested_thread_count on BR_SPAWN_LOOPER write failure
2026-11-28 15:37 [PATCH] rust_binder: decrement requested_thread_count on BR_SPAWN_LOOPER write failure Adhyansh Verma
@ 2026-11-29 10:35 ` Alice Ryhl
0 siblings, 0 replies; 2+ messages in thread
From: Alice Ryhl @ 2026-11-29 10:35 UTC (permalink / raw)
To: Adhyansh Verma
Cc: Alice Ryhl, Greg Kroah-Hartman, Carlos Llamas,
Arve Hjønnevåg, Todd Kjos, Christian Brauner,
Miguel Ojeda, rust-for-linux, linux-kernel
I don't think we should take this patch: in general, -EFAULT from an
illegal userspace buffer is fatal in Binder and we don't need to recover
from it. (Also, C Binder does not decrement proc->requested_threads on
put_user(BR_SPAWN_LOOPER) failure either.)
See also: https://lore.kernel.org/r/20261129103508.897811-1-aliceryhl@google.com
Alice
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 10:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 15:37 [PATCH] rust_binder: decrement requested_thread_count on BR_SPAWN_LOOPER write failure Adhyansh Verma
2026-11-29 10:35 ` 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®