linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Randy Dunlap <rdunlap@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: linux-next: Tree for Aug 20 (Wno-alloc-size-larger-than)
Date: Wed, 25 Aug 2021 22:23:07 -0700	[thread overview]
Message-ID: <202108252222.E7F891E40B@keescook> (raw)
In-Reply-To: <6b2b9423-4b25-a31e-290f-3ab26a92a655@infradead.org>

On Wed, Aug 25, 2021 at 10:10:24PM -0700, Randy Dunlap wrote:
> On 8/25/21 8:54 PM, Kees Cook wrote:
> > On Wed, Aug 25, 2021 at 10:49:19AM -0700, Randy Dunlap wrote:
> > > On 8/25/21 10:04 AM, Kees Cook wrote:
> > > > On Tue, Aug 24, 2021 at 11:58:59AM +1000, Stephen Rothwell wrote:
> > > > > On Mon, 23 Aug 2021 18:24:44 -0700 Randy Dunlap <rdunlap@infradead.org> wrote:
> > > > > > 
> > > > > > This is just weird. What I am seeing is that for every source file
> > > > > > where gcc emits a warning: it then follows that up with this
> > > > > > > > cc1: warning: unrecognized command line option '-Wno-alloc-size-larger-than'
> > > > > 
> > > > > I see the same, as well as:
> > > > > 
> > > > > <stdin>:1515:2: warning: #warning syscall clone3 not implemented [-Wcpp]
> > > > > cc1: warning: unrecognized command line option '-Wno-alloc-size-larger-than'
> > > > > 
> > > > > But only on my gcc 7.3.1 builds (the rest are gcc 10).
> > > > > 
> > > > > > Smells like a gcc bug to me.
> > > > > 
> > > > > Yes
> > > > > 
> > > > > Also noted here: https://github.com/DynamoRIO/drmemory/issues/2099 (second comment)
> > > > 
> > > > Okay, I think this work-around should work. I've been able to reproduce
> > > > the weird conditions, and this seems to behave correctly. Andrew, can
> > > > you fixup the fixup with this?
> > > > 
> > > > 
> > > > diff --git a/Makefile b/Makefile
> > > > index 26640899e7ca..c1842014a5de 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -1094,8 +1094,13 @@ endif
> > > >    ifdef CONFIG_CC_IS_GCC
> > > >    # The allocators already balk at large sizes, so silence the compiler
> > > > -# warnings for bounds checks involving those possible values.
> > > > -KBUILD_CFLAGS += $(call cc-option, -Wno-alloc-size-larger-than)
> > > > +# warnings for bounds checks involving those possible values. While
> > > > +# -Wno-alloc-size-larger-than would normally be used here, some versions
> > > > +# of gcc (<9.1) weirdly don't handle the option correctly when _other_
> > > > +# warnings are produced (?!), so instead use SIZE_MAX to effectively
> > > > +# disable it.
> > > > +# https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au
> > > > +KBUILD_CFLAGS += $(call cc-option, -Walloc-size-larger-than=SIZE_MAX)
> > > >    endif
> > > >    # disable invalid "can't wrap" optimizations for signed / pointers
> > > > 
> > > 
> > > Hi Kees,
> > > 
> > > I get a lot of these:
> > > 
> > > ../include/linux/slab.h: In function ‘keyctl_instantiate_key_common’:
> > > cc1: warning: invalid argument ‘SIZE_MAX’ to ‘-Walloc-size-larger-than=’
> > 
> > O_o
> > 
> > I love how the documentation on this option is consistently wrong. :)
> > 
> > I haven't been able to exactly reproduce this error on godbolt.org, but
> > I got close with trunk GCC:
> > gcc: error: argument to '-Walloc-size-larger-than=' should be a non-negative integer optionally followed by a size unit
> > 
> > Even though stdint.h is included. :(
> > 
> > Okay. How about _this_ fix?
> > 
> > diff --git a/Makefile b/Makefile
> > index efa9bd36b158..141a851930e6 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1096,8 +1096,17 @@ endif
> >   ifdef CONFIG_CC_IS_GCC
> >   # The allocators already balk at large sizes, so silence the compiler
> > -# warnings for bounds checks involving those possible values.
> > -KBUILD_CFLAGS += $(call cc-option, -Wno-alloc-size-larger-than)
> > +# warnings for bounds checks involving those possible values. While
> > +# -Wno-alloc-size-larger-than would normally be used here, earlier versions
> > +# of gcc (<9.1) weirdly don't handle the option correctly when _other_
> > +# warnings are produced (?!). Using -Walloc-size-larger-than=SIZE_MAX
> > +# doesn't work (as it is documented to), silently resolving to "0" prior to
> > +# version 9.1 (and producing an error more recently). Numeric values larger
> > +# than PTRDIFF_MAX also don't work prior to version 9.1, which are silently
> > +# ignored, continuing to default to PTRDIFF_MAX. So, left with no other
> > +# choice, we must perform a versioned check to disable this warning.
> > +# https://lore.kernel.org/lkml/20210824115859.187f272f@canb.auug.org.au
> > +KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0901, -Wno-alloc-size-larger-than)
> >   endif
> >   # disable invalid "can't wrap" optimizations for signed / pointers
> 
> Yes, this works for me. Thanks.
> 
> Tested-by: Randy Dunlap <rdunlap@infradead.org>

Oh good! I've slowly been losing my mind trying to find a solution. :)
Thanks for testing each attempt!

-Kees

-- 
Kees Cook

      reply	other threads:[~2021-08-26  5:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  9:26 linux-next: Tree for Aug 20 Stephen Rothwell
2021-08-20 21:54 ` linux-next: Tree for Aug 20 (Wno-alloc-size-larger-than) Randy Dunlap
2021-08-21  5:48   ` Kees Cook
2021-08-21 19:09     ` Randy Dunlap
2021-08-23 10:37       ` Stephen Rothwell
2021-08-24  1:24         ` Randy Dunlap
2021-08-24  1:58           ` Stephen Rothwell
2021-08-25  1:59             ` Kees Cook
2021-08-25 17:04             ` Kees Cook
2021-08-25 17:49               ` Randy Dunlap
2021-08-26  3:54                 ` Kees Cook
2021-08-26  5:10                   ` Randy Dunlap
2021-08-26  5:23                     ` Kees Cook [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=202108252222.E7F891E40B@keescook \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=sfr@canb.auug.org.au \
    /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).