From: Alice Ryhl <aliceryhl@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Carlos Llamas <cmllamas@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH 2/5] rust_binder: clamp write_read buffer sizes to usize::MAX
Date: Thu, 26 Nov 2026 09:53:41 +0000 [thread overview]
Message-ID: <20261126-binder-32bit-fixes-v1-2-22fc21baf6f8@google.com> (raw)
In-Reply-To: <20261126-binder-32bit-fixes-v1-0-22fc21baf6f8@google.com>
On 32-bit kernels, casting `BinderWriteRead` buffer sizes to `usize`
silently truncates lengths of 4 GiB or more modulo 2^32. Moreover,
`Thread::read()` subtracts the remaining writer length from the
untruncated 64-bit length, inflating `read_consumed` by multiples of
4 GiB. Thus, clamp these buffer lengths to `usize::MAX` and compute
`read_consumed` from the clamped length.
Cc: stable@vger.kernel.org
Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
drivers/android/binder/thread.rs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
index 54a208caebe1..8357313875d5 100644
--- a/drivers/android/binder/thread.rs
+++ b/drivers/android/binder/thread.rs
@@ -1520,9 +1520,10 @@ fn oneway_transaction_inner(self: &Arc<Self>, info: &mut TransactionInfo) -> Bin
fn write(self: &Arc<Self>, req: &mut BinderWriteRead) -> Result {
let write_start = req.write_buffer.wrapping_add(req.write_consumed);
- let write_len = req.write_size.saturating_sub(req.write_consumed);
+ let write_len = usize::try_from(req.write_size.saturating_sub(req.write_consumed))
+ .unwrap_or(usize::MAX);
let mut reader =
- UserSlice::new(UserPtr::from_addr(write_start as usize), write_len as usize).reader();
+ UserSlice::new(UserPtr::from_addr(write_start as usize), write_len).reader();
while reader.len() >= size_of::<u32>() && self.inner.lock().return_work.is_unused() {
let before = reader.len();
@@ -1592,9 +1593,10 @@ fn write(self: &Arc<Self>, req: &mut BinderWriteRead) -> Result {
fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
let read_start = req.read_buffer.wrapping_add(req.read_consumed);
- let read_len = req.read_size.saturating_sub(req.read_consumed);
+ let read_len =
+ usize::try_from(req.read_size.saturating_sub(req.read_consumed)).unwrap_or(usize::MAX);
let mut writer = BinderReturnWriter::new(
- UserSlice::new(UserPtr::from_addr(read_start as usize), read_len as usize).writer(),
+ UserSlice::new(UserPtr::from_addr(read_start as usize), read_len).writer(),
self,
);
let (in_pool, has_transaction, thread_todo, use_proc_queue) = {
@@ -1654,13 +1656,13 @@ fn read(self: &Arc<Self>, req: &mut BinderWriteRead, wait: bool) -> Result {
}
}
- req.read_consumed += read_len - writer.len() as u64;
+ req.read_consumed += (read_len - writer.len()) as u64;
// Write BR_SPAWN_LOOPER if the process needs more threads for its pool.
if has_noop_placeholder && in_pool && self.process.needs_thread() {
let mut writer = UserSlice::new(
UserPtr::from_addr(req.read_buffer as usize),
- req.read_size as usize,
+ usize::try_from(req.read_size).unwrap_or(usize::MAX),
)
.writer();
writer.write(&BR_SPAWN_LOOPER)?;
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-26 9:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:53 [PATCH 0/5] rust_binder: fix 32-bit truncation and alignment bugs Alice Ryhl
2026-11-26 9:53 ` [PATCH 1/5] rust_binder: read u64 pointer in BC_FREE_BUFFER Alice Ryhl
2026-11-26 9:53 ` Alice Ryhl [this message]
2026-11-26 9:53 ` [PATCH 3/5] rust_binder: reject transaction sizes exceeding usize::MAX Alice Ryhl
2026-11-26 9:53 ` [PATCH 4/5] rust_binder: align scatter-gather buffers to u64 Alice Ryhl
2026-11-26 9:53 ` [PATCH 5/5] rust_binder: use u64 for node and handle reference counts 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=20261126-binder-32bit-fixes-v1-2-22fc21baf6f8@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®