From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379416; b=TsPRgfvq+lvYwe4jrfJMYN6m3DcET0+aAPJ0SriOlj5Q9G587QE2UYZyjXfiOPLnUgwg Y60S6h7BsCUl5FE+1OjW7nIbTRPeWAHwFE/Y0QC3u16PmbkI8E8zUMwOgQF49LOo7p+ZX kkPh1oBoMm/T0xKzMsn3VAB0VgeRwKq98iQl3ryLoRifmBB0aPj/7RjaxcuZvm4Laq6Fb F+TnZT7lM2W5MIt4c7cSlApgELK4FtI1GC2bTQ/r+JXE6Vo7M+YwBp/wUC8fU2L0wAvIQ sE5cFA233VryjqGtO754bljuv34rVCr5JzP+TVxy+q4I32irQY406sbJgXwLpJoQThw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379416; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=7tQM3rcaDLBmXsZd0YK6814Qmr65GF+yvh855WGpXpY=; b=4YdiAIiIOJHz3T6gAe/qfy2ta6Uh3bOJ52YL3Kh/6F2nML402fn8dNN9KEQDGq+LXczg 28DLTcwc3WYCKeOQKTDH3/WUMF5aNsMyomO0bDXbBAxnDUUxmeqrlyvOEcGgyDsZkNy5T 1KQ1jXEmrxKBRBcvyLzwRQBpxwpteBwtUs8kcsCFwhbxstV6T5eu9IYoGK3Zwx9gULcmi azPq8vg1jyXitra7mflljbh16Hn77dYodintnI/3pUw3BL5XR77lU7t9G7pk4ASm9Kwhd p1mpsvy5ODwSB/LsTaGfH1L06ZjzZwOP2yiW/vcJSeSpZ/O7UCLxlmZJHCfe/xEjQgQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RNOQmFND; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B20F606A322; Fri, 4 Dec 2026 10:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RNOQmFND Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1C911F000C2; Fri, 4 Dec 2026 10:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379416; bh=7tQM3rcaDLBmXsZd0YK6814Qmr65GF+yvh855WGpXpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RNOQmFNDY7GMZVpzXLej+n8NKftxbDScncsLYjGCCjWNsCS4hCVRsUVDJ8tY/alPL UzT1BgxlCt/VvpCan6HFX0fjttmtrfvN7KhwY5Doz6HKh1L2P3g6l3CpC5rvMOcd6l bkdSZ0U/ZxNBI2OIz6mZLINB5ZfDJR+n4+Rql2RU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jann Horn , Christian Brauner , Chen Linxuan , Sasha Levin Subject: [PATCH 6.12 007/555] pidfd: restrict task access ioctls to the callers pid namespace Date: Fri, 4 Dec 2026 19:00:50 +0900 Message-ID: <20261204100604.219439968@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chen Linxuan [ Upstream commit ee8323fdc827c580425644db605a4be776cace57 ] pidfds can cross pid namespace boundaries: a task may obtain one for a process outside of its own pid namespace hierarchy through SO_PASSPIDFD or SO_PEERPIDFD, via SCM_RIGHTS, or through file descriptor inheritance. The namespace ioctls gate access with a ptrace check against the target's credentials only. That check does not account for the pid namespace relationship between the caller and the target, so a task inside a pid namespace can use a pidfd obtained across that boundary to acquire namespace file descriptors of a task outside of its hierarchy. procfs exposes the equivalent information only for tasks visible in the reader's pid namespace, and PIDFD_GET_INFO already answers with -EREMOTE for targets outside the caller's hierarchy. Extend that policy to the namespace ioctls: fail with -EREMOTE unless the target is visible in the caller's active pid namespace. Callers in ancestor pid namespaces are unaffected. Unlike PIDFD_GET_INFO, the visibility check is performed after the task lookup here, so reaped targets outside of the caller's pid namespace hierarchy answer -ESRCH instead of -EREMOTE. Link: https://lore.kernel.org/all/CAG48ez1T5-tUHVK_iHsgUtWa-inVdrZxA3E-ZCW0iENJvasKfg@mail.gmail.com Link: https://lore.kernel.org/all/20260925-gewischt-auftrag-tierzucht-c153cb3f9f74@brauner Suggested-by: Jann Horn Suggested-by: Christian Brauner Fixes: 5b08bd408534 ("pidfs: allow retrieval of namespace file descriptors") Cc: stable@vger.kernel.org Signed-off-by: Chen Linxuan Link: https://patch.msgid.link/20261027-pidfd-task-access-v1-1-d46cf0fa4ca1@black-desk.cn Signed-off-by: Christian Brauner (Amutable) [ sashal: Replaced the missing pid_in_current_pidns() helper with an equivalent pid_nr_ns(pid, task_active_pid_ns(current)) check, since that helper isn't in this tree. ] Signed-off-by: Sasha Levin --- fs/pidfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/pidfs.c b/fs/pidfs.c index b2dc613a64f6f..7a5efe86426bb 100644 --- a/fs/pidfs.c +++ b/fs/pidfs.c @@ -131,6 +131,14 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (!task) return -ESRCH; + /* + * Require the target to be visible in the caller's pid namespace + * for operations that grant access to its resources, mirroring + * procfs and PIDFD_GET_INFO. + */ + if (!pid_nr_ns(pid, task_active_pid_ns(current))) + return -EREMOTE; + /* * We're trying to open a file descriptor to the namespace so perform a * filesystem cred ptrace check. Hold @task's exec_update_lock for the -- 2.53.0