linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: "Holger Hoffstätte" <holger@applied-asynchrony.com>,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH V2] xfs: allocate xattr buffer on demand
Date: Mon, 26 Aug 2019 11:59:27 -0700	[thread overview]
Message-ID: <20190826185927.GR1037350@magnolia> (raw)
In-Reply-To: <20190811010136.GD7777@dread.disaster.area>

On Sun, Aug 11, 2019 at 11:01:36AM +1000, Dave Chinner wrote:
> On Sat, Aug 10, 2019 at 11:45:35PM +0200, Holger Hoffstätte wrote:
> > 
> > Hi Dave -
> > 
> > great patch but I found something that seems off in xfs_attr3_leaf_getvalue:
> 
> It's not a "great patch" if there's something wrong with it. :/
> 
> > > @@ -2378,31 +2403,23 @@ xfs_attr3_leaf_getvalue((..snip..)
> > > +	if (args->flags & ATTR_KERNOVAL) {
> > >   		args->valuelen = args->rmtvaluelen;
> > > +		return 0;
> > >   	}
> > > -	return 0;
> > > +	return xfs_attr_copy_value(args, NULL, args->rmtvaluelen);
> > 
> > With gcc9 I get:
> > 
> >   CC      fs/xfs/libxfs/xfs_attr_leaf.o
> > In function 'xfs_attr_copy_value',
> >     inlined from 'xfs_attr3_leaf_getvalue' at fs/xfs/libxfs/xfs_attr_leaf.c:2425:9:
> > fs/xfs/libxfs/xfs_attr_leaf.c:421:2: warning: argument 2 null where non-null expected [-Wnonnull]
> >   421 |  memcpy(args->value, value, valuelen);
> >       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > In file included from ./arch/x86/include/asm/string.h:5,
> >                  from ./include/linux/string.h:20,
> >                  from ./include/linux/uuid.h:12,
> >                  from ./fs/xfs/xfs_linux.h:10,
> >                  from ./fs/xfs/xfs.h:22,
> >                  from fs/xfs/libxfs/xfs_attr_leaf.c:7:
> > fs/xfs/libxfs/xfs_attr_leaf.c: In function 'xfs_attr3_leaf_getvalue':
> > ./arch/x86/include/asm/string_64.h:14:14: note: in a call to function 'memcpy' declared here
> >    14 | extern void *memcpy(void *to, const void *from, size_t len);
> >       |              ^~~~~~
> > 
> > and sure enough, the NULL "value" arg is and passed as-is to memcpy in
> > xfs_attr_copy_value.
> 
> "sure enough", eh?
> 
> > Maybe you meant to sanitize the value when it's NULL?
> 
> Nope - look at the code:
> 
>         args->rmtvaluelen = be32_to_cpu(name_rmt->valuelen);
> >>>>    args->rmtblkno = be32_to_cpu(name_rmt->valueblk);
>         args->rmtblkcnt = xfs_attr3_rmt_blocks(args->dp->i_mount,
>                                                args->rmtvaluelen);
>         if (args->flags & ATTR_KERNOVAL) {
>                 args->valuelen = args->rmtvaluelen;
>                 return 0;
>         }
>         return xfs_attr_copy_value(args, NULL, args->rmtvaluelen);
> }
> 
> And the relevant code in xfs_attr_copy_value() does:
> 
>         /* remote block xattr requires IO for copy-in */
> >>>>    if (args->rmtblkno)
> >>>>            return xfs_attr_rmtval_get(args);
> 
>         memcpy(args->value, value, valuelen);
>         return 0;
> }
> 
> The memcpy() is never reached in this case. Hence the compiler
> warning is a false positive and the code is not going to crash here.
> 
> Regardless, I'm going to have to change the code because I doubt gcc
> will ever be smart enough to understand the code flow as it stands.
> We have to do this every so often to avoid false positive
> uninitialised variable warnings, so it's not like working around
> compiler issues is something new.
> 
> I'll post an updated version tomorrow....

Ping?

--D

> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com

      reply	other threads:[~2019-08-26 18:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  4:59 [PATCH V2] xfs: allocate xattr buffer on demand Dave Chinner
2019-08-01 20:37 ` Darrick J. Wong
2019-08-10 21:45 ` Holger Hoffstätte
2019-08-11  1:01   ` Dave Chinner
2019-08-26 18:59     ` Darrick J. Wong [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=20190826185927.GR1037350@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=holger@applied-asynchrony.com \
    --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).