[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250613031411.GH1647736@ZenIV>
Date: Fri, 13 Jun 2025 04:14:11 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: NeilBrown <neil@...wn.name>
Cc: Kees Cook <kees@...nel.org>, Joel Granados <joel.granados@...nel.org>,
linux-fsdevel@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] proc_sysctl: Fix up ->is_seen() handling
On Fri, Jun 13, 2025 at 03:41:34AM +0100, Al Viro wrote:
> On Fri, Jun 13, 2025 at 12:37:33PM +1000, NeilBrown wrote:
>
> > If two threads in the same namespace look up the same name at the same
> > time (which previously didn't exist), they will both enter
> > d_alloc_parallel() where neither will notice the other, so both will
> > create and install d_in_lookup() dentries, and then both will call
> > ->lookup, creating two identical inodes.
> >
> > I suspect that isn't fatal, but it does seem odd.
> >
> > Maybe proc_sys_compare should return 0 for d_in_lookup() (aka !inode)
> > dentries, and then proc_sys_revalidate() can perform the is_seen test
> > and return -EAGAIN if needed, and __lookup_slow() and others could
> > interpret that as meaning to "goto again" without calling
> > d_invalidate().
>
> Umm... Not sure it's the best solution; let me think a bit. Just need
> to finish going through the ported rpc_pipefs series for the final look
> and posting it; should be about half an hour or so...
FWIW, I think we need the following:
mismatch in name/len => return 1
in_lookup => return 0, let the fucker get rechecked later when
it ceases to be in_lookup; can only happen when we are called from
d_alloc_parallel().
otherwise, NULL inode => return 1; we are seeing a dentry halfway
through __dentry_kill(); caller is a lockless dcache lookup, under RCU
otherwise, check ->sysctl and sysctl_is_seen().
And yes, you do need rcu_dereference() there. Caller must be holding
rcu_read_lock or dentry->d_lock or have a counting reference to dentry.
Powered by blists - more mailing lists