linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kasan: Fix tag for large allocations when using CONFIG_SLAB
@ 2021-10-01  2:41 Matthew Wilcox (Oracle)
  2021-10-01 10:30 ` Marco Elver
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-10-01  2:41 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Andrew Morton, kasan-dev, linux-mm, linux-kernel
  Cc: Matthew Wilcox (Oracle)

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 2baf121fb8c5..41779ad109cd 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -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
-- 
2.32.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-03 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01  2:41 [PATCH] kasan: Fix tag for large allocations when using CONFIG_SLAB Matthew Wilcox (Oracle)
2021-10-01 10:30 ` Marco Elver
2021-10-01 13:29 ` Andrey Konovalov
2021-10-01 14:05   ` Matthew Wilcox
2021-10-03 16:27     ` Andrey Konovalov
2021-10-03 16:27 ` Andrey Konovalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox