[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200124055358.GD832@sol.localdomain>
Date: Thu, 23 Jan 2020 21:53:58 -0800
From: Eric Biggers <ebiggers@...nel.org>
To: Gao Xiang <hsiangkao@....com>
Cc: linux-ext4@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-f2fs-devel@...ts.sourceforge.net,
Alexander Viro <viro@...iv.linux.org.uk>,
Daniel Rosenberg <drosen@...gle.com>,
Gabriel Krisman Bertazi <krisman@...labora.com>
Subject: Re: [PATCH] ext4: fix race conditions in ->d_compare() and ->d_hash()
On Fri, Jan 24, 2020 at 01:27:50PM +0800, Gao Xiang wrote:
> On Thu, Jan 23, 2020 at 09:16:01PM -0800, Eric Biggers wrote:
> > On Fri, Jan 24, 2020 at 01:04:25PM +0800, Gao Xiang wrote:
> > > > diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> > > > index 8964778aabefb..0129d14629881 100644
> > > > --- a/fs/ext4/dir.c
> > > > +++ b/fs/ext4/dir.c
> > > > @@ -671,9 +671,11 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
> > > > const char *str, const struct qstr *name)
> > > > {
> > > > struct qstr qstr = {.name = str, .len = len };
> > > > - struct inode *inode = dentry->d_parent->d_inode;
> > > > + const struct dentry *parent = READ_ONCE(dentry->d_parent);
> > >
> > > I'm not sure if we really need READ_ONCE d_parent here (p.s. d_parent
> > > won't be NULL anyway), and d_seq will guard all its validity. If I'm
> > > wrong, correct me kindly...
> > >
> > > Otherwise, it looks good to me...
> > > Reviewed-by: Gao Xiang <gaoxiang25@...wei.com>
> > >
> >
> > While d_parent can't be set to NULL, it can still be changed concurrently.
> > So we need READ_ONCE() to ensure that a consistent value is used.
>
> If I understand correctly, unlazy RCU->ref-walk will be guarded by
> seqlock, and for ref-walk we have d_lock (and even parent lock)
> in relative paths. So I prematurely think no race of renaming or
> unlinking evenually.
>
> I'm curious about that if experts could correct me about this.
>
Taking a seqlock for read doesn't prevent the protected data from changing.
It just allows the reader to detect that it changed.
So we still need to handle the dentry fields being changed concurrently here,
even if it will be detected by a read_seqcount_retry() later.
- Eric
Powered by blists - more mailing lists