All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] slub: choose the right freelist pointer location when creating small caches
@ 2021-06-05  1:58 ` Lin, Zhenpeng
  0 siblings, 0 replies; 10+ messages in thread
From: Lin, Zhenpeng @ 2021-06-05  1:58 UTC (permalink / raw)
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Kees Cook, linux-mm,
	linux-kernel

When enabling CONFIG_SLUB_DEBUG and booting with "slub_debug=Z", the
kernel crashes at creating caches if the object size is smaller
than 2*sizeof(void*). The problem is due to the wrong calculation
of freepointer_area. The freelist pointer can be stored in the
middle of object only if the object size is not smaller than
2*sizeof(void*). Otherwise, the freelist pointer will be corrupted by
SLUB_RED_ZONE.

Fixes: 3202fa62fb43 ("slub: relocate freelist pointer to middle of object")
Fixes: 89b83f282d8b ("slub: avoid redzone when choosing freepointer location")
Signed-off-by: Zhenpeng Lin <zplin@psu.edu>
---
mm/slub.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 3f96e099817a..cb23233ee683 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3704,7 +3704,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
	 * can't use that portion for writing the freepointer, so
	 * s->offset must be limited within this for the general case.
	 */
-	freepointer_area = size;
+	freepointer_area = s->object_size;

#ifdef CONFIG_SLUB_DEBUG
	/*
@@ -3751,7 +3751,7 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
		 */
		s->offset = size;
		size += sizeof(void *);
-	} else if (freepointer_area > sizeof(void *)) {
+	} else if (freepointer_area >= 2 * sizeof(void *)) {
		/*
		 * Store freelist pointer near middle of object to keep
		 * it away from the edges of the object to avoid small
--
2.17.1



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

end of thread, other threads:[~2021-06-11  4:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05  1:58 [PATCH] slub: choose the right freelist pointer location when creating small caches Lin, Zhenpeng
2021-06-05  1:58 ` Lin, Zhenpeng
2021-06-08 18:26 ` Kees Cook
2021-06-08 18:33   ` Lin, Zhenpeng
2021-06-08 18:41     ` Kees Cook
2021-06-08 19:06       ` Lin, Zhenpeng
2021-06-08 23:14         ` Kees Cook
2021-06-10 20:20           ` Lin, Zhenpeng
2021-06-10 23:01             ` Kees Cook
2021-06-11  4:22               ` Lin, Zhenpeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.