From nobody Sun Feb 8 05:13:00 2026 Received: from lgeamrelo13.lge.com (lgeamrelo13.lge.com [156.147.23.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98B0F2BEFFB for ; Thu, 29 Jan 2026 08:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769676616; cv=none; b=ep12Odac8DJOK2qmtVK5ULnYj8UNdXM+LpVwLaNupt0dWmgOxQyJK2a6YK574TkaOImQq24XNdwKBg8ppede5ylwC1NvtxVlc2TQg9YP9qykHEEHC1eM5XKlUiG/lNhOjN039fuLitsAf+XWFB9KM1z4INso+8f6unGwkr2e7B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769676616; c=relaxed/simple; bh=42ExUEcwpHqQp/+4fltsfJYhB19bOmGoT5X7nlBvvf8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EF5IGdmMuzX8fuROtixsrp/mPw/n4CXVxTN4Uqm8T2TCBnZ2l2Uuiqb1Jl4uH/qN/8kU+JzhunY3YOrfwrvbltmrPF0o4oX+3VS+gZIE47nGAXvMhTprgpaxc75bUHrekW8GvwsW86rx+CRONOXCdfzEFrzLA+9I/rm0x+gNmk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo04.lge.com) (156.147.1.127) by 156.147.23.53 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 156.147.1.127 X-Original-MAILFROM: jongan.kim@lge.com Received: from unknown (HELO jongan-kim-nissan-cdc.bee-live.svc.cluster.local) (10.159.44.48) by 156.147.1.127 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 10.159.44.48 X-Original-MAILFROM: jongan.kim@lge.com From: jongan.kim@lge.com To: aliceryhl@google.com, arve@android.com, brauner@kernel.org, cmllamas@google.com, gregkh@linuxfoundation.org, tkjos@android.com, ojeda@kernel.org, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org, yury.norov@gmail.com, vitaly.wool@konsulko.se, tamird@gmail.com, viresh.kumar@linaro.org, daniel.almeida@collabora.com Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, jongan.kim@lge.com, heesu0025.kim@lge.com, ht.hong@lge.com, jungsu.hwang@lge.com, kernel-team@android.com, sanghun.lee@lge.com, seulgi.lee@lge.com, sunghoon.kim@lge.com Subject: [PATCH v2 1/3] binder: handle PID namespace conversion for freeze operation Date: Thu, 29 Jan 2026 17:41:17 +0900 Message-Id: <20260129084119.32994-2-jongan.kim@lge.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260129084119.32994-1-jongan.kim@lge.com> References: <20260129084119.32994-1-jongan.kim@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: JongAn Kim Currently, when a freeze is attempted from a non-init PID namespace, there is a possibility that the wrong process in the init namespace may be frozen due to PID collision across namespaces. For example, if a container with PID namespace has a process with PID 100 (which maps to PID 5000 in init namespace), attempting to freeze PID 100 from the container could incorrectly match a different process with PID 100 in the init namespace. This patch fixes the issue by: 1. Converting the caller's PID from their namespace to init namespace 2. Matching against binder_proc->pid (which stores init namespace TGID) 3. Returning -EINVAL for invalid PIDs and -ESRCH for not-found processes This change ensures correct PID handling when binder freeze occurs in non-init PID namespace. Signed-off-by: JongAn Kim --- drivers/android/binder.c | 52 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 535fc881c8da..4695e459c924 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -5609,6 +5609,40 @@ static bool binder_txns_pending_ilocked(struct binde= r_proc *proc) return false; } =20 +/** + * binder_convert_to_init_ns_tgid() - Convert pid to global pid(init names= pace) + * @pid: pid from user space + * + * Converts a process ID (TGID) from the caller's PID namespace to the + * corresponding TGID in the init namespace. + * + * Return: On success, returns TGID in init namespace (positive value). + * On error, returns -EINVAL if pid <=3D 0, or -ESRCH if process + * not found or not visible in init namespace. + */ +static int binder_convert_to_init_ns_tgid(u32 pid) +{ + struct task_struct *task; + int init_ns_pid; + + /* already in init namespace */ + if (task_is_in_init_pid_ns(current)) + return pid; + + if (pid =3D=3D 0) + return -EINVAL; + + rcu_read_lock(); + task =3D pid_task(find_vpid(pid), PIDTYPE_PID); + init_ns_pid =3D task ? task_tgid_nr_ns(task, &init_pid_ns) : -ESRCH; + rcu_read_unlock(); + + if (!init_ns_pid) + return -ESRCH; + + return init_ns_pid; +} + static void binder_add_freeze_work(struct binder_proc *proc, bool is_froze= n) { struct binder_node *prev =3D NULL; @@ -5717,13 +5751,18 @@ static int binder_ioctl_get_freezer_info( struct binder_proc *target_proc; bool found =3D false; __u32 txns_pending; + int init_ns_pid =3D 0; =20 info->sync_recv =3D 0; info->async_recv =3D 0; =20 + init_ns_pid =3D binder_convert_to_init_ns_tgid(info->pid); + if (init_ns_pid < 0) + return init_ns_pid; + mutex_lock(&binder_procs_lock); hlist_for_each_entry(target_proc, &binder_procs, proc_node) { - if (target_proc->pid =3D=3D info->pid) { + if (target_proc->pid =3D=3D init_ns_pid) { found =3D true; binder_inner_proc_lock(target_proc); txns_pending =3D binder_txns_pending_ilocked(target_proc); @@ -5869,6 +5908,7 @@ static long binder_ioctl(struct file *filp, unsigned = int cmd, unsigned long arg) struct binder_freeze_info info; struct binder_proc **target_procs =3D NULL, *target_proc; int target_procs_count =3D 0, i =3D 0; + int init_ns_pid =3D 0; =20 ret =3D 0; =20 @@ -5877,9 +5917,15 @@ static long binder_ioctl(struct file *filp, unsigned= int cmd, unsigned long arg) goto err; } =20 + init_ns_pid =3D binder_convert_to_init_ns_tgid(info.pid); + if (init_ns_pid < 0) { + ret =3D init_ns_pid; + goto err; + } + mutex_lock(&binder_procs_lock); hlist_for_each_entry(target_proc, &binder_procs, proc_node) { - if (target_proc->pid =3D=3D info.pid) + if (target_proc->pid =3D=3D init_ns_pid) target_procs_count++; } =20 @@ -5900,7 +5946,7 @@ static long binder_ioctl(struct file *filp, unsigned = int cmd, unsigned long arg) } =20 hlist_for_each_entry(target_proc, &binder_procs, proc_node) { - if (target_proc->pid !=3D info.pid) + if (target_proc->pid !=3D init_ns_pid) continue; =20 binder_inner_proc_lock(target_proc); --=20 2.25.1 From nobody Sun Feb 8 05:13:00 2026 Received: from lgeamrelo11.lge.com (lgeamrelo11.lge.com [156.147.23.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4345A3803C8 for ; Thu, 29 Jan 2026 09:11:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769677887; cv=none; b=MI0/tDuHDx6ilGJqDxpYb7OT470F1/WLsQYFqR+avGA2ipGGsKzDiarsi/zVaTX4WCgfuSBxrIqOsfmVckaGQDGO0WekRgpCfuAzJEANDV53/yJ7UuKP2xL873Lutttdir0KcTkX/XP27tGJjRNQOyejF+43z1jtc6+nePxTs98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769677887; c=relaxed/simple; bh=oidqWeDXFJh9vIZTJJ/F/UAlYmkMB0+bEY8za2Ydd6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gw/j0drQZgHkaGs45A4aF6wNysQLXhe32/Fq65I9LElzUELoIsoWdF2dWhVzjAGsi1RWo1HPMo+ehmJd7h0O4yMfsY5+KcLdJ5pfs4jfbDwyPHGvzm5P64a2jVBBDWMA2QSbIig2VkSDyUGmRP3KwQfeJnrITqMtTzTDUq8LNeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo04.lge.com) (156.147.1.127) by 156.147.23.51 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 156.147.1.127 X-Original-MAILFROM: jongan.kim@lge.com Received: from unknown (HELO jongan-kim-nissan-cdc.bee-live.svc.cluster.local) (10.159.44.48) by 156.147.1.127 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 10.159.44.48 X-Original-MAILFROM: jongan.kim@lge.com From: jongan.kim@lge.com To: aliceryhl@google.com, arve@android.com, brauner@kernel.org, cmllamas@google.com, gregkh@linuxfoundation.org, tkjos@android.com, ojeda@kernel.org, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org, yury.norov@gmail.com, vitaly.wool@konsulko.se, tamird@gmail.com, viresh.kumar@linaro.org, daniel.almeida@collabora.com Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, jongan.kim@lge.com, heesu0025.kim@lge.com, ht.hong@lge.com, jungsu.hwang@lge.com, kernel-team@android.com, sanghun.lee@lge.com, seulgi.lee@lge.com, sunghoon.kim@lge.com Subject: [PATCH v2 2/3] rust: pid: add Pid abstraction and init_pid_ns helper Date: Thu, 29 Jan 2026 17:41:18 +0900 Message-Id: <20260129084119.32994-3-jongan.kim@lge.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260129084119.32994-1-jongan.kim@lge.com> References: <20260129084119.32994-1-jongan.kim@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: HeeSu Kim Add a new Pid abstraction in rust/kernel/pid.rs that wraps the kernel's struct pid and provides safe Rust interfaces for: - find_vpid_with_guard: Find a pid by number under RCU protection - pid_task_with_guard: Get the task associated with a pid under RCU protection Also add init_pid_ns() helper function to pid_namespace.rs to get a reference to the init PID namespace. These abstractions use lifetime-bounded references tied to RCU guards to ensure memory safety when accessing RCU-protected data structures. Signed-off-by: HeeSu Kim --- rust/kernel/lib.rs | 1 + rust/kernel/pid.rs | 100 +++++++++++++++++++++++++++++++++++ rust/kernel/pid_namespace.rs | 9 ++++ 3 files changed, 110 insertions(+) create mode 100644 rust/kernel/pid.rs diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index f812cf120042..60a518d65d0e 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -122,6 +122,7 @@ pub mod page; #[cfg(CONFIG_PCI)] pub mod pci; +pub mod pid; pub mod pid_namespace; pub mod platform; pub mod prelude; diff --git a/rust/kernel/pid.rs b/rust/kernel/pid.rs new file mode 100644 index 000000000000..00989b953c23 --- /dev/null +++ b/rust/kernel/pid.rs @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Process identifiers (PIDs). +//! +//! C header: [`include/linux/pid.h`](srctree/include/linux/pid.h) + +use crate::{bindings, ffi::c_int, sync::rcu, task::Task, types::Opaque}; + +/// Wraps the kernel's `struct pid`. +/// +/// This structure represents the Rust abstraction for a C `struct pid`. +/// A `Pid` represents a process identifier that can be looked up in diffe= rent +/// PID namespaces. +#[repr(transparent)] +pub struct Pid { + inner: Opaque, +} + +impl Pid { + /// Returns a raw pointer to the inner C struct. + #[inline] + pub fn as_ptr(&self) -> *mut bindings::pid { + self.inner.get() + } + + /// Finds a `struct pid` by its pid number within the current task's P= ID namespace. + /// + /// Returns `None` if no such pid exists. + /// + /// The returned reference is only valid for the duration of the RCU r= ead-side + /// critical section represented by the `rcu::Guard`. + /// + /// # Examples + /// + /// ``` + /// use kernel::pid::Pid; + /// use kernel::sync::rcu; + /// + /// let guard =3D rcu::read_lock(); + /// if let Some(pid) =3D Pid::find_vpid_with_guard(1, &guard) { + /// pr_info!("Found pid 1\n"); + /// } + /// ``` + /// + /// Returns `None` for non-existent PIDs: + /// + /// ``` + /// use kernel::pid::Pid; + /// use kernel::sync::rcu; + /// + /// let guard =3D rcu::read_lock(); + /// // PID 0 (swapper/idle) is not visible via find_vpid. + /// assert!(Pid::find_vpid_with_guard(0, &guard).is_none()); + /// ``` + #[inline] + pub fn find_vpid_with_guard<'a>(nr: i32, _rcu_guard: &'a rcu::Guard) -= > Option<&'a Self> { + // SAFETY: Called under RCU protection as guaranteed by the Guard = reference. + let ptr =3D unsafe { bindings::find_vpid(nr as c_int) }; + if ptr.is_null() { + None + } else { + // SAFETY: `find_vpid` returns a valid pointer under RCU prote= ction, + // and `Pid` is `#[repr(transparent)]` over `bindings::pid`. + Some(unsafe { &*(ptr as *const Self) }) + } + } + + /// Gets the task associated with this PID. + /// + /// Returns `None` if no task is associated with this PID. + /// + /// The returned reference is only valid for the duration of the RCU r= ead-side + /// critical section represented by the `rcu::Guard`. + /// + /// # Examples + /// + /// ``` + /// use kernel::pid::Pid; + /// use kernel::sync::rcu; + /// + /// let guard =3D rcu::read_lock(); + /// if let Some(pid) =3D Pid::find_vpid_with_guard(1, &guard) { + /// if let Some(task) =3D pid.pid_task_with_guard(&guard) { + /// pr_info!("Found task for pid 1\n"); + /// } + /// } + /// ``` + #[inline] + pub fn pid_task_with_guard<'a>(&'a self, _rcu_guard: &'a rcu::Guard) -= > Option<&'a Task> { + // SAFETY: Called under RCU protection as guaranteed by the Guard = reference. + let task_ptr =3D unsafe { bindings::pid_task(self.as_ptr(), bindin= gs::pid_type_PIDTYPE_PID) }; + if task_ptr.is_null() { + None + } else { + // SAFETY: `pid_task` returns a valid pointer under RCU protec= tion, + // and `Task` is `#[repr(transparent)]` over `bindings::task_s= truct`. + Some(unsafe { &*task_ptr.cast() }) + } + } +} diff --git a/rust/kernel/pid_namespace.rs b/rust/kernel/pid_namespace.rs index 979a9718f153..6029e3e120d0 100644 --- a/rust/kernel/pid_namespace.rs +++ b/rust/kernel/pid_namespace.rs @@ -63,3 +63,12 @@ unsafe impl Send for PidNamespace {} // SAFETY: It's OK to access `PidNamespace` through shared references from= other threads because // we're either accessing properties that don't change or that are properl= y synchronised by C code. unsafe impl Sync for PidNamespace {} + +/// Returns a reference to the init PID namespace. +/// +/// This is the root PID namespace that exists throughout the lifetime of = the kernel. +#[inline] +pub fn init_pid_ns() -> &'static PidNamespace { + // SAFETY: `init_pid_ns` is a global static that is valid for the life= time of the kernel. + unsafe { PidNamespace::from_ptr(core::ptr::addr_of!(bindings::init_pid= _ns)) } +} --=20 2.25.1 From nobody Sun Feb 8 05:13:00 2026 Received: from lgeamrelo13.lge.com (lgeamrelo13.lge.com [156.147.23.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98A9726B95B for ; Thu, 29 Jan 2026 08:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.147.23.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769676615; cv=none; b=JkRHr2Tmzz3b+Moi7jckwOHA+t5MKTeQ4EXQtqrRHzof+sOCDnJo0JRg+764H/017yf+seWsl/m95xXKmveDpzOwiMQeKEX7JeAGhojz90IF+pEr51Qswg/mxOk7Gr+dyh5Hp5zwq3AD4Vt5aYGOk+Dte34TuwldhkUhq2v5Ut8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769676615; c=relaxed/simple; bh=B6BX9LAqKeH96zCaktFruwWYpyDs6u+KS/1irGHdG1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ihNaY+YSyNILj4Fcf9c1QUh4sq3ZNMBFm0c8EOv57GPbFefr6/VAgR73+VU3RUUsNpWwmxyaxvI+fHQraka/4uz85L1QnAUtGJdPV+ludWhA0q9NKhSohuHoVzciL0CXbLOyUqcZQ3hixT1YL56FDRFGH/Q8MtPEaDW6geqCook= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.client-ip=156.147.23.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO lgeamrelo04.lge.com) (156.147.1.127) by 156.147.23.53 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 156.147.1.127 X-Original-MAILFROM: jongan.kim@lge.com Received: from unknown (HELO jongan-kim-nissan-cdc.bee-live.svc.cluster.local) (10.159.44.48) by 156.147.1.127 with ESMTP; 29 Jan 2026 17:41:21 +0900 X-Original-SENDERIP: 10.159.44.48 X-Original-MAILFROM: jongan.kim@lge.com From: jongan.kim@lge.com To: aliceryhl@google.com, arve@android.com, brauner@kernel.org, cmllamas@google.com, gregkh@linuxfoundation.org, tkjos@android.com, ojeda@kernel.org, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org, yury.norov@gmail.com, vitaly.wool@konsulko.se, tamird@gmail.com, viresh.kumar@linaro.org, daniel.almeida@collabora.com Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, jongan.kim@lge.com, heesu0025.kim@lge.com, ht.hong@lge.com, jungsu.hwang@lge.com, kernel-team@android.com, sanghun.lee@lge.com, seulgi.lee@lge.com, sunghoon.kim@lge.com Subject: [PATCH v2 3/3] rust_binder: handle PID namespace conversion for freeze operation Date: Thu, 29 Jan 2026 17:41:19 +0900 Message-Id: <20260129084119.32994-4-jongan.kim@lge.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260129084119.32994-1-jongan.kim@lge.com> References: <20260129084119.32994-1-jongan.kim@lge.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: HeeSu Kim Port PID namespace conversion logic from C binder to the Rust implementation. Without namespace conversion, freeze operations from non-init namespaces can match wrong processes due to PID collision. This adds proper conversion to ensure freeze operations target the correct process. Signed-off-by: HeeSu Kim --- drivers/android/binder/process.rs | 40 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/pro= cess.rs index 132055b4790f..41b89accea6a 100644 --- a/drivers/android/binder/process.rs +++ b/drivers/android/binder/process.rs @@ -22,6 +22,8 @@ id_pool::IdPool, list::{List, ListArc, ListArcField, ListLinks}, mm, + pid::Pid, + pid_namespace::init_pid_ns, prelude::*, rbtree::{self, RBTree, RBTreeNode, RBTreeNodeReservation}, seq_file::SeqFile, @@ -29,7 +31,7 @@ sync::poll::PollTable, sync::{ lock::{spinlock::SpinLockBackend, Guard}, - Arc, ArcBorrow, CondVar, CondVarTimeoutResult, Mutex, SpinLock, Un= iqueArc, + Arc, ArcBorrow, CondVar, CondVarTimeoutResult, Mutex, rcu, SpinLoc= k, UniqueArc, }, task::Task, types::ARef, @@ -1498,17 +1500,47 @@ pub(crate) fn ioctl_freeze(&self, info: &BinderFree= zeInfo) -> Result { } } =20 +/// Convert a PID from the current namespace to the global (init) namespac= e. +fn convert_to_init_ns_tgid(pid: u32) -> Result { + let current =3D kernel::current!(); + let init_ns =3D init_pid_ns(); + + if current.active_pid_ns().map(|ns| ns.as_ptr()) =3D=3D Some(init_ns.a= s_ptr()) { + // Already in init namespace. + return Ok(pid as i32); + } + + if pid =3D=3D 0 { + return Err(EINVAL); + } + + let rcu_guard =3D rcu::read_lock(); + + let pid_struct =3D Pid::find_vpid_with_guard(pid as i32, &rcu_guard).o= k_or(ESRCH)?; + let task =3D pid_struct.pid_task_with_guard(&rcu_guard).ok_or(ESRCH)?; + let init_ns_pid =3D task.tgid_nr_ns(Some(init_ns)); + + if init_ns_pid =3D=3D 0 { + return Err(ESRCH); + } + + Ok(init_ns_pid) +} + fn get_frozen_status(data: UserSlice) -> Result { let (mut reader, mut writer) =3D data.reader_writer(); =20 let mut info =3D reader.read::()?; + + let init_ns_pid =3D convert_to_init_ns_tgid(info.pid)?; + info.sync_recv =3D 0; info.async_recv =3D 0; let mut found =3D false; =20 for ctx in crate::context::get_all_contexts()? { ctx.for_each_proc(|proc| { - if proc.task.pid() =3D=3D info.pid as _ { + if proc.task.pid() =3D=3D init_ns_pid as _ { found =3D true; let inner =3D proc.inner.lock(); let txns_pending =3D inner.txns_pending_locked(); @@ -1530,13 +1562,15 @@ fn get_frozen_status(data: UserSlice) -> Result { fn ioctl_freeze(reader: &mut UserSliceReader) -> Result { let info =3D reader.read::()?; =20 + let init_ns_pid =3D convert_to_init_ns_tgid(info.pid)?; + // Very unlikely for there to be more than 3, since a process normally= uses at most binder and // hwbinder. let mut procs =3D KVec::with_capacity(3, GFP_KERNEL)?; =20 let ctxs =3D crate::context::get_all_contexts()?; for ctx in ctxs { - for proc in ctx.get_procs_with_pid(info.pid as i32)? { + for proc in ctx.get_procs_with_pid(init_ns_pid)? { procs.push(proc, GFP_KERNEL)?; } } --=20 2.25.1