Skip to contentSkip to conversation

kunit: configs: Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests

PATCH In review Richard Fitzgerald 3 participants 4 messages Apr 11, 2025 – May 30, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kunit: configs: Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests

Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests.config. This helps to detect use of uninitialized local variables.

This option found an uninitialized data bug in the cs_dsp test.

---
 tools/testing/kunit/configs/all_tests.config | 1 +
 1 file changed, 1 insertion(+)
tools/testing/kunit/configs/all_tests.config +1 -0
index cdd9782f9646..4a60bb71fe72 100644
@@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y
 CONFIG_KUNIT_ALL_TESTS=y
 
 CONFIG_FORTIFY_SOURCE=y
+CONFIG_INIT_STACK_ALL_PATTERN=y
 
 CONFIG_IIO=y
 
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Richard Fitzgerald

Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests.config. This helps to detect use of uninitialized local variables.

This option found an uninitialized data bug in the cs_dsp test.

---

Hmm... for KASAN, we had a separate config fragment for picking these sorts of things up. Then again, given we've already got stackinit tests, we probably want this anyway, and it's clearly useful to have it as a default.

Cheers,
-- David

Quoted 18 lines
 tools/testing/kunit/configs/all_tests.config | 1 +
 1 file changed, 1 insertion(+)
tools/testing/kunit/configs/all_tests.config +1 -1
index cdd9782f9646..4a60bb71fe72 100644
@@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y
 CONFIG_KUNIT_ALL_TESTS=y
 
 CONFIG_FORTIFY_SOURCE=y
+CONFIG_INIT_STACK_ALL_PATTERN=y
 
 CONFIG_IIO=y
 
--

2.39.5

#2 lore raw
In reply to Richard Fitzgerald
Quoted 15 lines · On Fri, 11 Apr 2025 10:59:04 +0100 Richard Fitzgerald wrote:

Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests.config. This helps to detect use of uninitialized local variables.

This option found an uninitialized data bug in the cs_dsp test.

---
 tools/testing/kunit/configs/all_tests.config | 1 +
 1 file changed, 1 insertion(+)
tools/testing/kunit/configs/all_tests.config +0 -0
index cdd9782f9646..4a60bb71fe72 100644

tools/testing/kunit/configs/all_tests.config CONFIG_KUNIT_EXAMPLE_TEST=y · line 13

Quoted 4 lines
tools/testing/kunit/configs/all_tests.config +1 -0
@@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y
 CONFIG_KUNIT_ALL_TESTS=y
 
 CONFIG_FORTIFY_SOURCE=y
+CONFIG_INIT_STACK_ALL_PATTERN=y

This breaks kunit for older compilers:

$ ./tools/testing/kunit/kunit.py run  --alltests --json --arch=x86_64 
 Configuring KUnit Kernel ...
 Regenerating .config ...
 Populating config with:
 $ make ARCH=x86_64 O=.kunit olddefconfig
 ERROR:root:Not all Kconfig options selected in kunitconfig were in the generated .config.
 This is probably due to unsatisfied dependencies.
 Missing: CONFIG_INIT_STACK_ALL_PATTERN=y
$ gcc --version
 gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)

IIUC GCC 11.5 is supported so pattern init can't be a hard requirement. How about we do this instead? Can you check if it'd work for you?

security/Kconfig.hardening +1 -0
index c17366ce8224..904b99f34cd0 100644
@@ -113,6 +113,7 @@ choice
                bool "pattern-init everything (strongest)"
+               default KUNIT_ALL_TESTS
                depends on CC_HAS_AUTO_VAR_INIT_PATTERN
                depends on !KMSAN
                help
                  Initializes everything on the stack (including padding)
                  with a specific debug value. This is intended to eliminate
#3 lore raw
Quoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Fri, 11 Apr 2025 10:59:04 +0100 Richard Fitzgerald wrote:

Enable CONFIG_INIT_STACK_ALL_PATTERN in all_tests.config. This helps to detect use of uninitialized local variables.

This option found an uninitialized data bug in the cs_dsp test.

---
  tools/testing/kunit/configs/all_tests.config | 1 +
  1 file changed, 1 insertion(+)
tools/testing/kunit/configs/all_tests.config +0 -0
index cdd9782f9646..4a60bb71fe72 100644
@@ -10,6 +10,7 @@ CONFIG_KUNIT_EXAMPLE_TEST=y
  CONFIG_KUNIT_ALL_TESTS=y
 
Quoted 4 lines

tools/testing/kunit/configs/all_tests.config CONFIG_KUNIT_EXAMPLE_TEST=y · line 13

Quoted 2 lines
tools/testing/kunit/configs/all_tests.config +1 -0
  CONFIG_FORTIFY_SOURCE=y
+CONFIG_INIT_STACK_ALL_PATTERN=y

This breaks kunit for older compilers:

Drop it then.
It's not essential. Just something that showed a bug in a test so I thought would be useful to test always. But if there are compatibility problems it would be better not to have it in all_tests.