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 5/5] rust_binder: use u64 for node and handle reference counts
Date: Thu, 26 Nov 2026 09:53:44 +0000 [thread overview]
Message-ID: <20261126-binder-32bit-fixes-v1-5-22fc21baf6f8@google.com> (raw)
In-Reply-To: <20261126-binder-32bit-fixes-v1-0-22fc21baf6f8@google.com>
On 32-bit platforms, node and handle reference counts currently use
usize, so an unprivileged process can overflow them using repeated
BC_ACQUIRE or BC_INCREFS commands. This triggers an overflow panic when
overflow checks are enabled, or wraps around and corrupts reference
counts when they are disabled. Thus, use u64 for node and handle
reference counts to prevent overflow, and saturate the UAPI counts
reported via BinderNodeInfoForRef at u32::MAX.
Cc: stable@vger.kernel.org
Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
drivers/android/binder/node.rs | 22 +++++++++++-----------
drivers/android/binder/process.rs | 4 ++--
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/drivers/android/binder/node.rs b/drivers/android/binder/node.rs
index b27554aacc95..33547b8e71c5 100644
--- a/drivers/android/binder/node.rs
+++ b/drivers/android/binder/node.rs
@@ -129,7 +129,7 @@ fn did_push_strong_zero2one_wrapper(&mut self) {
struct CountState {
/// The reference count.
- count: usize,
+ count: u64,
/// Whether the process that owns this node thinks that we hold a refcount on it. (Note that
/// even if count is greater than one, we only increment it once in the owning process.)
has_count: bool,
@@ -409,7 +409,7 @@ pub(crate) fn update_refcount_locked(
self: &DArc<Node>,
inc: bool,
strong: bool,
- count: usize,
+ count: u64,
owner_inner: &mut ProcessInner,
) -> Option<DLArc<Node>> {
let is_dead = owner_inner.is_dead;
@@ -506,7 +506,7 @@ pub(crate) fn incr_refcount_allow_zero2one_with_wrapper(
}
}
- pub(crate) fn update_refcount(self: &DArc<Self>, inc: bool, count: usize, strong: bool) {
+ pub(crate) fn update_refcount(self: &DArc<Self>, inc: bool, count: u64, strong: bool) {
self.owner
.inner
.lock()
@@ -519,8 +519,8 @@ pub(crate) fn populate_counts(
guard: &Guard<'_, ProcessInner, SpinLockBackend>,
) {
let inner = self.inner.access(guard);
- out.strong_count = inner.strong.count as u32;
- out.weak_count = inner.weak.count as u32;
+ out.strong_count = u32::try_from(inner.strong.count).unwrap_or(u32::MAX);
+ out.weak_count = u32::try_from(inner.weak.count).unwrap_or(u32::MAX);
}
pub(crate) fn populate_debug_info(
@@ -808,15 +808,15 @@ fn debug_print(&self, m: &SeqFile, prefix: &str, _tprefix: &str, hashed: bool) -
pub(crate) struct NodeRef {
pub(crate) node: DArc<Node>,
/// How many times does this NodeRef hold a refcount on the Node?
- strong_node_count: usize,
- weak_node_count: usize,
+ strong_node_count: u64,
+ weak_node_count: u64,
/// How many times does userspace hold a refcount on this NodeRef?
- strong_count: usize,
- weak_count: usize,
+ strong_count: u64,
+ weak_count: u64,
}
impl NodeRef {
- pub(crate) fn new(node: DArc<Node>, strong_count: usize, weak_count: usize) -> Self {
+ pub(crate) fn new(node: DArc<Node>, strong_count: u64, weak_count: u64) -> Self {
Self {
node,
strong_node_count: strong_count,
@@ -857,7 +857,7 @@ pub(crate) fn absorb(&mut self, mut other: Self) {
}
}
- pub(crate) fn get_count(&self) -> (usize, usize) {
+ pub(crate) fn get_count(&self) -> (u64, u64) {
(self.strong_count, self.weak_count)
}
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index f23dbe98d688..719e794757a2 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -231,7 +231,7 @@ pub(crate) fn update_node_refcount(
node: &DArc<Node>,
inc: bool,
strong: bool,
- count: usize,
+ count: u64,
othread: Option<&Thread>,
) {
let push = node.update_refcount_locked(inc, strong, count, self);
@@ -579,7 +579,7 @@ pub(crate) fn debug_print_stats(&self, m: &SeqFile, ctx: &Context) -> Result {
{
let mut refs = self.node_refs.lock();
- let (mut count, mut weak, mut strong) = (0, 0, 0);
+ let (mut count, mut weak, mut strong) = (0usize, 0u64, 0u64);
for r in refs.by_handle.values_mut() {
let node_ref = r.node_ref();
let (nstrong, nweak) = node_ref.get_count();
--
2.56.1.839.g22a8290db9-goog
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 ` [PATCH 2/5] rust_binder: clamp write_read buffer sizes to usize::MAX Alice Ryhl
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 ` Alice Ryhl [this message]
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-5-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®