Skip to content

Commit 632c219

Browse files
Haibo Ligregkh
authored andcommitted
kasan: print the original fault addr when access invalid shadow
commit babddbf upstream. 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/20231009073748.159228-1-haibo.li@mediatek.com Fixes: 2f004ee("x86/kasan: Print original address on #GP") Signed-off-by: Haibo Li <haibo.li@mediatek.com> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Haibo Li <haibo.li@mediatek.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent be9e6f5 commit 632c219

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
@@ -234,10 +234,10 @@ static inline void kasan_release_vmalloc(unsigned long start,
234234
unsigned long free_region_end) {}
235235
#endif
236236

237-
#ifdef CONFIG_KASAN_INLINE
237+
#ifdef CONFIG_KASAN
238238
void kasan_non_canonical_hook(unsigned long addr);
239-
#else /* CONFIG_KASAN_INLINE */
239+
#else /* CONFIG_KASAN */
240240
static inline void kasan_non_canonical_hook(unsigned long addr) { }
241-
#endif /* CONFIG_KASAN_INLINE */
241+
#endif /* CONFIG_KASAN */
242242

243243
#endif /* LINUX_KASAN_H */

mm/kasan/report.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write,
560560
return ret;
561561
}
562562

563-
#ifdef CONFIG_KASAN_INLINE
564563
/*
565-
* With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
564+
* With CONFIG_KASAN, accesses to bogus pointers (outside the high
566565
* canonical half of the address space) cause out-of-bounds shadow memory reads
567566
* before the actual access. For addresses in the low canonical half of the
568567
* address space, as well as most non-canonical addresses, that out-of-bounds
@@ -598,4 +597,3 @@ void kasan_non_canonical_hook(unsigned long addr)
598597
pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type,
599598
orig_addr, orig_addr + KASAN_SHADOW_MASK);
600599
}
601-
#endif

0 commit comments

Comments
 (0)