Skip to content

Commit 0bb1fbf

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: mm: kfence: only handle translation faults
Alexander noted that KFENCE only expects to handle faults from invalid page table entries (i.e. translation faults), but arm64's fault handling logic will call kfence_handle_page_fault() for other types of faults, including alignment faults caused by unaligned atomics. This has the unfortunate property of causing those other faults to be reported as "KFENCE: use-after-free", which is misleading and hinders debugging. Fix this by only forwarding unhandled translation faults to the KFENCE code, similar to what x86 does already. Alexander has verified that this passes all the tests in the KFENCE test suite and avoids bogus reports on misaligned atomics. Link: https://lore.kernel.org/all/[email protected]/ Fixes: 840b239 ("arm64, kfence: enable KFENCE for ARM64") Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Tested-by: Alexander Potapenko <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marco Elver <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent a4ee286 commit 0bb1fbf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arch/arm64/mm/fault.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ static bool is_el1_mte_sync_tag_check_fault(unsigned long esr)
354354
return false;
355355
}
356356

357+
static bool is_translation_fault(unsigned long esr)
358+
{
359+
return (esr & ESR_ELx_FSC_TYPE) == ESR_ELx_FSC_FAULT;
360+
}
361+
357362
static void __do_kernel_fault(unsigned long addr, unsigned long esr,
358363
struct pt_regs *regs)
359364
{
@@ -386,7 +391,8 @@ static void __do_kernel_fault(unsigned long addr, unsigned long esr,
386391
} else if (addr < PAGE_SIZE) {
387392
msg = "NULL pointer dereference";
388393
} else {
389-
if (kfence_handle_page_fault(addr, esr & ESR_ELx_WNR, regs))
394+
if (is_translation_fault(esr) &&
395+
kfence_handle_page_fault(addr, esr & ESR_ELx_WNR, regs))
390396
return;
391397

392398
msg = "paging request";

0 commit comments

Comments
 (0)