All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel.h: Disable -Wreturn-stack-address for _THIS_IP_
@ 2018-07-30 17:06 Nick Desaulniers
  2018-07-30 18:39 ` Nathan Chancellor
  2018-07-31  6:50 ` kbuild test robot
  0 siblings, 2 replies; 7+ messages in thread
From: Nick Desaulniers @ 2018-07-30 17:06 UTC (permalink / raw)
  To: akpm
  Cc: mka, ghackmann, ghackmann, Nick Desaulniers, stable, Kees Cook,
	Ingo Molnar, Greg Kroah-Hartman, Josh Poimboeuf, Wei Wang,
	Masahiro Yamada, Randy Dunlap, NeilBrown, linux-kernel

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-07-31 16:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-07-30 21:15       ` Nick Desaulniers
2018-07-31  6:50 ` kbuild test robot
2018-07-31 16:46   ` Nick Desaulniers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.