Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit/fortify: Add back "volatile" for sizeof() constants

It seems the Clang can see through OPTIMIZER_HIDE_VAR when the constant
is coming from sizeof. Adding "volatile" back to these variables solves
this false positive without reintroducing the issues that originally led
to switching to OPTIMIZER_HIDE_VAR in the first place[1].

Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://github.com/ClangBuiltLinux/linux/issues/2075 [1]
Cc: Jannik Glückert <jannik.glueckert@gmail.com>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Fixes: 6ee149f61bcc ("kunit/fortify: Replace "volatile" with OPTIMIZER_HIDE_VAR()")
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20250628234034.work.800-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>

Kees Cook 10299c07 5e54510a

+2 -2
+2 -2
lib/tests/fortify_kunit.c
··· 1003 1003 { 1004 1004 char one[] = "My mind is going ..."; 1005 1005 char two[] = "My mind is going ... I can feel it."; 1006 - size_t one_len = sizeof(one) - 1; 1007 - size_t two_len = sizeof(two) - 1; 1006 + volatile size_t one_len = sizeof(one) - 1; 1007 + volatile size_t two_len = sizeof(two) - 1; 1008 1008 1009 1009 OPTIMIZER_HIDE_VAR(one_len); 1010 1010 OPTIMIZER_HIDE_VAR(two_len);