Skip to content

Commit 17c1756

Browse files
arndbakpm00
authored andcommitted
kasan: disable kasan_non_canonical_hook() for HW tags
On arm64, building with CONFIG_KASAN_HW_TAGS now causes a compile-time error: mm/kasan/report.c: In function 'kasan_non_canonical_hook': mm/kasan/report.c:637:20: error: 'KASAN_SHADOW_OFFSET' undeclared (first use in this function) 637 | if (addr < KASAN_SHADOW_OFFSET) | ^~~~~~~~~~~~~~~~~~~ mm/kasan/report.c:637:20: note: each undeclared identifier is reported only once for each function it appears in mm/kasan/report.c:640:77: error: expected expression before ';' token 640 | orig_addr = (addr - KASAN_SHADOW_OFFSET) << KASAN_SHADOW_SCALE_SHIFT; This was caused by removing the dependency on CONFIG_KASAN_INLINE that used to prevent this from happening. Use the more specific dependency on KASAN_SW_TAGS || KASAN_GENERIC to only ignore the function for hwasan mode. Link: https://lkml.kernel.org/r/[email protected] Fixes: 12ec6a9 ("kasan: print the original fault addr when access invalid shadow") Signed-off-by: Arnd Bergmann <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Haibo Li <[email protected]> Cc: Kees Cook <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: AngeloGioacchino Del Regno <[email protected]> Cc: Matthias Brugger <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent babddbf commit 17c1756

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
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
469+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
470470
void kasan_non_canonical_hook(unsigned long addr);
471-
#else /* CONFIG_KASAN */
471+
#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
472472
static inline void kasan_non_canonical_hook(unsigned long addr) { }
473-
#endif /* CONFIG_KASAN */
473+
#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
474474

475475
#endif /* LINUX_KASAN_H */

mm/kasan/report.c

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

624+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
624625
/*
625-
* With CONFIG_KASAN, accesses to bogus pointers (outside the high
626+
* With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
626627
* canonical half of the address space) cause out-of-bounds shadow memory reads
627628
* before the actual access. For addresses in the low canonical half of the
628629
* address space, as well as most non-canonical addresses, that out-of-bounds
@@ -658,3 +659,4 @@ void kasan_non_canonical_hook(unsigned long addr)
658659
pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type,
659660
orig_addr, orig_addr + KASAN_GRANULE_SIZE - 1);
660661
}
662+
#endif

0 commit comments

Comments
 (0)