Skip to content

Commit babddbf

Browse files
Haibo Liakpm00
Haibo Li
authored andcommitted
kasan: print the original fault addr when access invalid shadow
when the checked address is illegal,the corresponding shadow address from kasan_mem_to_shadow may have no mapping in mmu table. Access such shadow address causes kernel oops. Here is a sample about oops on arm64(VA 39bit) with KASAN_SW_TAGS and KASAN_OUTLINE on: [ffffffb80aaaaaaa] pgd=000000005d3ce003, p4d=000000005d3ce003, pud=000000005d3ce003, pmd=0000000000000000 Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP Modules linked in: CPU: 3 PID: 100 Comm: sh Not tainted 6.6.0-rc1-dirty #43 Hardware name: linux,dummy-virt (DT) pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : __hwasan_load8_noabort+0x5c/0x90 lr : do_ib_ob+0xf4/0x110 ffffffb80aaaaaaa is the shadow address for efffff80aaaaaaaa. The problem is reading invalid shadow in kasan_check_range. The generic kasan also has similar oops. It only reports the shadow address which causes oops but not the original address. Commit 2f004ee("x86/kasan: Print original address on #GP") introduce to kasan_non_canonical_hook but limit it to KASAN_INLINE. This patch extends it to KASAN_OUTLINE mode. Link: https://lkml.kernel.org/r/[email protected] Fixes: 2f004ee("x86/kasan: Print original address on #GP") Signed-off-by: Haibo Li <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: AngeloGioacchino Del Regno <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Haibo Li <[email protected]> Cc: Matthias Brugger <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Kees Cook <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2820b0f commit babddbf

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

include/linux/kasan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ static inline void kasan_free_module_shadow(const struct vm_struct *vm) {}
466466

467467
#endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */
468468

469-
#ifdef CONFIG_KASAN_INLINE
469+
#ifdef CONFIG_KASAN
470470
void kasan_non_canonical_hook(unsigned long addr);
471-
#else /* CONFIG_KASAN_INLINE */
471+
#else /* CONFIG_KASAN */
472472
static inline void kasan_non_canonical_hook(unsigned long addr) { }
473-
#endif /* CONFIG_KASAN_INLINE */
473+
#endif /* CONFIG_KASAN */
474474

475475
#endif /* LINUX_KASAN_H */

mm/kasan/report.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,8 @@ void kasan_report_async(void)
621621
}
622622
#endif /* CONFIG_KASAN_HW_TAGS */
623623

624-
#ifdef CONFIG_KASAN_INLINE
625624
/*
626-
* With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
625+
* With CONFIG_KASAN, accesses to bogus pointers (outside the high
627626
* canonical half of the address space) cause out-of-bounds shadow memory reads
628627
* before the actual access. For addresses in the low canonical half of the
629628
* address space, as well as most non-canonical addresses, that out-of-bounds
@@ -659,4 +658,3 @@ void kasan_non_canonical_hook(unsigned long addr)
659658
pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type,
660659
orig_addr, orig_addr + KASAN_GRANULE_SIZE - 1);
661660
}
662-
#endif

0 commit comments

Comments
 (0)