mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user