From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 9FC85606D4D3 for ; Wed, 4 Nov 2026 19:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WUjVvSgY Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jKb2L2nCwz2xr2; Thu, 05 Nov 2026 06:23:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2600:3c04:e001:324:0:1991:8:25" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793820202; cv=none; b=gGNCYM4nh75RMRifoJAqJko+gURE++prpYGipszC42CzBT3+H3EGn8GQYvpe30FNnmeVkTBQCdGHVEiZtR/SLK8jqdZg4nzfCh1tlG+e2knb1Jd8gsHKBgIuY6ffr/BEsnoXVXVP4AywC76wThEPYKcVTjYVpXknMFinqZDfmB0NbinFLuKAMKlHpVhx0T3LYIaKdLf0UMSXziYt5FoaaY6sEIUZchbYZkSCAUEJ1sqJ311KWp6P2tE3gnwBXY9vEIaJYdRKoHwi1WH/ySRKEYcDzjmMLZgh2tIVHQUuMk0XyA/Cg0tAHlkYQS+TbYWhzfreqr4yyLDEBkzLQY0enw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793820202; c=relaxed/relaxed; bh=9dtN9D2ek/PODLB9eXKISWT+1DyRVltUAnsYO5R4w7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eG61TJEJriRJdbWiqdcjJro+u1uDiKyZ06OZjswEfnrEtEayGHo+DDLhJ6kM4IIURU4x1OOfmhJ8MhBpkGF4Y1t4wX+QMKm0bq5W9f36k8IQMrwGG3CIavzGbdl5ibgXSzjAYSEIEJZQfU56Sb3IvTBMtMCcmUYQJIWb5JZZ4iIjac2jgFTJr4gdIZCgDw4TkH7R7fXa6Z5YBNeCbFYTMiqvYcbNXXQhe1/LhZQcc9T+9hk+reO6wPW5WQP0woOkybucIi46kvwa8rY7dhb4nB0Xez28V+BnX8JX015bIDZm+eoCCTHKV29xTeBzaG41IniXItMAKsi9Cl2iHZqh4Q== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WUjVvSgY; dkim-atps=neutral; spf=pass (client-ip=2600:3c04:e001:324:0:1991:8:25; helo=tor.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WUjVvSgY; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2600:3c04:e001:324:0:1991:8:25; helo=tor.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) Received: from tor.source.kernel.org (tor.source.kernel.org [IPv6:2600:3c04:e001:324:0:1991:8:25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jKb2K43Fgz2xnQ for ; Thu, 05 Nov 2026 06:23:21 +1100 (AEDT) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 775D060A82; Wed, 4 Nov 2026 19:23:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 055C01F000C1; Wed, 4 Nov 2026 19:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793820199; bh=9dtN9D2ek/PODLB9eXKISWT+1DyRVltUAnsYO5R4w7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WUjVvSgYe5Hj7+VHJxqGCdVuPZtH9TtLIRIu84V4WAA6vFP1AvkW+oSj/edLc2ck/ AAJWe21jGN66rAVWXOLHwrW3BkgJ7C5MMC9kqPjYIm9KMsBUn46oa0vCJA/TU5q6rX iH5MZ7/d6lbSeiP9AbR9i30r2ap/96zzZx+nemJvi6mhYtlWM8sEF2UUpZwV40I+z3 +txyiwalAfhoSb0jj4BJxzYGfVLI7LPAybYz/+TrWrBDGQ0NUDbS+hRxwxJlmPbijJ EE86e3tlHpNNL7Pmd5DKa/IXf1VMJPtPlvfcVaYXoetHk9VmlRKFC3n8SLFdRpRElE JRmL7ZtyfUvGw== From: Christian Brauner To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jann Horn , Josef Bacik , Chris Mason , Jeff Layton , NeilBrown , Eric Dumazet , Thomas Gleixner , Al Viro , Jonathan Corbet , Christoph Hellwig , Greg Kroah-Hartman , Joel Granados , Kees Cook , Jan Kara , Jan Kara , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-um@lists.infradead.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org, ibm-acpi-devel@lists.sourceforge.net, jfs-discussion@lists.sourceforge.net, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-mm@kvack.org, linux-sh@vger.kernel.org, linux-usb@vger.kernel.org, samba-technical@lists.samba.org, sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-doc@vger.kernel.org, linux-serial@vger.kernel.org, linux-atm-general@lists.sourceforge.net, Takashi Iwai , linux-input@vger.kernel.org, linux-raid@vger.kernel.org, linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org, linux-debuggers@vger.kernel.org, "Christian Brauner (Amutable)" , Chuck Lever , stable@vger.kernel.org Subject: [PATCH RESEND v2 29/51] proc: don't walk through a non-directory when resolving a name Date: Wed, 4 Nov 2026 20:23:04 +0100 Message-ID: <20261104-work-procfs-bugfixes-v2-29-021c84d852e0@kernel.org> In-Reply-To: <20261104-work-procfs-bugfixes-v2-0-021c84d852e0@kernel.org> References: <20261104-work-procfs-bugfixes-v2-0-021c84d852e0@kernel.org> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2403; i=brauner@kernel.org; h=from:subject:message-id; bh=syoXv99Xi8HZbn/gUZHMWCnjRlLtpR5bAeJLx/CLQI8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9bnzfyJTJaHMu41dep952AaYXinG37t+WyDPu5f08x dN5TvXxjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgImwHGP4n7qS/1/T39mfA+ez nur5I3X/0v1ZE26+TomYpu8oNvN10zOG/0VzMx60c//Q3nGn5Li21/MFnmxuVnN23S5+YyFT+l7 1HzMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 __xlate_proc_name() walks the components of a name like "a/b/c" and takes whatever it finds for "a" and "b" as the directory to go on in. It never checks that they actually are directories. So proc_create("file/x") hangs x into the subdir tree of the regular file "file". Nobody can look x up there, but remove_proc_subtree() on the file removes and frees x along with it, behind the back of whoever registered x. pktgen passes the name the writer of "add_device" picks to proc_create_data(), and only the part in front of the '@' has to name a network device: echo "add_device lo@" > /proc/net/pktgen/kpktgend_0 echo "add_device lo@/x" > /proc/net/pktgen/kpktgend_1 echo "rem_device_all" > /proc/net/pktgen/kpktgend_0 echo "rem_device_all" > /proc/net/pktgen/kpktgend_1 The third write frees both entries and the fourth one makes kpktgend_1 call proc_remove() on the freed second one: BUG: KASAN: slab-use-after-free in proc_remove+0x8f/0xa0 Read of size 8 at addr ff110001134c8e70 by task kpktgend_1/243 Call Trace: proc_remove+0x8f/0xa0 pktgen_remove_device.isra.0+0x118/0x500 pktgen_rem_all_ifs+0xeb/0x1a0 pktgen_thread_worker+0x1b42/0x7280 The files of a network namespace belong to the root of its user namespace and these writes don't require a capability. So once pktgen is loaded an unprivileged user can do this in namespaces of its own. Treat a component that isn't a directory like one that doesn't exist. All names with a '/' that the tree passes in as literals only walk through directories. pktgen is fixed separately to not pass such names in the first place. Reported-by: Chris Mason Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/proc/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 4c3fcaf68ef4..6ac9c4c13897 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -170,7 +170,7 @@ static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret, de = *ret ?: &proc_root; while ((next = strchr(cp, '/')) != NULL) { de = pde_subdir_find(de, cp, next - cp); - if (!de) { + if (!de || !S_ISDIR(de->mode)) { WARN(1, "name '%s'\n", name); return -ENOENT; } -- 2.53.0