diff options
author | Kees Cook <keescook@chromium.org> | 2023-04-07 12:27:14 -0700 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2024-02-29 13:38:02 -0800 |
commit | 4ce615e798a752d4431fcc52960478906dec2f0e (patch) | |
tree | d76038c7680c29c84a99c9c02dd327e0788e685a /lib/string_helpers.c | |
parent | 1a78f8cb5daac77405e449f5305ad72c01818a46 (diff) |
fortify: Provide KUnit counters for failure testing
The standard C string APIs were not designed to have a failure mode;
they were expected to always succeed without memory safety issues.
Normally, CONFIG_FORTIFY_SOURCE will use fortify_panic() to stop
processing, as truncating a read or write may provide an even worse
system state. However, this creates a problem for testing under things
like KUnit, which needs a way to survive failures.
When building with CONFIG_KUNIT, provide a failure path for all users
of fortify_panic, and track whether the failure was a read overflow or
a write overflow, for KUnit tests to examine. Inspired by similar logic
in the slab tests.
Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r-- | lib/string_helpers.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 9291dc74ae01..5e53d42e32bb 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -18,6 +18,8 @@ #include <linux/slab.h> #include <linux/string.h> #include <linux/string_helpers.h> +#include <kunit/test.h> +#include <kunit/test-bug.h> /** * string_get_size - get the size in the specified units |