summaryrefslogtreecommitdiff
path: root/lib/string_helpers.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2023-04-07 12:27:16 -0700
committerKees Cook <keescook@chromium.org>2024-02-29 13:38:02 -0800
commit3d965b33e40d973b450cb0212913f039476c16f4 (patch)
tree213bf660d55d66a2a4a273f8394156f30f83410c /lib/string_helpers.c
parentfa4a3f86d4982b603865ccb97dde82f0ae1e3302 (diff)
fortify: Improve buffer overflow reporting
Improve the reporting of buffer overflows under CONFIG_FORTIFY_SOURCE to help accelerate debugging efforts. The calculations are all just sitting in registers anyway, so pass them along to the function to be reported. For example, before: detected buffer overflow in memcpy and after: memcpy: detected buffer overflow: 4096 byte read of buffer size 1 Link: https://lore.kernel.org/r/20230407192717.636137-10-keescook@chromium.org Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'lib/string_helpers.c')
-rw-r--r--lib/string_helpers.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 5e53d42e32bb..6bbafd6a10d9 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -1016,20 +1016,21 @@ static const char * const fortify_func_name[] = {
#undef MAKE_FORTIFY_FUNC_NAME
};
-void __fortify_report(const u8 reason)
+void __fortify_report(const u8 reason, const size_t avail, const size_t size)
{
const u8 func = FORTIFY_REASON_FUNC(reason);
const bool write = FORTIFY_REASON_DIR(reason);
const char *name;
name = fortify_func_name[umin(func, FORTIFY_FUNC_UNKNOWN)];
- WARN(1, "%s: detected buffer %s overflow\n", name, str_read_write(!write));
+ WARN(1, "%s: detected buffer overflow: %zu byte %s of buffer size %zu\n",
+ name, size, str_read_write(!write), avail);
}
EXPORT_SYMBOL(__fortify_report);
-void __fortify_panic(const u8 reason)
+void __fortify_panic(const u8 reason, const size_t avail, const size_t size)
{
- __fortify_report(reason);
+ __fortify_report(reason, avail, size);
BUG();
}
EXPORT_SYMBOL(__fortify_panic);