Linux-Next Archive mirror
 help / color / mirror / Atom feed
* [PATCH] Compiler Attributes: Add __alloc_size for better bounds checking fix
@ 2021-08-27 15:13 Kees Cook
  0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2021-08-27 15:13 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kees Cook, Randy Dunlap, Stephen Rothwell,
	Linux Next Mailing List, linux-hardening

Adjust the warning logic to deal with pre-9.1 gcc behaviors.

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Hi Andrew, this is meant to replace:
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
Thanks!
---
 Makefile | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 41ed29b5af2b..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 += -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
-- 
2.30.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-27 15:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-27 15:13 [PATCH] Compiler Attributes: Add __alloc_size for better bounds checking fix Kees Cook

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 read-only IMAP folder(s) and NNTP newsgroup(s).