Skip to content

Commit

Permalink
kasan, mm: fix conflicts with init_on_alloc/free
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: Dmitry Vyukov <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Vincenzo Frascino <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Peter Collingbourne <[email protected]>
Cc: Evgenii Stepanov <[email protected]>
Cc: Branislav Rankov <[email protected]>
Cc: Kevin Brodsky <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xairy authored and torvalds committed Jan 24, 2021
1 parent 76bc99e commit ce5716c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,8 @@ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s,
void *obj)
{
if (unlikely(slab_want_init_on_free(s)) && obj)
memset((void *)((char *)obj + s->offset), 0, sizeof(void *));
memset((void *)((char *)kasan_reset_tag(obj) + s->offset),
0, sizeof(void *));
}

/*
Expand Down Expand Up @@ -2883,7 +2884,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s,
stat(s, ALLOC_FASTPATH);
}

maybe_wipe_obj_freeptr(s, kasan_reset_tag(object));
maybe_wipe_obj_freeptr(s, object);

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

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

/* memcg and kmem_cache debug support */
Expand Down

0 comments on commit ce5716c

Please sign in to comment.