[PATCH 5.14 102/169] mm, slub: fix potential use-after-free in slab_debugfs_fops

From
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date
2021-10-25 19:53:23
Also in
lkml
Reply to
Greg Kroah-Hartman, 2021-10-25
From: Miaohe Lin <linmiaohe@huawei.com>

commit 67823a544414def2a36c212abadb55b23bcda00c upstream.

When sysfs_slab_add failed, we shouldn't call debugfs_slab_add() for s
because s will be freed soon.  And slab_debugfs_fops will use s later
leading to a use-after-free.

Link: https://lkml.kernel.org/r/20210916123920.48704-5-linmiaohe@huawei.com (local)
Fixes: 64dd68497be7 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: Vlastimil Babka <redacted>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Bharata B Rao <redacted>
Cc: Christoph Lameter <redacted>
Cc: David Rientjes <rientjes@google.com>
Cc: Faiyaz Mohammed <redacted>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Joonsoo Kim <redacted>
Cc: Kees Cook <redacted>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Roman Gushchin <redacted>
Cc: <redacted>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 mm/slub.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4604,13 +4604,15 @@ int __kmem_cache_create(struct kmem_cach
 		return 0;
 
 	err = sysfs_slab_add(s);
-	if (err)
+	if (err) {
 		__kmem_cache_release(s);
+		return err;
+	}
 
 	if (s->flags & SLAB_STORE_USER)
 		debugfs_slab_add(s);
 
-	return err;
+	return 0;
 }
 
 void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)

Thread (181 messages) 181 messages, 9 authors, last reply 2022-01-11
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help