public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>, linux-xfs@vger.kernel.org
Subject: Re: "signed < sizeof()" bug in xfs_attr_shortform_verify() ?
Date: Thu, 27 Aug 2020 09:15:26 +0100	[thread overview]
Message-ID: <20200827081526.GE7605@infradead.org> (raw)
In-Reply-To: <20200825221842.GR6107@magnolia>

On Tue, Aug 25, 2020 at 03:18:42PM -0700, Darrick J. Wong wrote:
> On Wed, Aug 26, 2020 at 12:10:48AM +0300, Alexey Dobriyan wrote:
> > xfs_attr_shortform_verify() contains the following code:
> > 
> > 
> > 	int64_t size = ifp->if_bytes;
> >         /*
> >          * Give up if the attribute is way too short.
> >          */
> >         if (size < sizeof(struct xfs_attr_sf_hdr))
> >                 return __this_address;
> > 
> > 
> > In general "if (signed < sizeof())" is wrong because of how type
> > promotions work. Such check won't catch small negative values.
> > 
> > I don't know XFS well enough to know if negative values were excluded
> > somewhere above the callchain, but maybe someone else does.
> 
> The initial allocations are always positive and the subsequent
> xfs_idata_realloc are checked to prevent if_bytes from going negative,
> but it does seem funny to me that if_bytes is declared int64_t...

Yes, the int64_t is weird.  IIRC the signednes was done to simplify
some arithmertics in the reallocation case, but that shouldn't really
leak out..

      reply	other threads:[~2020-08-27  8:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25 21:10 "signed < sizeof()" bug in xfs_attr_shortform_verify() ? Alexey Dobriyan
2020-08-25 22:18 ` Darrick J. Wong
2020-08-27  8:15   ` Christoph Hellwig [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=20200827081526.GE7605@infradead.org \
    --to=hch@infradead.org \
    --cc=adobriyan@gmail.com \
    --cc=darrick.wong@oracle.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