Skip to content

Commit b1add41

Browse files
fvincenzotorvalds
authored andcommitted
kasan: fix hw tags enablement when KUNIT tests are disabled
Kasan enables hw tags via kasan_enable_tagging() which based on the mode passed via kernel command line selects the correct hw backend. kasan_enable_tagging() is meant to be invoked indirectly via the cpu features framework of the architectures that support these backends. Currently the invocation of this function is guarded by CONFIG_KASAN_KUNIT_TEST which allows the enablement of the correct backend only when KUNIT tests are enabled in the kernel. This inconsistency was introduced in commit: ed6d744 ("kasan: test: support async (again) and asymm modes for HW_TAGS") ... and prevents to enable MTE on arm64 when KUNIT tests for kasan hw_tags are disabled. Fix the issue making sure that the CONFIG_KASAN_KUNIT_TEST guard does not prevent the correct invocation of kasan_enable_tagging(). Link: https://lkml.kernel.org/r/20220408124323.10028-1-vincenzo.frascino@arm.com Fixes: ed6d744 ("kasan: test: support async (again) and asymm modes for HW_TAGS") Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Alexander Potapenko <glider@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 25934fc commit b1add41

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

mm/kasan/hw_tags.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ void __kasan_poison_vmalloc(const void *start, unsigned long size)
336336

337337
#endif
338338

339-
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
340-
341339
void kasan_enable_tagging(void)
342340
{
343341
if (kasan_arg_mode == KASAN_ARG_MODE_ASYNC)
@@ -347,6 +345,9 @@ void kasan_enable_tagging(void)
347345
else
348346
hw_enable_tagging_sync();
349347
}
348+
349+
#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
350+
350351
EXPORT_SYMBOL_GPL(kasan_enable_tagging);
351352

352353
void kasan_force_async_fault(void)

mm/kasan/kasan.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,27 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
355355
#define hw_set_mem_tag_range(addr, size, tag, init) \
356356
arch_set_mem_tag_range((addr), (size), (tag), (init))
357357

358+
void kasan_enable_tagging(void);
359+
358360
#else /* CONFIG_KASAN_HW_TAGS */
359361

360362
#define hw_enable_tagging_sync()
361363
#define hw_enable_tagging_async()
362364
#define hw_enable_tagging_asymm()
363365

366+
static inline void kasan_enable_tagging(void) { }
367+
364368
#endif /* CONFIG_KASAN_HW_TAGS */
365369

366370
#if defined(CONFIG_KASAN_HW_TAGS) && IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
367371

368-
void kasan_enable_tagging(void);
369372
void kasan_force_async_fault(void);
370373

371-
#else /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
374+
#else /* CONFIG_KASAN_HW_TAGS && CONFIG_KASAN_KUNIT_TEST */
372375

373-
static inline void kasan_enable_tagging(void) { }
374376
static inline void kasan_force_async_fault(void) { }
375377

376-
#endif /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
378+
#endif /* CONFIG_KASAN_HW_TAGS && CONFIG_KASAN_KUNIT_TEST */
377379

378380
#ifdef CONFIG_KASAN_SW_TAGS
379381
u8 kasan_random_tag(void);

0 commit comments

Comments
 (0)