From nobody Sun Feb 8 07:57:51 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 828E31DFFD for ; Thu, 8 Jan 2026 01:20: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=1767835216; cv=none; b=S/09+icvdrmQufL6zsCFHbBhFVzdXGTya4rD0Aoqu2lnnbT/DTD/NN3IBDGaj/GA4ok1y0xkw/JSt2BeuZU7LD1keNhN7cPWQhVceYDwxj2looq2Rulz0XC4b5BToUGUUQ5FjdxpDvLsh1b/Mtj2tLLFcYakaXkLygBee/DOl2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767835216; c=relaxed/simple; bh=/H11RUoj9nZUkp6wGj5b1WjMFvnZ8ARH4TPHwkprD58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZdnHrAka0OPfBxAamKGJsUgw1eQKWWrewlQETHzbaPxXXSPOt0OFsWpEsWNLF4W2PMDrYj0pGPlERybmoPO7Izr/JVmeQ30ZwlnmavekvT5jg9If072f91oc8JL65Wl26yMFxj49MfJyD+gNaIRNUYmuc0oOjSBWFyoBB2O6Hns= 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 lgeamrelo02.lge.com) (156.147.1.126) by 156.147.23.53 with ESMTP; 8 Jan 2026 10:10:12 +0900 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: jongan.kim@lge.com Received: from unknown (HELO jongan-kim-nissan-cdc.bee-live.svc.cluster.local) (10.159.39.42) by 156.147.1.126 with ESMTP; 8 Jan 2026 10:10:12 +0900 X-Original-SENDERIP: 10.159.39.42 X-Original-MAILFROM: jongan.kim@lge.com From: jongan.kim@lge.com To: gregkh@linuxfoundation.org, arve@android.com, tkjos@android.com, brauner@kernel.org, cmllamas@google.com, aliceryhl@google.com Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, jongan.kim@lge.com, ht.hong@lge.com, sunghoon.kim@lge.com, sanghun.lee@lge.com, jungsu.hwang@lge.com, seulgi.lee@lge.com Subject: [PATCH RESEND] binder: handle PID namespace conversion for freeze operation Date: Thu, 8 Jan 2026 10:10:11 +0900 Message-Id: <20260108011011.450202-1-jongan.kim@lge.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251203024140.175952-1-jongan.kim@lge.com> References: <20251203024140.175952-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 a3a1b5c33ba3..337d1f2c4533 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -5607,6 +5607,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(int 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 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; @@ -5715,13 +5749,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); @@ -5867,6 +5906,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 @@ -5875,9 +5915,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 @@ -5898,7 +5944,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