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 3CBAD60703B5 for ; Mon, 2 Nov 2026 14:30:02 +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=RW+vtAzi Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jJDcm6vjvz3bV6; Tue, 03 Nov 2026 01:30:00 +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=1793629800; cv=none; b=JAKyafqYLUY7NehY7zN6laPZTsly78i1AZVpyjXx03sbbLa8+uqWYvzIvTgbA+/MtJCQYwCG/gVAt+uUR6WdchLg5keUwNQb79QW3usXLZWq9wtk5ZB2VwM2qjkCnrvo2OzHno5ZSbnFRJ2xveXbICAUN9Se70ekJc19Y7Vn6HgzwUyAcvrl8UzFtXWxDBnxUmzi56mJJWkG5DT/xmbvFyf4nnaIY72v7sn7Vn1q2Tn3s0NpAw9PTgH9As/8DPw7LYLkR0mB/R+DWOSvEvt25Q5v+XVENVyyOEvzPQ4SZSkwTLjCr30H9aoDk8+qynTplYqqGSK+dhY2D/vS1wQpqw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793629800; c=relaxed/relaxed; bh=SA3lGiy6S79OdVacoNeeNA0LWGoA0p1Ppo9PoyQO2Ks=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VwiwJGbHvSZBNnawhp1J1x9d/rmO++dic6DCtfRvfdmBPPEUY0lyXrxTiSIo1tw+MqBL1dxeoKaDSIVdQh6Yg2+Cro4VGTiSq4cR9gfWkI6tYaHJgv1+e1dRaLocirv7edHHH/8EV05+tdcvD8C71xjXDO2hlIrCMNio7KSnqGLYOi8tNgNOQIG/5LEFTr3za/G+VReZ15WbEcIbHzi071GSrJwBAbGK0l1pdpU4RXP0aRKLILAEsXDRF+GTxuDF9YsxQR4O3okuqvwIwmu6vH+1AzKKmWRw6HiO7GfBqjGNaTiIPCLHqs8T0Ah6ZYIDSMsHMxC/Ek5f7jK9Q9g7pg== 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=RW+vtAzi; 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=RW+vtAzi; 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 4jJDcm19pWz30W5 for ; Tue, 03 Nov 2026 01:30:00 +1100 (AEDT) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 4C06F60618; Mon, 2 Nov 2026 14:29:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E3171F00A17; Mon, 2 Nov 2026 14:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793629798; bh=SA3lGiy6S79OdVacoNeeNA0LWGoA0p1Ppo9PoyQO2Ks=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=RW+vtAzixHFdftAw+FFf7X1DqyjNjrm5rXJzLqMgENvUyh6lxSop0zLX2+vQS8q3U qRZVYZNACtSOXvDQAbomlArmJKHhYUFIBB2YrfNds0mv1wfARpxrZIlRmEwlYwFopc 5VdZGPqAWRIGCJ/WjNt4zJr1epJ29nqoWmRFqTaIbIhCMRcObitFsIcVlAgJcZod0r ACWF7EpwiUSzD42RWAztKJAwpw5HeZTLOr4cdHEhkz65HDjFGe1NQmquxEr2sddSYL RwpzOOV7W3I2TVeiKdqC8qxeUtM4wH2oSQalOWqHC31war9q1hlS5ta/ceFelklXjl B3xNbX+COlrjQ== From: Christian Brauner Date: Mon, 02 Nov 2026 15:21:49 +0100 Subject: [PATCH RFC 34/38] proc: sysctl: look at the table under sysctl_lock when creating an inode 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" Content-Transfer-Encoding: 7bit Message-Id: <20261102-work-procfs-bugfixes-v1-34-59422ed3e465@kernel.org> References: <20261102-work-procfs-bugfixes-v1-0-59422ed3e465@kernel.org> In-Reply-To: <20261102-work-procfs-bugfixes-v1-0-59422ed3e465@kernel.org> 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 X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2783; i=brauner@kernel.org; h=from:subject:message-id; bh=C8EYtx2R+lYWtFHGeY0iXNf5hNAMg0s7P8pl3m1iKgk=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9mJOj8UzGeLUCc9+ZM2pvbvxebnnhmpE+g+SSXWobN Dosy223dJSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzk5QVGhrYU5dR7fIy37FMe 6+iy+10qiYvReZc66/8Z5ztf76fa+DEynFt/fqvi+l16ifbTVh5Z/+J12e1rnoUitwqfWIbW8FV OYgQA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 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 proc_sys_make_inode() checks under sysctl_lock that @head isn't being unregistered, lets go of the lock, and then reads the mode of @table and calls ->set_ownership() with @head. That's fine as long as the caller holds @head in use, which keeps unregistering from getting past that check. The next patch has a caller that only pins the memory of @head. For that one the table, and whatever the owner of the header keeps behind it, is only there for as long as nobody unregisters the header, which happens under sysctl_lock. So read the mode and set the ownership before letting go of the lock. The ->set_ownership() callbacks only look up ids in a user namespace. No functional changes. Signed-off-by: Christian Brauner (Amutable) --- fs/proc/proc_sysctl.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 2150cf842919..a1242247f492 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -500,6 +500,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, struct ctl_table_root *root = head->root; struct inode *inode; struct proc_inode *ei; + umode_t mode; inode = new_inode(sb); if (!inode) @@ -509,12 +510,22 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, ei = PROC_I(inode); + inode->i_uid = GLOBAL_ROOT_UID; + inode->i_gid = GLOBAL_ROOT_GID; spin_lock(&sysctl_lock); if (unlikely(head->unregistering)) { spin_unlock(&sysctl_lock); iput(inode); return ERR_PTR(-ENOENT); } + /* + * The table, and whatever the owner of the header keeps behind it, + * is only there for as long as nobody unregisters the header, which + * happens under sysctl_lock. So look at them before letting go of it. + */ + mode = table->mode; + if (root->set_ownership) + root->set_ownership(head, &inode->i_uid, &inode->i_gid); ei->sysctl = head; ei->sysctl_entry = table; hlist_add_head_rcu(&ei->sibling_inodes, &head->inodes); @@ -522,8 +533,8 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, spin_unlock(&sysctl_lock); simple_inode_init_ts(inode); - inode->i_mode = table->mode; - if (!S_ISDIR(table->mode)) { + inode->i_mode = mode; + if (!S_ISDIR(mode)) { inode->i_mode |= S_IFREG; inode->i_op = &proc_sys_inode_operations; inode->i_fop = &proc_sys_file_operations; @@ -535,11 +546,6 @@ static struct inode *proc_sys_make_inode(struct super_block *sb, make_empty_dir_inode(inode); } - inode->i_uid = GLOBAL_ROOT_UID; - inode->i_gid = GLOBAL_ROOT_GID; - if (root->set_ownership) - root->set_ownership(head, &inode->i_uid, &inode->i_gid); - return inode; } -- 2.53.0