Skip to content

Commit

Permalink
mm, kfence: bug on data corruption after error report
Browse files Browse the repository at this point in the history
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 <levente@leventepolyak.net>
  • Loading branch information
anthraxx committed Mar 6, 2024
1 parent 7cb2745 commit afa65d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Kconfig.kfence
Expand Up @@ -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
5 changes: 5 additions & 0 deletions mm/kfence/report.c
Expand Up @@ -8,6 +8,7 @@
#include <linux/stdarg.h>

#include <linux/kernel.h>
#include <linux/bug.h>
#include <linux/lockdep.h>
#include <linux/math.h>
#include <linux/printk.h>
Expand Down Expand Up @@ -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! */
Expand Down

0 comments on commit afa65d3

Please sign in to comment.