Skip to content

Commit bfc8089

Browse files
Kuan-Ying Leetorvalds
authored andcommitted
mm/kmemleak: reset tag when compare object pointer
When we use HW-tag based kasan and enable vmalloc support, we hit the following bug. It is due to comparison between tagged object and non-tagged pointer. We need to reset the kasan tag when we need to compare tagged object and non-tagged pointer. kmemleak: [name:kmemleak&]Scan area larger than object 0xffffffe77076f440 CPU: 4 PID: 1 Comm: init Tainted: G S W 5.15.25-android13-0-g5cacf919c2bc #1 Hardware name: MT6983(ENG) (DT) Call trace: add_scan_area+0xc4/0x244 kmemleak_scan_area+0x40/0x9c layout_and_allocate+0x1e8/0x288 load_module+0x2c8/0xf00 __se_sys_finit_module+0x190/0x1d0 __arm64_sys_finit_module+0x20/0x30 invoke_syscall+0x60/0x170 el0_svc_common+0xc8/0x114 do_el0_svc+0x28/0xa0 el0_svc+0x60/0xf8 el0t_64_sync_handler+0x88/0xec el0t_64_sync+0x1b4/0x1b8 kmemleak: [name:kmemleak&]Object 0xf5ffffe77076b000 (size 32768): kmemleak: [name:kmemleak&] comm "init", pid 1, jiffies 4294894197 kmemleak: [name:kmemleak&] min_count = 0 kmemleak: [name:kmemleak&] count = 0 kmemleak: [name:kmemleak&] flags = 0x1 kmemleak: [name:kmemleak&] checksum = 0 kmemleak: [name:kmemleak&] backtrace: module_alloc+0x9c/0x120 move_module+0x34/0x19c layout_and_allocate+0x1c4/0x288 load_module+0x2c8/0xf00 __se_sys_finit_module+0x190/0x1d0 __arm64_sys_finit_module+0x20/0x30 invoke_syscall+0x60/0x170 el0_svc_common+0xc8/0x114 do_el0_svc+0x28/0xa0 el0_svc+0x60/0xf8 el0t_64_sync_handler+0x88/0xec el0t_64_sync+0x1b4/0x1b8 Link: https://lkml.kernel.org/r/20220318034051.30687-1-Kuan-Ying.Lee@mediatek.com Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Matthias Brugger <matthias.bgg@gmail.com> Cc: Chinwen Chang <chinwen.chang@mediatek.com> Cc: Nicholas Tang <nicholas.tang@mediatek.com> Cc: Yee Lee <yee.lee@mediatek.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c89b3ad commit bfc8089

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

mm/kmemleak.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
796796
unsigned long flags;
797797
struct kmemleak_object *object;
798798
struct kmemleak_scan_area *area = NULL;
799+
unsigned long untagged_ptr;
800+
unsigned long untagged_objp;
799801

800802
object = find_and_get_object(ptr, 1);
801803
if (!object) {
@@ -804,6 +806,9 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
804806
return;
805807
}
806808

809+
untagged_ptr = (unsigned long)kasan_reset_tag((void *)ptr);
810+
untagged_objp = (unsigned long)kasan_reset_tag((void *)object->pointer);
811+
807812
if (scan_area_cache)
808813
area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp));
809814

@@ -815,8 +820,8 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp)
815820
goto out_unlock;
816821
}
817822
if (size == SIZE_MAX) {
818-
size = object->pointer + object->size - ptr;
819-
} else if (ptr + size > object->pointer + object->size) {
823+
size = untagged_objp + object->size - untagged_ptr;
824+
} else if (untagged_ptr + size > untagged_objp + object->size) {
820825
kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr);
821826
dump_object_info(object);
822827
kmem_cache_free(scan_area_cache, area);

0 commit comments

Comments
 (0)