Kernel: Expose sysctl 'ubsan_is_deadly' to panic the Kernel on UB

This makes it easier to find UB, for example when fuzzing the Kernel.

This can be enabled by default, thanks to @boricj's work in
32e1354b9b.
This commit is contained in:
Ben Wiederhake 2021-03-04 22:07:23 +01:00 committed by Andreas Kling
commit 00131d244e
Notes: sideshowbarker 2024-07-18 21:38:47 +09:00
3 changed files with 14 additions and 1 deletions

View file

@ -26,22 +26,26 @@
#include <AK/Format.h>
#include <Kernel/KSyms.h>
#include <Kernel/Panic.h>
#include <Kernel/UBSanitizer.h>
using namespace Kernel;
using namespace Kernel::UBSanitizer;
bool Kernel::UBSanitizer::g_ubsan_is_deadly { true };
extern "C" {
static void print_location(const SourceLocation& location)
{
if (!location.filename()) {
dbgln("KUBSAN: in unknown file");
} else {
dbgln("KUBSAN: at {}, line {}, column: {}", location.filename(), location.line(), location.column());
}
dump_backtrace();
if (g_ubsan_is_deadly)
PANIC("UB is configured to be deadly.");
}
void __ubsan_handle_load_invalid_value(const InvalidValueData&, ValueHandle);