From: Keshav Verma <iganschel@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Carlos Llamas" <cmllamas@google.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Keshav Verma" <iganschel@gmail.com>
Subject: [PATCH v2] rust_binder: check context manager before creating node
Date: Thu, 18 Jun 2026 17:42:02 +0530 [thread overview]
Message-ID: <20260618121202.6258-1-iganschel@gmail.com> (raw)
In-Reply-To: <20260617222030.15189-1-iganschel@gmail.com>
Rust Binder currently creates the Binder node before checking whether a
context manager is already registered. If a context manager already exists,
set_manager_node() returns -EBUSY after node state has already been created.
Add a check before creating the node to match the C Binder ordering for
the common already registered case. Keep the final checks in set_manager_node()
so races with another caller are still handled after node creation.
Signed-off-by: Keshav Verma <iganschel@gmail.com>
---
Changes in v2:
- Fix commit message line wrapping.
- Drop pr_warn!() from the pre-check since userspace can trigger it.
drivers/android/binder/context.rs | 19 +++++++++++++++++++
drivers/android/binder/process.rs | 1 +
2 files changed, 20 insertions(+)
diff --git a/drivers/android/binder/context.rs b/drivers/android/binder/context.rs
index ddddb66b3557..f7ae84074f96 100644
--- a/drivers/android/binder/context.rs
+++ b/drivers/android/binder/context.rs
@@ -4,6 +4,7 @@
use kernel::{
alloc::kvec::KVVec,
+ cred::Credential,
error::code::*,
prelude::*,
security,
@@ -107,6 +108,24 @@ pub(crate) fn deregister_process(self: &Arc<Self>, proc: &Arc<Process>) {
}
}
+ pub(crate) fn check_manager(&self, cred: &Credential) -> Result {
+ let manager = self.manager.lock();
+ if manager.node.is_some() {
+ return Err(EBUSY);
+ }
+ security::binder_set_context_mgr(cred)?;
+
+ // If the context manager has been set before, ensure that we use the same euid.
+ let caller_uid = Kuid::current_euid();
+ if let Some(ref uid) = manager.uid {
+ if *uid != caller_uid {
+ return Err(EPERM);
+ }
+ }
+
+ Ok(())
+ }
+
pub(crate) fn set_manager_node(&self, node_ref: NodeRef) -> Result {
let mut manager = self.manager.lock();
if manager.node.is_some() {
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index 96b8440ceac6..d09facebddf6 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -741,6 +741,7 @@ fn set_as_manager(
} else {
(0, 0, 0)
};
+ self.ctx.check_manager(&self.cred)?;
let node_ref = self.get_node(ptr, cookie, flags as _, true, thread)?;
let node = node_ref.node.clone();
self.ctx.set_manager_node(node_ref)?;
--
2.39.5
prev parent reply other threads:[~2026-06-18 12:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 22:20 [PATCH] rust_binder: check context manager before creating node Keshav Verma
2026-06-18 10:27 ` Greg Kroah-Hartman
[not found] ` <CAPE_3zLCOwqa8Yb21oAb8i9AHW-UPqW=+9848fUtuTKK6wAZDA@mail.gmail.com>
2026-06-18 11:28 ` Greg Kroah-Hartman
2026-06-18 11:33 ` Miguel Ojeda
2026-06-18 11:52 ` Alice Ryhl
2026-06-18 12:12 ` Keshav Verma [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=20260618121202.6258-1-iganschel@gmail.com \
--to=iganschel@gmail.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tkjos@android.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.