From ce6fa91b93630396ca220c33dd38ffc62686d499 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Wed, 6 Sep 2017 16:19:22 -0700 Subject: [PATCH] mm/slub.c: add a naive detection of double free or corruption Add an assertion similar to "fasttop" check in GNU C Library allocator as a part of SLAB_FREELIST_HARDENED feature. An object added to a singly linked freelist should not point to itself. That helps to detect some double free errors (e.g. CVE-2017-2636) without slub_debug and KASAN. Link: http://lkml.kernel.org/r/1502468246-1262-1-git-send-email-alex.popov@linux.com Signed-off-by: Alexander Popov Acked-by: Christoph Lameter Cc: Kees Cook Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Paul E McKenney Cc: Ingo Molnar Cc: Tejun Heo Cc: Andy Lutomirski Cc: Nicolas Pitre Cc: Rik van Riel Cc: Tycho Andersen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/slub.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 6c87c2c6af24..16a60f871f39 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -290,6 +290,10 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp) { unsigned long freeptr_addr = (unsigned long)object + s->offset; +#ifdef CONFIG_SLAB_FREELIST_HARDENED + BUG_ON(object == fp); /* naive detection of double free or corruption */ +#endif + *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr); } -- 2.20.1