]> www.infradead.org Git - users/willy/linux.git/commitdiff
kasan: Fix tag for large allocations when using CONFIG_SLAB
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 1 Oct 2021 02:31:48 +0000 (22:31 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 3 Oct 2021 10:56:47 +0000 (06:56 -0400)
If an object is allocated on a tail page of a multi-page slab, kasan
will get the wrong tag because page->s_mem is NULL for tail pages.
I'm not quite sure what the user-visible effect of this might be.

Fixes: 7f94ffbc4c6a ("kasan: add hooks implementation for tag-based mode")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
mm/kasan/common.c

index 2baf121fb8c50030b761b8c546aa26853b8d08e3..41779ad109cdb475a8855f6b7b8bdca76ed72c10 100644 (file)
@@ -298,7 +298,7 @@ static inline u8 assign_tag(struct kmem_cache *cache,
        /* For caches that either have a constructor or SLAB_TYPESAFE_BY_RCU: */
 #ifdef CONFIG_SLAB
        /* For SLAB assign tags based on the object index in the freelist. */
-       return (u8)obj_to_index(cache, virt_to_page(object), (void *)object);
+       return (u8)obj_to_index(cache, virt_to_head_page(object), (void *)object);
 #else
        /*
         * For SLUB assign a random tag during slab creation, otherwise reuse