Kmemleak need to scan kernel memory to check memory leak.
With hardware tag-based kasan enabled, when it scans on
the invalid slab and dereference, the issue will occur
as below.
Hardware tag-based KASAN doesn't use compiler instrumentation, we
can not use kasan_disable_current() to ignore tag check.
Based on the below report, there are 11 0xf7 granules, which amounts to
176 bytes, and the object is allocated from the kmalloc-256 cache. So
when kmemleak accesses the last 256-176 bytes, it causes faults, as
those are marked with KASAN_KMALLOC_REDZONE == KASAN_TAG_INVALID ==
0xfe.
Thus, we reset tags before accessing metadata to avoid from false positives.
[ 151.905804] ==================================================================
[ 151.907120] BUG: KASAN: out-of-bounds in scan_block+0x58/0x170
[ 151.908773] Read at addr f7ff0000c0074eb0 by task kmemleak/138
[ 151.909656] Pointer tag: [f7], memory tag: [fe]
[ 151.910195]
[ 151.910876] CPU: 7 PID: 138 Comm: kmemleak Not tainted 5.14.0-rc2-00001-g8cae8cd89f05-dirty #134
[ 151.912085] Hardware name: linux,dummy-virt (DT)
[ 151.912868] Call trace:
[ 151.913211] dump_backtrace+0x0/0x1b0
[ 151.913796] show_stack+0x1c/0x30
[ 151.914248] dump_stack_lvl+0x68/0x84
[ 151.914778] print_address_description+0x7c/0x2b4
[ 151.915340] kasan_report+0x138/0x38c
[ 151.915804] __do_kernel_fault+0x190/0x1c4
[ 151.916386] do_tag_check_fault+0x78/0x90
[ 151.916856] do_mem_abort+0x44/0xb4
[ 151.917308] el1_abort+0x40/0x60
[ 151.917754] el1h_64_sync_handler+0xb4/0xd0
[ 151.918270] el1h_64_sync+0x78/0x7c
[ 151.918714] scan_block+0x58/0x170
[ 151.919157] scan_gray_list+0xdc/0x1a0
[ 151.919626] kmemleak_scan+0x2ac/0x560
[ 151.920129] kmemleak_scan_thread+0xb0/0xe0
[ 151.920635] kthread+0x154/0x160
61 more lines
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 228a2fbe0657..73d46d16d575 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -290,7 +290,7 @@ static void hex_dump_object(struct seq_file *seq,
warn_or_seq_printf(seq, " hex dump (first %zu bytes):\n", len);
kasan_disable_current();
warn_or_seq_hex_dump(seq, DUMP_PREFIX_NONE, HEX_ROW_SIZE,
- HEX_GROUP_SIZE, ptr, len, HEX_ASCII);
+ HEX_GROUP_SIZE, kasan_reset_tag((void *)ptr), len, HEX_ASCII);
kasan_enable_current();
}
@@ -1171,7 +1171,7 @@ static bool update_checksum(struct kmemleak_object *object)
kasan_disable_current();
kcsan_disable_current();
- object->checksum = crc32(0, (void *)object->pointer, object->size);
+ object->checksum = crc32(0, kasan_reset_tag((void *)object->pointer), object->size);
kasan_enable_current();
kcsan_enable_current();
@@ -1246,7 +1246,7 @@ static void scan_block(void *_start, void *_end,
break;
kasan_disable_current();
- pointer = *ptr;
+ pointer = *(unsigned long *)kasan_reset_tag((void *)ptr);
kasan_enable_current();
untagged_ptr = (unsigned long)kasan_reset_tag((void *)pointer);
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel