From a501da58b1767b07cb1e8051a58477d6cc3db18b Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Tue, 25 May 2021 21:04:47 +0200 Subject: [PATCH] mm, kfence: bug on data corruption after error report Trigger BUG when kfence encounters data corruption of kfence managed objects. This allows a finer-grained control instead of globally enabling panic_on_warn. Signed-off-by: Levente Polyak --- lib/Kconfig.kfence | 9 +++++++++ mm/kfence/report.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence index 912f252a41fc6..463dd86ee8c79 100644 --- a/lib/Kconfig.kfence +++ b/lib/Kconfig.kfence @@ -84,4 +84,13 @@ config KFENCE_KUNIT_TEST during boot; say M if you want the test to build as a module; say N if you are unsure. +config KFENCE_BUG_ON_DATA_CORRUPTION + bool "Trigger a BUG when data corruption is detected" + default y + help + Select this option if the kernel should BUG when kfence encounters + data corruption of kfence managed objects after error report. + + If unsure, say Y. + endif # KFENCE diff --git a/mm/kfence/report.c b/mm/kfence/report.c index cbd9456359b96..0e8bd51c55231 100644 --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -267,6 +268,10 @@ void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *r lockdep_on(); +#ifdef CONFIG_KFENCE_BUG_ON_DATA_CORRUPTION + BUG(); +#endif + check_panic_on_warn("KFENCE"); /* We encountered a memory safety error, taint the kernel! */