public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	ghackmann@android.com, Greg Hackmann <ghackmann@google.com>,
	stable@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	Ingo Molnar <mingo@kernel.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>, Wei Wang <wvw@google.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	rdunlap@infradead.org, neilb@suse.com,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel.h: Disable -Wreturn-stack-address for _THIS_IP_
Date: Mon, 30 Jul 2018 13:01:19 -0700	[thread overview]
Message-ID: <20180730200119.GA8599@flashbox> (raw)
In-Reply-To: <CAKwvOdmYjgSMH5jESiK3kQa1DSyBpxesAmi_gbY9LL5_8XrA5g@mail.gmail.com>

On Mon, Jul 30, 2018 at 12:48:06PM -0700, Nick Desaulniers wrote:
> On Mon, Jul 30, 2018 at 11:39 AM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > On Mon, Jul 30, 2018 at 10:06:20AM -0700, Nick Desaulniers wrote:
> > > Starting with Clang-7.0, _THIS_IP_ generates -Wreturn-stack-address
> > > warnings for almost every translation unit. In general, I'd prefer to
> > > leave this on (returning the address of a stack allocated variable is in
> > > general a bad idea) and disable it only at whitelisted call sites.
> > >
> > > We can't do something like:
> > >  #pragma clang diagnostic push
> > >  #pragma clang diagnostic ignored "-Wreturn-stack-address"
> > >  <code>
> > >  #pragma clang diagnostic pop
> > >
> > > in a GNU Statement Expression or macro, hence we use _Pragma, which is
> > > its raison d'être: https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html
> > >
> > > Cc: stable@vger.kernel.org # 4.17, 4.14, 4.9, 4.4
> > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > > ---
> > >  include/linux/kernel.h | 10 +++++++++-
> > >  1 file changed, 9 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> > > index 941dc0a5a877..5906f5727f90 100644
> > > --- a/include/linux/kernel.h
> > > +++ b/include/linux/kernel.h
> > > @@ -168,7 +168,15 @@
> > >
> > >
> > >  #define _RET_IP_             (unsigned long)__builtin_return_address(0)
> > > -#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
> > > +#define _THIS_IP_  (                                                 \
> > > +{                                                                    \
> > > +     _Pragma("clang diagnostic push")                                \
> > > +     _Pragma("clang diagnostic ignored \"-Wreturn-stack-address\"")  \
> > > +     __label__ __here;                                               \
> > > +__here: (unsigned long)&&__here;                                     \
> > > +     _Pragma("clang diagnostic pop")                                 \
> > > +}                                                                    \
> > > +)
> > >
> > >  #ifdef CONFIG_LBDAF
> > >  # include <asm/div64.h>
> > > --
> > > 2.18.0.233.g985f88cf7e-goog
> > >
> >
> > This generates a ton of warnings with GCC:
> >
> > In file included from ./include/linux/spinlock.h:58,
> >                  from ./include/linux/mmzone.h:8,
> >                  from ./include/linux/gfp.h:6,
> >                  from ./include/linux/slab.h:15,
> >                  from ./include/linux/crypto.h:24,
> >                  from arch/x86/kernel/asm-offsets.c:9:
> > ./include/linux/bottom_half.h: In function ‘local_bh_disable’:
> > ./include/linux/bottom_half.h:19: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> >   __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
> >
> > ./include/linux/bottom_half.h:19: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> > ./include/linux/bottom_half.h:19: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> > ./include/linux/bottom_half.h: In function ‘local_bh_enable’:
> > ./include/linux/bottom_half.h:32: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> >   __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
> >
> > ./include/linux/bottom_half.h:32: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> > ./include/linux/bottom_half.h:32: error: ignoring #pragma clang diagnostic [-Werror=unknown-pragmas]
> > cc1: all warnings being treated as errors
> > make[1]: *** [Kbuild:56: arch/x86/kernel/asm-offsets.s] Error 1
> > make: *** [Makefile:1081: prepare0] Error 2
> 
> Ah, good catch.  I thought I had tested locally with gcc-8, but it
> seems that it was likely only godbolt.  I do see the errors locally
> when building with gcc-8.
> 
> >
> > A proper solution is probably going to involve what was done for the
> > -Wattribute-alias warnings from GCC 8 in commits 8793bb7f4a9d ("kbuild:
> > add macro for controlling warnings to linux/compiler.h") and
> > bee20031772a ("disable -Wattribute-alias warning for SYSCALL_DEFINEx()")
> >
> > I'll take a look at it in a bit unless someone beats me to it.
> 
> I'll fix this up, triple check with gcc-8, and attribute you in the
> Suggested-by tag.  Thank you for verifying.
> -- 
> Thanks,
> ~Nick Desaulniers

I forgot to mention there is a similar macro that will need this same
fix in arch/arm64/include/asm/processor.h (current_text_addr), if you
want to tackle it in v2. Do CC me on the next series so that I can test,
thank you for doing this!

Cheers,
Nathan

  reply	other threads:[~2018-07-30 20:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 17:06 [PATCH] kernel.h: Disable -Wreturn-stack-address for _THIS_IP_ Nick Desaulniers
2018-07-30 18:39 ` Nathan Chancellor
2018-07-30 19:48   ` Nick Desaulniers
2018-07-30 20:01     ` Nathan Chancellor [this message]
2018-07-30 21:15       ` Nick Desaulniers
2018-07-31  6:50 ` kbuild test robot
2018-07-31 16:46   ` Nick Desaulniers

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=20180730200119.GA8599@flashbox \
    --to=natechancellor@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ghackmann@android.com \
    --cc=ghackmann@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mka@chromium.org \
    --cc=ndesaulniers@google.com \
    --cc=neilb@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=wvw@google.com \
    --cc=yamada.masahiro@socionext.com \
    /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