From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f73.google.com ([209.85.214.73]:35932 "EHLO mail-it0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731904AbeG3XLd (ORCPT ); Mon, 30 Jul 2018 19:11:33 -0400 Received: by mail-it0-f73.google.com with SMTP id m185-v6so778234itm.1 for ; Mon, 30 Jul 2018 14:34:39 -0700 (PDT) Date: Mon, 30 Jul 2018 14:34:12 -0700 In-Reply-To: <20180730213412.242849-1-ndesaulniers@google.com> Message-Id: <20180730213412.242849-3-ndesaulniers@google.com> Mime-Version: 1.0 References: <20180730213412.242849-1-ndesaulniers@google.com> Subject: [PATCH v2 2/2] kernel.h: Disable -Wreturn-stack-address for _THIS_IP_ From: Nick Desaulniers To: akpm@linux-foundation.org, natechancellor@gmail.com Cc: arnd@arndb.de, paul.burton@mips.com, christophe.leroy@c-s.fr, shorne@gmail.com, yamada.masahiro@socionext.com, keescook@chromium.org, mingo@kernel.org, gregkh@linuxfoundation.org, tglx@linutronix.de, rdunlap@infradead.org, bp@suse.de, neilb@suse.com, linux-kernel@vger.kernel.org, aryabinin@virtuozzo.com, dwmw@amazon.co.uk, sandipan@linux.vnet.ibm.com, linux@rasmusvillemoes.dk, paullawrence@google.com, andreyknvl@google.com, will.deacon@arm.com, ghackmann@android.com, stable@vger.kernel.org, ghackmann@google.com, mka@chromium.org, jpoimboe@redhat.com, wvw@google.com, avagin@openvz.org, Nick Desaulniers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: stable-owner@vger.kernel.org List-ID: 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" #pragma clang diagnostic pop in a GNU Statement Expression or macro, hence we use _Pragma, which is its raison d'=C3=AAtre: https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html We also can't use compiler specific pragma's without triggering -Werror=3Dunknown-pragmas in other compilers, so use __diag. Cc: stable@vger.kernel.org # 4.17, 4.14, 4.9, 4.4 Suggested-by: Nathan Chancellor Signed-off-by: Nick Desaulniers --- 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..909bb771c0ca 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -168,7 +168,15 @@ =20 =20 #define _RET_IP_ (unsigned long)__builtin_return_address(0) -#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }= ) +#define _THIS_IP_ ( \ +{ \ + __label__ __here; \ + __diag_push() \ + __diag_ignore(CLANG, 7, "-Wreturn-stack-address", "") \ +__here: (unsigned long)&&__here; \ + __diag_pop() \ +} \ +) =20 #ifdef CONFIG_LBDAF # include --=20 2.18.0.345.g5c9ce644c3-goog