On architectures with CONFIG_DCACHE_WORD_ACCESS, load_unaligned_zeropad() does the word loads of the dcache name compare and of path name hashing. None of the KASAN test cases reads memory through it, so nothing noticed that KASAN did not check these loads at all. Add a case that reads a freed object through load_unaligned_zeropad() and expects a report. Skip it with hardware tag-based KASAN, since arm64 turns tag checking off for this load: kasan_load_unaligned_zeropad, x86_64, generic KASAN without "word-at-a-time: check the first byte in load_unaligned_zeropad()" FAILED with it PASSED Signed-off-by: Qiliang Yuan --- mm/kasan/kasan_test_c.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c index b9e167ed5be32..c791512f6fc49 100644 --- a/mm/kasan/kasan_test_c.c +++ b/mm/kasan/kasan_test_c.c @@ -28,6 +28,9 @@ #include #include +#ifdef CONFIG_DCACHE_WORD_ACCESS +#include +#endif #include "kasan.h" @@ -1673,6 +1676,26 @@ static void kasan_memcmp(struct kunit *test) kfree(ptr); } +static void kasan_load_unaligned_zeropad(struct kunit *test) +{ +#ifdef CONFIG_DCACHE_WORD_ACCESS + char *ptr; + + /* The tag check is turned off for this load on arm64 with MTE. */ + KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_KASAN_HW_TAGS); + + ptr = kmalloc(64, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr); + kfree(ptr); + + OPTIMIZER_HIDE_VAR(ptr); + KUNIT_EXPECT_KASAN_FAIL_READ(test, + kasan_int_result = load_unaligned_zeropad(ptr)); +#else + kunit_skip(test, "Test requires CONFIG_DCACHE_WORD_ACCESS=y"); +#endif +} + static void kasan_strings(struct kunit *test) { char *ptr; @@ -2264,6 +2287,7 @@ static struct kunit_case kasan_kunit_test_cases[] = { KUNIT_CASE(kasan_alloca_oob_right), KUNIT_CASE(kasan_memchr), KUNIT_CASE(kasan_memcmp), + KUNIT_CASE(kasan_load_unaligned_zeropad), KUNIT_CASE(kasan_strings), KUNIT_CASE(kasan_bitops_generic), KUNIT_CASE(kasan_bitops_tags), -- 2.43.0