summaryrefslogtreecommitdiffstats
path: root/lib/fortify_kunit.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2023-04-07 12:27:08 -0700
committerKees Cook <keescook@chromium.org>2024-02-29 13:38:02 -0800
commit1a78f8cb5daac77405e449f5305ad72c01818a46 (patch)
tree853014d815279c81021d79a9acd8de78fe01d350 /lib/fortify_kunit.c
parent475ddf1fce1ec4826c8dda40ec59f7f83a7aadb8 (diff)
downloadlinux-stable-1a78f8cb5daac77405e449f5305ad72c01818a46.tar.gz
linux-stable-1a78f8cb5daac77405e449f5305ad72c01818a46.tar.bz2
linux-stable-1a78f8cb5daac77405e449f5305ad72c01818a46.zip
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>
Diffstat (limited to 'lib/fortify_kunit.c')
-rw-r--r--lib/fortify_kunit.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c
index 2e4fedc81621..7a88b5dd3d27 100644
--- a/lib/fortify_kunit.c
+++ b/lib/fortify_kunit.c
@@ -22,6 +22,11 @@
#include <linux/string.h>
#include <linux/vmalloc.h>
+/* Handle being built without CONFIG_FORTIFY_SOURCE */
+#ifndef __compiletime_strlen
+# define __compiletime_strlen __builtin_strlen
+#endif
+
static const char array_of_10[] = "this is 10";
static const char *ptr_of_11 = "this is 11!";
static char array_unknown[] = "compiler thinks I might change";
@@ -308,6 +313,14 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc)
} while (0)
DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc)
+static int fortify_test_init(struct kunit *test)
+{
+ if (!IS_ENABLED(CONFIG_FORTIFY_SOURCE))
+ kunit_skip(test, "Not built with CONFIG_FORTIFY_SOURCE=y");
+
+ return 0;
+}
+
static struct kunit_case fortify_test_cases[] = {
KUNIT_CASE(known_sizes_test),
KUNIT_CASE(control_flow_split_test),
@@ -324,6 +337,7 @@ static struct kunit_case fortify_test_cases[] = {
static struct kunit_suite fortify_test_suite = {
.name = "fortify",
+ .init = fortify_test_init,
.test_cases = fortify_test_cases,
};