Skip to content

Commit 1a78f8c

Browse files
committed
fortify: Allow KUnit test to build without FORTIFY
In order for CI systems to notice all the skipped tests related to CONFIG_FORTIFY_SOURCE, allow the FORTIFY_SOURCE KUnit tests to build with or without CONFIG_FORTIFY_SOURCE. Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 475ddf1 commit 1a78f8c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2748,7 +2748,7 @@ config STACKINIT_KUNIT_TEST
27482748

27492749
config FORTIFY_KUNIT_TEST
27502750
tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS
2751-
depends on KUNIT && FORTIFY_SOURCE
2751+
depends on KUNIT
27522752
default KUNIT_ALL_TESTS
27532753
help
27542754
Builds unit tests for checking internals of FORTIFY_SOURCE as used

lib/fortify_kunit.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include <linux/string.h>
2323
#include <linux/vmalloc.h>
2424

25+
/* Handle being built without CONFIG_FORTIFY_SOURCE */
26+
#ifndef __compiletime_strlen
27+
# define __compiletime_strlen __builtin_strlen
28+
#endif
29+
2530
static const char array_of_10[] = "this is 10";
2631
static const char *ptr_of_11 = "this is 11!";
2732
static char array_unknown[] = "compiler thinks I might change";
@@ -308,6 +313,14 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc)
308313
} while (0)
309314
DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc)
310315

316+
static int fortify_test_init(struct kunit *test)
317+
{
318+
if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE))
319+
kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y");
320+
321+
return 0;
322+
}
323+
311324
static struct kunit_case fortify_test_cases[] = {
312325
KUNIT_CASE(known_sizes_test),
313326
KUNIT_CASE(control_flow_split_test),
@@ -324,6 +337,7 @@ static struct kunit_case fortify_test_cases[] = {
324337

325338
static struct kunit_suite fortify_test_suite = {
326339
.name = "fortify",
340+
.init = fortify_test_init,
327341
.test_cases = fortify_test_cases,
328342
};
329343

0 commit comments

Comments
 (0)