fortify: Update compile-time tests for Clang 14
authorKees Cook <keescook@chromium.org>
Sun, 30 Jan 2022 17:59:29 +0000 (09:59 -0800)
committerKees Cook <keescook@chromium.org>
Mon, 14 Feb 2022 00:50:06 +0000 (16:50 -0800)
Clang 14 introduces support for compiletime_assert(). Update the
compile-time warning regex to catch Clang's variant of the warning text
in preparation for Clang supporting CONFIG_FORTIFY_SOURCE.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: linux-hardening@vger.kernel.org
Cc: llvm@lists.linux.dev
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/lkml/YfbtQKtpyAM1hHiC@dev-arch.archlinux-ax161
Signed-off-by: Kees Cook <keescook@chromium.org>
scripts/test_fortify.sh

index a4da365508f02b6d502d7f8fdb2ea5fd1b6ea396..c2688ab8281d025ad80168b783d293950c4e726c 100644 (file)
@@ -46,8 +46,12 @@ if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
                status="warning: unsafe ${FUNC}() usage lacked '$WANT' symbol in $IN"
        fi
 else
-       # If the build failed, check for the warning in the stderr (gcc).
-       if ! grep -q -m1 "error: call to .\b${WANT}\b." "$TMP" ; then
+       # If the build failed, check for the warning in the stderr.
+       # GCC:
+       # ./include/linux/fortify-string.h:316:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
+       # Clang 14:
+       # ./include/linux/fortify-string.h:316:4: error: call to __write_overflow_field declared with 'warning' attribute: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror,-Wattribute-warning]
+       if ! grep -Eq -m1 "error: call to .?\b${WANT}\b.?" "$TMP" ; then
                status="warning: unsafe ${FUNC}() usage lacked '$WANT' warning in $IN"
        fi
 fi