mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fortify: Disable colored diagnostics in test_fortify.sh
@ 2026-09-24 20:34 Igor Velkov via B4 Relay
  2026-09-25 18:58 ` Nicolas Schier
  2026-09-25 20:52 ` Nathan Chancellor
  0 siblings, 2 replies; 3+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-09-24 20:34 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-hardening, linux-kernel, Nicolas Schier, Nathan Chancellor,
	Igor Velkov

From: Igor Velkov <iav@iav.lv>

When the build forces colored diagnostics, e.g. with
KCFLAGS=-fdiagnostics-color=always, the compiler wraps the expected
error in ANSI escape sequences and the grep does not match it. Every
test then reports "lacked '__write_overflow' warning" although FORTIFY
caught the overflow, and a real FORTIFY regression looks the same.

  warning: unsafe strcpy() usage lacked '__write_overflow' warning in lib/test_fortify/write_overflow-strcpy.c

Pass -fdiagnostics-color=never after the caller's flags so that the
test compile always emits plain text.

Fixes: be58f7103700 ("fortify: Add compile-time FORTIFY_SOURCE tests")
Assisted-by: LLM
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Found in Armbian kernel builds, which pass -fdiagnostics-color=always
in KCFLAGS: all 18 tests reported "lacked".

Tested on arm64, 7.2.y, KCFLAGS=-fdiagnostics-color=always,
building lib/test_fortify/ (tests ok out of 18):

                 before   after   after, -D__NO_FORTIFY
  GCC 14.2          0       18        0
  clang 19.1.7      0       18        0

An LLM assistant found the cause, wrote the fix and the changelog,
and ran the tests; I reviewed all of it.
---
 lib/test_fortify/test_fortify.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/test_fortify/test_fortify.sh b/lib/test_fortify/test_fortify.sh
index ad6dd44fa31c..c07eb3302c9d 100644
--- a/lib/test_fortify/test_fortify.sh
+++ b/lib/test_fortify/test_fortify.sh
@@ -37,7 +37,8 @@ export LANG=C
 
 status=
 # Attempt to build a source that is expected to fail with a specific warning.
-if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
+# Disable colors so that the grep below can match the warning.
+if "$@" -Werror -fdiagnostics-color=never -c "$IN" -o "$OUT".o 2> "$TMP" ; then
 	# If the build succeeds, either the test has failed or the
 	# warning may only happen at link time (Clang). In that case,
 	# make sure the expected symbol is unresolved in the symbol list.

---
base-commit: 760f96b7f54beb8dc6f85d97ac7854fddba86835
change-id: 20260924-fortify-test-color-f34a31b56bcc

Best regards,
-- 
Igor Velkov <iav@iav.lv>



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

* Re: [PATCH] fortify: Disable colored diagnostics in test_fortify.sh
  2026-09-24 20:34 [PATCH] fortify: Disable colored diagnostics in test_fortify.sh Igor Velkov via B4 Relay
@ 2026-09-25 18:58 ` Nicolas Schier
  2026-09-25 20:52 ` Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Schier @ 2026-09-25 18:58 UTC (permalink / raw)
  To: iav; +Cc: Kees Cook, linux-hardening, linux-kernel, Nathan Chancellor

On Thu, Sep 24, 2026 at 11:34:29PM +0300, Igor Velkov via B4 Relay wrote:
> From: Igor Velkov <iav@iav.lv>
> 
> When the build forces colored diagnostics, e.g. with
> KCFLAGS=-fdiagnostics-color=always, the compiler wraps the expected
> error in ANSI escape sequences and the grep does not match it. Every
> test then reports "lacked '__write_overflow' warning" although FORTIFY
> caught the overflow, and a real FORTIFY regression looks the same.
> 
>   warning: unsafe strcpy() usage lacked '__write_overflow' warning in lib/test_fortify/write_overflow-strcpy.c
> 
> Pass -fdiagnostics-color=never after the caller's flags so that the
> test compile always emits plain text.
> 
> Fixes: be58f7103700 ("fortify: Add compile-time FORTIFY_SOURCE tests")
> Assisted-by: LLM
> Signed-off-by: Igor Velkov <iav@iav.lv>
> ---
> Found in Armbian kernel builds, which pass -fdiagnostics-color=always
> in KCFLAGS: all 18 tests reported "lacked".
> 
> Tested on arm64, 7.2.y, KCFLAGS=-fdiagnostics-color=always,
> building lib/test_fortify/ (tests ok out of 18):
> 
>                  before   after   after, -D__NO_FORTIFY
>   GCC 14.2          0       18        0
>   clang 19.1.7      0       18        0
> 
> An LLM assistant found the cause, wrote the fix and the changelog,
> and ran the tests; I reviewed all of it.
> ---
>  lib/test_fortify/test_fortify.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/test_fortify/test_fortify.sh b/lib/test_fortify/test_fortify.sh
> index ad6dd44fa31c..c07eb3302c9d 100644
> --- a/lib/test_fortify/test_fortify.sh
> +++ b/lib/test_fortify/test_fortify.sh
> @@ -37,7 +37,8 @@ export LANG=C
>  
>  status=
>  # Attempt to build a source that is expected to fail with a specific warning.
> -if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
> +# Disable colors so that the grep below can match the warning.
> +if "$@" -Werror -fdiagnostics-color=never -c "$IN" -o "$OUT".o 2> "$TMP" ; then
>  	# If the build succeeds, either the test has failed or the
>  	# warning may only happen at link time (Clang). In that case,
>  	# make sure the expected symbol is unresolved in the symbol list.
> 
> ---
> base-commit: 760f96b7f54beb8dc6f85d97ac7854fddba86835
> change-id: 20260924-fortify-test-color-f34a31b56bcc
> 
> Best regards,
> -- 
> Igor Velkov <iav@iav.lv>
> 
> 

Tested-by: Nicolas Schier <nsc@kernel.org>
Reviewed-by: Nicolas Schier <nsc@kernel.org>

-- 
Nicolas

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

* Re: [PATCH] fortify: Disable colored diagnostics in test_fortify.sh
  2026-09-24 20:34 [PATCH] fortify: Disable colored diagnostics in test_fortify.sh Igor Velkov via B4 Relay
  2026-09-25 18:58 ` Nicolas Schier
@ 2026-09-25 20:52 ` Nathan Chancellor
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2026-09-25 20:52 UTC (permalink / raw)
  To: iav; +Cc: Kees Cook, linux-hardening, linux-kernel, Nicolas Schier

On Thu, Sep 24, 2026 at 11:34:29PM +0300, Igor Velkov via B4 Relay wrote:
> From: Igor Velkov <iav@iav.lv>
> 
> When the build forces colored diagnostics, e.g. with
> KCFLAGS=-fdiagnostics-color=always, the compiler wraps the expected
> error in ANSI escape sequences and the grep does not match it. Every
> test then reports "lacked '__write_overflow' warning" although FORTIFY
> caught the overflow, and a real FORTIFY regression looks the same.
> 
>   warning: unsafe strcpy() usage lacked '__write_overflow' warning in lib/test_fortify/write_overflow-strcpy.c
> 
> Pass -fdiagnostics-color=never after the caller's flags so that the
> test compile always emits plain text.
> 
> Fixes: be58f7103700 ("fortify: Add compile-time FORTIFY_SOURCE tests")
> Assisted-by: LLM
> Signed-off-by: Igor Velkov <iav@iav.lv>
> ---
> Found in Armbian kernel builds, which pass -fdiagnostics-color=always
> in KCFLAGS: all 18 tests reported "lacked".

Hmmm, interesting default...

That said, seems reasonable to me. Presumably it is more complicated to
handle this in the regex.

Reviewed-by: Nathan Chancellor <nathan@kernel.org>

> Tested on arm64, 7.2.y, KCFLAGS=-fdiagnostics-color=always,
> building lib/test_fortify/ (tests ok out of 18):
> 
>                  before   after   after, -D__NO_FORTIFY
>   GCC 14.2          0       18        0
>   clang 19.1.7      0       18        0
> 
> An LLM assistant found the cause, wrote the fix and the changelog,
> and ran the tests; I reviewed all of it.
> ---
>  lib/test_fortify/test_fortify.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/test_fortify/test_fortify.sh b/lib/test_fortify/test_fortify.sh
> index ad6dd44fa31c..c07eb3302c9d 100644
> --- a/lib/test_fortify/test_fortify.sh
> +++ b/lib/test_fortify/test_fortify.sh
> @@ -37,7 +37,8 @@ export LANG=C
>  
>  status=
>  # Attempt to build a source that is expected to fail with a specific warning.
> -if "$@" -Werror -c "$IN" -o "$OUT".o 2> "$TMP" ; then
> +# Disable colors so that the grep below can match the warning.
> +if "$@" -Werror -fdiagnostics-color=never -c "$IN" -o "$OUT".o 2> "$TMP" ; then
>  	# If the build succeeds, either the test has failed or the
>  	# warning may only happen at link time (Clang). In that case,
>  	# make sure the expected symbol is unresolved in the symbol list.
> 
> ---
> base-commit: 760f96b7f54beb8dc6f85d97ac7854fddba86835
> change-id: 20260924-fortify-test-color-f34a31b56bcc
> 
> Best regards,
> -- 
> Igor Velkov <iav@iav.lv>
> 
> 

-- 
Cheers,
Nathan

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

end of thread, other threads:[~2026-09-25 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-24 20:34 [PATCH] fortify: Disable colored diagnostics in test_fortify.sh Igor Velkov via B4 Relay
2026-09-25 18:58 ` Nicolas Schier
2026-09-25 20:52 ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®