[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250611225848.1374929-3-neil@brown.name>
Date: Thu, 12 Jun 2025 08:57:03 +1000
From: NeilBrown <neil@...wn.name>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>,
Jan Kara <jack@...e.cz>
Cc: David Howells <dhowells@...hat.com>,
Tyler Hicks <code@...icks.com>,
Chuck Lever <chuck.lever@...cle.com>,
Jeff Layton <jlayton@...nel.org>,
Miklos Szeredi <miklos@...redi.hu>,
Amir Goldstein <amir73il@...il.com>,
Kees Cook <kees@...nel.org>,
Joel Granados <joel.granados@...nel.org>,
Namjae Jeon <linkinjeon@...nel.org>,
Steve French <smfrench@...il.com>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
netfs@...ts.linux.dev,
linux-kernel@...r.kernel.org,
ecryptfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org,
linux-nfs@...r.kernel.org,
linux-unionfs@...r.kernel.org,
linux-cifs@...r.kernel.org
Subject: [PATCH 2/2] fs/proc: take rcu_read_lock() in proc_sys_compare()
proc_sys_compare() is the ->d_compare function for /proc/sys.
It uses rcu_dereference() which assumes the RCU read lock is held and
can complain if it isn't.
However there is no guarantee that this lock is held by d_same_name()
(the caller of ->d_compare). In particularly d_alloc_parallel() calls
d_same_name() after rcu_read_unlock().
So this patch calls rcu_read_lock() before accessing the inode (which
seems to be the focus of RCU protection here), and drops it afterwards.
Signed-off-by: NeilBrown <neil@...wn.name>
---
fs/proc/proc_sysctl.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index cc9d74a06ff0..a4cdc0a189ef 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -917,19 +917,23 @@ static int proc_sys_compare(const struct dentry *dentry,
{
struct ctl_table_header *head;
struct inode *inode;
+ int ret;
/* Although proc doesn't have negative dentries, rcu-walk means
* that inode here can be NULL */
/* AV: can it, indeed? */
+ rcu_read_lock();
inode = d_inode_rcu(dentry);
- if (!inode)
- return 1;
- if (name->len != len)
- return 1;
- if (memcmp(name->name, str, len))
- return 1;
- head = rcu_dereference(PROC_I(inode)->sysctl);
- return !head || !sysctl_is_seen(head);
+ if (!inode ||
+ name->len != len ||
+ memcmp(name->name, str, len)) {
+ ret = 1;
+ } else {
+ head = rcu_dereference(PROC_I(inode)->sysctl);
+ ret = !head || !sysctl_is_seen(head);
+ }
+ rcu_read_unlock();
+ return ret;
}
static const struct dentry_operations proc_sys_dentry_operations = {
--
2.49.0
Powered by blists - more mailing lists