Skip to content

Commit 09833d9

Browse files
ramosian-gliderakpm00
authored andcommitted
mm/kfence: disable KFENCE upon KASAN HW tags enablement
KFENCE does not currently support KASAN hardware tags. As a result, the two features are incompatible when enabled simultaneously. Given that MTE provides deterministic protection and KFENCE is a sampling-based debugging tool, prioritize the stronger hardware protections. Disable KFENCE initialization and free the pre-allocated pool if KASAN hardware tags are detected to ensure the system maintains the security guarantees provided by MTE. Link: https://lkml.kernel.org/r/20260213095410.1862978-1-glider@google.com Fixes: 0ce20dd ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Alexander Potapenko <glider@google.com> Suggested-by: Marco Elver <elver@google.com> Reviewed-by: Marco Elver <elver@google.com> Cc: Andrey Konovalov <andreyknvl@gmail.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Ernesto Martinez Garcia <ernesto.martinezgarcia@tugraz.at> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Kees Cook <kees@kernel.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6de23f8 commit 09833d9

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

mm/kfence/core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/hash.h>
1414
#include <linux/irq_work.h>
1515
#include <linux/jhash.h>
16+
#include <linux/kasan-enabled.h>
1617
#include <linux/kcsan-checks.h>
1718
#include <linux/kfence.h>
1819
#include <linux/kmemleak.h>
@@ -916,6 +917,20 @@ void __init kfence_alloc_pool_and_metadata(void)
916917
if (!kfence_sample_interval)
917918
return;
918919

920+
/*
921+
* If KASAN hardware tags are enabled, disable KFENCE, because it
922+
* does not support MTE yet.
923+
*/
924+
if (kasan_hw_tags_enabled()) {
925+
pr_info("disabled as KASAN HW tags are enabled\n");
926+
if (__kfence_pool) {
927+
memblock_free(__kfence_pool, KFENCE_POOL_SIZE);
928+
__kfence_pool = NULL;
929+
}
930+
kfence_sample_interval = 0;
931+
return;
932+
}
933+
919934
/*
920935
* If the pool has already been initialized by arch, there is no need to
921936
* re-allocate the memory pool.

0 commit comments

Comments
 (0)