mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 12:57:53 +00:00
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>
This commit is contained in:
parent
475ddf1fce
commit
1a78f8cb5d
2 changed files with 15 additions and 1 deletions
|
@ -2748,7 +2748,7 @@ config STACKINIT_KUNIT_TEST
|
||||||
|
|
||||||
config FORTIFY_KUNIT_TEST
|
config FORTIFY_KUNIT_TEST
|
||||||
tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS
|
tristate "Test fortified str*() and mem*() function internals at runtime" if !KUNIT_ALL_TESTS
|
||||||
depends on KUNIT && FORTIFY_SOURCE
|
depends on KUNIT
|
||||||
default KUNIT_ALL_TESTS
|
default KUNIT_ALL_TESTS
|
||||||
help
|
help
|
||||||
Builds unit tests for checking internals of FORTIFY_SOURCE as used
|
Builds unit tests for checking internals of FORTIFY_SOURCE as used
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/vmalloc.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 array_of_10[] = "this is 10";
|
||||||
static const char *ptr_of_11 = "this is 11!";
|
static const char *ptr_of_11 = "this is 11!";
|
||||||
static char array_unknown[] = "compiler thinks I might change";
|
static char array_unknown[] = "compiler thinks I might change";
|
||||||
|
@ -308,6 +313,14 @@ DEFINE_ALLOC_SIZE_TEST_PAIR(kvmalloc)
|
||||||
} while (0)
|
} while (0)
|
||||||
DEFINE_ALLOC_SIZE_TEST_PAIR(devm_kmalloc)
|
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[] = {
|
static struct kunit_case fortify_test_cases[] = {
|
||||||
KUNIT_CASE(known_sizes_test),
|
KUNIT_CASE(known_sizes_test),
|
||||||
KUNIT_CASE(control_flow_split_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 = {
|
static struct kunit_suite fortify_test_suite = {
|
||||||
.name = "fortify",
|
.name = "fortify",
|
||||||
|
.init = fortify_test_init,
|
||||||
.test_cases = fortify_test_cases,
|
.test_cases = fortify_test_cases,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue