Skip to content

Commit ce5716c

Browse files
xairytorvalds
authored andcommitted
kasan, mm: fix conflicts with init_on_alloc/free
A few places where SLUB accesses object's data or metadata were missed in a previous patch. This leads to false positives with hardware tag-based KASAN when bulk allocations are used with init_on_alloc/free. Fix the false-positives by resetting pointer tags during these accesses. (The kasan_reset_tag call is removed from slab_alloc_node, as it's added into maybe_wipe_obj_freeptr.) Link: https://linux-review.googlesource.com/id/I50dd32838a666e173fe06c3c5c766f2c36aae901 Link: https://lkml.kernel.org/r/093428b5d2ca8b507f4a79f92f9929b35f7fada7.1610731872.git.andreyknvl@google.com Fixes: aa1ef4d ("kasan, mm: reset tags when accessing metadata") Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Alexander Potapenko <glider@google.com> Cc: Marco Elver <elver@google.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Peter Collingbourne <pcc@google.com> Cc: Evgenii Stepanov <eugenis@google.com> Cc: Branislav Rankov <Branislav.Rankov@arm.com> Cc: Kevin Brodsky <kevin.brodsky@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 76bc99e commit ce5716c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

mm/slub.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,8 @@ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s,
27912791
void *obj)
27922792
{
27932793
if (unlikely(slab_want_init_on_free(s)) && obj)
2794-
memset((void *)((char *)obj + s->offset), 0, sizeof(void *));
2794+
memset((void *)((char *)kasan_reset_tag(obj) + s->offset),
2795+
0, sizeof(void *));
27952796
}
27962797

27972798
/*
@@ -2883,7 +2884,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s,
28832884
stat(s, ALLOC_FASTPATH);
28842885
}
28852886

2886-
maybe_wipe_obj_freeptr(s, kasan_reset_tag(object));
2887+
maybe_wipe_obj_freeptr(s, object);
28872888

28882889
if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object)
28892890
memset(kasan_reset_tag(object), 0, s->object_size);
@@ -3329,7 +3330,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
33293330
int j;
33303331

33313332
for (j = 0; j < i; j++)
3332-
memset(p[j], 0, s->object_size);
3333+
memset(kasan_reset_tag(p[j]), 0, s->object_size);
33333334
}
33343335

33353336
/* memcg and kmem_cache debug support */

0 commit comments

Comments
 (0)