* + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree
@ 2021-10-12 20:56 akpm
2021-10-12 21:05 ` Stephen Rothwell
0 siblings, 1 reply; 4+ messages in thread
From: akpm @ 2021-10-12 20:56 UTC (permalink / raw)
To: keescook, mm-commits, sfr, willy
The patch titled
Subject: scripts: kernel-doc: Ignore __alloc_size() attribute
has been added to the -mm tree. Its filename is
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Kees Cook <keescook@chromium.org>
Subject: scripts: kernel-doc: Ignore __alloc_size() attribute
Fixes "Compiler Attributes: add __alloc_size() for better bounds checking"
so that the __alloc_size() macro is ignored for function prototypes when
generating kerndoc. Avoids warnings like:
./include/linux/slab.h:662: warning: Function parameter or member '1' not described in '__alloc_size'
./include/linux/slab.h:662: warning: Function parameter or member '2' not described in '__alloc_size'
./include/linux/slab.h:662: warning: expecting prototype for kcalloc(). Prototype was for __alloc_size() instead
Link: https://lkml.kernel.org/r/20211011180650.3603988-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
scripts/kernel-doc | 1 +
1 file changed, 1 insertion(+)
--- a/scripts/kernel-doc~compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
+++ a/scripts/kernel-doc
@@ -1789,6 +1789,7 @@ sub dump_function($$) {
$prototype =~ s/__weak +//;
$prototype =~ s/__sched +//;
$prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
+ $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//;
my $define = $prototype =~ s/^#\s*define\s+//; #ak added
$prototype =~ s/__attribute_const__ +//;
$prototype =~ s/__attribute__\s*\(\(
_
Patches currently in -mm which might be from keescook@chromium.org are
kasan-test-bypass-__alloc_size-checks.patch
rapidio-avoid-bogus-__alloc_size-warning.patch
compiler-attributes-add-__alloc_size-for-better-bounds-checking.patch
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
slab-clean-up-function-prototypes.patch
slab-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-kvmalloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-vmalloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-page_alloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
percpu-add-__alloc_size-attributes-for-better-bounds-checking.patch
maintainers-add-exec-binfmt-section-with-myself-and-eric.patch
binfmt_elf-reintroduce-using-map_fixed_noreplace.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree
2021-10-12 20:56 + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree akpm
@ 2021-10-12 21:05 ` Stephen Rothwell
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Rothwell @ 2021-10-12 21:05 UTC (permalink / raw)
To: akpm; +Cc: keescook, mm-commits, Jonathan Corbet, willy
[-- Attachment #1: Type: text/plain, Size: 401 bytes --]
Hi Andrew,
On Tue, 12 Oct 2021 13:56:10 -0700 akpm@linux-foundation.org wrote:
>
> The patch titled
> Subject: scripts: kernel-doc: Ignore __alloc_size() attribute
> has been added to the -mm tree. Its filename is
> compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
This patch has been added to Jon Corbet's tree today.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree
@ 2021-09-11 22:13 akpm
0 siblings, 0 replies; 4+ messages in thread
From: akpm @ 2021-09-11 22:13 UTC (permalink / raw)
To: mm-commits, will, samitolvanen, peterz, ojeda, nivedita,
ndesaulniers, nathan, masahiroy, elver, arnd, ardb, keescook
The patch titled
Subject: Compiler Attributes: check GCC version for __alloc_size attribute
has been added to the -mm tree. Its filename is
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Kees Cook <keescook@chromium.org>
Subject: Compiler Attributes: check GCC version for __alloc_size attribute
Unfortunately, just version checking the use of
-Wno-alloc-size-larger-than is not sufficient to make the __alloc_size
attribute behave correctly under older GCC versions. The attribute itself
must be disabled in those situations too, as there appears to be no way to
reliably silence the SIZE_MAX constant expression cases for GCC versions
less than 9.1:
In file included from ./include/linux/resource_ext.h:11,
from ./include/linux/pci.h:40,
from drivers/net/ethernet/intel/ixgbe/ixgbe.h:9,
from drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c:4:
In function 'kmalloc_node',
inlined from 'ixgbe_alloc_q_vector' at ./include/linux/slab.h:743:9:
./include/linux/slab.h:618:9: error: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
return __kmalloc_node(size, flags, node);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/slab.h: In function 'ixgbe_alloc_q_vector':
./include/linux/slab.h:455:7: note: in a call to allocation function '__kmalloc_node' declared here
void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_slab_alignment __malloc;
^~~~~~~~~~~~~~
Specifically:
-Wno-alloc-size-larger-than is not correctly handled by GCC < 9.1
https://godbolt.org/z/hqsfG7q84 (doesn't disable)
https://godbolt.org/z/P9jdrPTYh (doesn't admit to not knowing about option)
https://godbolt.org/z/465TPMWKb (only warns when other warnings appear)
-Walloc-size-larger-than=18446744073709551615 is not handled by GCC < 8.2
https://godbolt.org/z/73hh1EPxz (ignores numeric value)
Link: https://lkml.kernel.org/r/20210910201132.3809437-1-keescook@chromium.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Marco Elver <elver@google.com>
Cc: Will Deacon <will@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/compiler-gcc.h | 9 +++++++++
include/linux/compiler_attributes.h | 6 ------
include/linux/compiler_types.h | 5 +++++
3 files changed, 14 insertions(+), 6 deletions(-)
--- a/include/linux/compiler_attributes.h~compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
+++ a/include/linux/compiler_attributes.h
@@ -54,12 +54,6 @@
#define __aligned_largest __attribute__((__aligned__))
/*
- * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute
- * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size
- */
-#define __alloc_size(x, ...) __attribute__((__alloc_size__(x, ## __VA_ARGS__)))
-
-/*
* Note: users of __always_inline currently do not write "inline" themselves,
* which seems to be required by gcc to apply the attribute according
* to its docs (and also "warning: always_inline function might not be
--- a/include/linux/compiler-gcc.h~compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
+++ a/include/linux/compiler-gcc.h
@@ -153,3 +153,12 @@
#else
#define __diag_GCC_8(s)
#endif
+
+/*
+ * https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute
+ * However, prior to 9.1, -Wno-alloc-size-larger-than does not work,
+ * making this attribute unusable.
+ */
+#if GCC_VERSION < 90100
+#define __alloc_size(x, ...) /**/
+#endif
--- a/include/linux/compiler_types.h~compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
+++ a/include/linux/compiler_types.h
@@ -254,6 +254,11 @@ struct ftrace_likely_data {
#define asm_volatile_goto(x...) asm goto(x)
#endif
+/* If not specifically disabled, allow the use of __alloc_size attribute. */
+#ifndef __alloc_size
+# define __alloc_size(x, ...) __attribute__((__alloc_size__(x, ## __VA_ARGS__)))
+#endif
+
#ifdef CONFIG_CC_HAS_ASM_INLINE
#define asm_inline asm __inline
#else
_
Patches currently in -mm which might be from keescook@chromium.org are
rapidio-avoid-bogus-__alloc_size-warning.patch
compiler-attributes-add-__alloc_size-for-better-bounds-checking.patch
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
checkpatch-add-__alloc_size-to-known-attribute.patch
slab-clean-up-function-declarations.patch
slab-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-page_alloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
percpu-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-vmalloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
* + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree
@ 2021-08-22 21:08 akpm
0 siblings, 0 replies; 4+ messages in thread
From: akpm @ 2021-08-22 21:08 UTC (permalink / raw)
To: mm-commits, sfr, rdunlap, keescook
The patch titled
Subject: compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
has been added to the -mm tree. Its filename is
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
This patch should soon appear at
https://ozlabs.org/~akpm/mmots/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
and later at
https://ozlabs.org/~akpm/mmotm/broken-out/compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next and is updated
there every 3-4 working days
------------------------------------------------------
From: Kees Cook <keescook@chromium.org>
Subject: compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
fix warning
cc1: warning: unrecognized command line option '-Wno-alloc-size-larger-than'
Ew. Thanks for letting me know. I thought I'd verified this existed in
gcc going back to 4.9, but it looks like I did something wrong in that
test.
Link: https://lkml.kernel.org/r/202108202248.921E8C66@keescook
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/Makefile~compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix
+++ a/Makefile
@@ -1081,7 +1081,7 @@ KBUILD_CFLAGS += $(call cc-disable-warni
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
+KBUILD_CFLAGS += $(call cc-option, -Wno-alloc-size-larger-than)
endif
# disable invalid "can't wrap" optimizations for signed / pointers
_
Patches currently in -mm which might be from keescook@chromium.org are
compiler-attributes-add-__alloc_size-for-better-bounds-checking.patch
compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch
checkpatch-add-__alloc_size-to-known-attribute.patch
slab-clean-up-function-declarations.patch
slab-add-__alloc_size-attributes-for-better-bounds-checking.patch
mm-page_alloc-add-__alloc_size-attributes-for-better-bounds-checking.patch
percpu-add-__alloc_size-attributes-for-better-bounds-checking.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-12 21:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 20:56 + compiler-attributes-add-__alloc_size-for-better-bounds-checking-fix.patch added to -mm tree akpm
2021-10-12 21:05 ` Stephen Rothwell
-- strict thread matches above, loose matches on Subject: below --
2021-09-11 22:13 akpm
2021-08-22 21:08 akpm
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.