]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hardening: simplify CONFIG_CC_HAS_COUNTED_BY
authorJan Hendrik Farr <kernel@jfarr.cc>
Wed, 30 Apr 2025 18:42:31 +0000 (20:42 +0200)
committerKees Cook <kees@kernel.org>
Thu, 8 May 2025 16:42:05 +0000 (09:42 -0700)
Simplifies CONFIG_CC_HAS_COUNTED_BY by removing the build test and
relying solely on gcc/clang version numbering (GCC_VERSION >= 150100 and
CLANG_VERSION >= 190103).

The build test was used to allow unreleased gcc 15.0 builds to use the
__counted_by attribute. Now that gcc 15.1.0 has been released, this is
not needed anymore. Note: This will disable __counted_by on unreleased
gcc 15.0 builds.

clang version support for __counted_by remains unchanged.

Link: https://lore.kernel.org/all/Zw8iawAF5W2uzGuh@archlinux/T/#m204c09f63c076586a02d194b87dffc7e81b8de7b
Link: https://lore.kernel.org/r/20241029140036.577804-2-kernel@jfarr.cc
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Jan Hendrik Farr <kernel@jfarr.cc>
Link: https://lore.kernel.org/r/20250430184231.671365-2-kernel@jfarr.cc
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <kees@kernel.org>
init/Kconfig

index 63f5974b9fa6ea3f5c92203cedd1f2f82aa468a1..017fde21d0ba0a9ed4ad8e0f8277dc9b4e91689a 100644 (file)
@@ -121,13 +121,14 @@ config CC_HAS_NO_PROFILE_FN_ATTR
        def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror)
 
 config CC_HAS_COUNTED_BY
-       # TODO: when gcc 15 is released remove the build test and add
-       # a gcc version check
-       def_bool $(success,echo 'struct flex { int count; int array[] __attribute__((__counted_by__(count))); };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)
+       bool
        # clang needs to be at least 19.1.3 to avoid __bdos miscalculations
        # https://github.com/llvm/llvm-project/pull/110497
        # https://github.com/llvm/llvm-project/pull/112636
-       depends on !(CC_IS_CLANG && CLANG_VERSION < 190103)
+       default y if CC_IS_CLANG && CLANG_VERSION >= 190103
+       # supported since gcc 15.1.0
+       # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
+       default y if CC_IS_GCC && GCC_VERSION >= 150100
 
 config CC_HAS_MULTIDIMENSIONAL_NONSTRING
        def_bool $(success,echo 'char tag[][4] __attribute__((__nonstring__)) = { };' | $(CC) $(CLANG_FLAGS) -x c - -c -o /dev/null -Werror)