Skip to content

Commit 536ffb4

Browse files
anakryikogregkh
authored andcommitted
mm: fix vrealloc()'s KASAN poisoning logic
commit d699440 upstream. When vrealloc() reuses already allocated vmap_area, we need to re-annotate poisoned and unpoisoned portions of underlying memory according to the new size. This results in a KASAN splat recorded at [1]. A KASAN mis-reporting issue where there is none. Note, hard-coding KASAN_VMALLOC_PROT_NORMAL might not be exactly correct, but KASAN flag logic is pretty involved and spread out throughout __vmalloc_node_range_noprof(), so I'm using the bare minimum flag here and leaving the rest to mm people to refactor this logic and reuse it here. Link: https://lkml.kernel.org/r/[email protected] Link: https://lore.kernel.org/bpf/[email protected]/ [1] Fixes: 3ddc2fe ("mm: vmalloc: implement vrealloc()") Signed-off-by: Andrii Nakryiko <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Uladzislau Rezki (Sony) <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bd4d233 commit 536ffb4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/vmalloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4093,7 +4093,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags)
40934093
/* Zero out spare memory. */
40944094
if (want_init_on_alloc(flags))
40954095
memset((void *)p + size, 0, old_size - size);
4096-
4096+
kasan_poison_vmalloc(p + size, old_size - size);
4097+
kasan_unpoison_vmalloc(p, size, KASAN_VMALLOC_PROT_NORMAL);
40974098
return (void *)p;
40984099
}
40994100

0 commit comments

Comments
 (0)