linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: remove racy hasattr check from attr get
Date: Sun, 8 Jan 2017 11:12:09 -0500	[thread overview]
Message-ID: <20170108161209.GE62847@bfoster.bfoster> (raw)
In-Reply-To: <20170108153008.GA10552@infradead.org>

On Sun, Jan 08, 2017 at 07:30:08AM -0800, Christoph Hellwig wrote:
> On Fri, Jan 06, 2017 at 02:37:12PM -0500, Brian Foster wrote:
> > xfs_attr_get() has an unlocked attribute fork check to optimize away a
> > lock cycle in cases where the fork does not exist or is otherwise empty.
> > This check is not safe, however, because an attribute fork short form to
> > extent format conversion includes a transient state that causes the
> > xfs_inode_hasattr() check to fail. Specifically,
> > xfs_attr_shortform_to_leaf() creates an empty extent format attribute
> > fork and then adds the existing shortform attributes to it.
> > 
> > This means that lookup of an existing xattr can spuriously return
> > -ENOATTR when racing against a setxattr that causes the associated
> > format conversion. This was originally reproduced by an untar on a
> > particularly configured glusterfs volume, but can also be reproduced on
> > demand with properly crafted xattr requests.
> > 
> > The format conversion occurs under the exclusive ilock. xfs_attr_get()
> > already has the proper locking and checks further down in the function
> > to handle this situation correctly. Drop the unlocked check to avoid the
> > spurious failure and rely on the existing logic.
> > 
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > ---
> > 
> > This survives a local xfstests run and the original glusterfs
> > reproducer. I also have an xfstests reproducer that I will post shortly.
> > 
> > Brian
> > 
> >  fs/xfs/libxfs/xfs_attr.c | 3 ---
> >  1 file changed, 3 deletions(-)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> > index af1ecb1..8fcbc52 100644
> > --- a/fs/xfs/libxfs/xfs_attr.c
> > +++ b/fs/xfs/libxfs/xfs_attr.c
> > @@ -131,9 +131,6 @@ xfs_attr_get(
> >  	if (XFS_FORCED_SHUTDOWN(ip->i_mount))
> >  		return -EIO;
> >  
> > -	if (!xfs_inode_hasattr(ip))
> > -		return -ENOATTR;
> > -
> 
> What about the similar pre-lock check in xfs_attr_remove?

Yep, will fix. Thanks for catching that..

Brian

> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

      reply	other threads:[~2017-01-08 16:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-06 19:37 [PATCH] xfs: remove racy hasattr check from attr get Brian Foster
2017-01-08 15:30 ` Christoph Hellwig
2017-01-08 16:12   ` Brian Foster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170108161209.GE62847@bfoster.bfoster \
    --to=bfoster@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).