aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2021-05-19 12:16:59 -0700
committerKees Cook <keescook@chromium.org>2021-05-19 15:06:13 -0700
commit0bee95cae61e3cfc979fb3baab53189b65f5f777 (patch)
tree75cc5ea4455e0e75bdf9e26fe24c9fe2c0d441f8
parent03404e22f4e88583981e087b1c28cd877f3f627a (diff)
downloadlinux-0bee95cae61e3cfc979fb3baab53189b65f5f777.tar.gz
[DEBUG] fortify: Warn about all cases where memcpy() cannot check bounds
This is very noisy. :) Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--include/linux/fortify-string.h11
-rw-r--r--kernel/panic.c8
2 files changed, 18 insertions, 1 deletions
diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
index ed9b8b7c1cb00..74fd5ae241111 100644
--- a/include/linux/fortify-string.h
+++ b/include/linux/fortify-string.h
@@ -204,7 +204,7 @@ __FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
* y = deterministic compile-time bounds checking
* n = cannot do deterministic compile-time bounds checking
* n/a = no run-time bounds checking needed since compile-time deterministic
- * W = compile-time warn about lack of any bounds checking (TODO)
+ * W = compile-time warn about lack of any bounds checking
* B = perform run-time bounds checking
*
*/
@@ -251,6 +251,15 @@ __FORTIFY_INLINE void __fortify_memcpy_chk(void *p, const void *q,
if (q_size != q_size_field)
__runtime_read_check();
+ /*
+ * Add build warnings to identify cases where it is
+ * not possible to perform run-time bounds checks.
+ */
+ if (p_size == (size_t)(-1))
+ __runtime_write_check_missing();
+ if (q_size == (size_t)(-1))
+ __runtime_read_check_missing();
+
/* Warn when writing beyond destination field size. */
WARN_ON(p_size != p_size_field && p_size_field < size);
/* Warn when reading beyond source field size. */
diff --git a/kernel/panic.c b/kernel/panic.c
index 26257197162ed..bb29cda63e602 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -743,3 +743,11 @@ EXPORT_SYMBOL(__runtime_write_check);
void __runtime_read_check(void)
{ }
EXPORT_SYMBOL(__runtime_read_check);
+
+void __runtime_write_check_missing(void)
+{ }
+EXPORT_SYMBOL(__runtime_write_check_missing);
+
+void __runtime_read_check_missing(void)
+{ }
+EXPORT_SYMBOL(__runtime_read_check_missing);