[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1559133448-31779-1-git-send-email-dianzhangchen0@gmail.com>
Date: Wed, 29 May 2019 20:37:28 +0800
From: Dianzhang Chen <dianzhangchen0@...il.com>
To: cl@...ux.com
Cc: penberg@...nel.org, rientjes@...gle.com, iamjoonsoo.kim@....com,
akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
Dianzhang Chen <dianzhangchen0@...il.com>
Subject: [PATCH] mm/slab_common.c: fix possible spectre-v1 in kmalloc_slab()
The `size` in kmalloc_slab() is indirectly controlled by userspace via syscall: poll(defined in fs/select.c), hence leading to a potential exploitation of the Spectre variant 1 vulnerability.
The `size` can be controlled from: poll -> do_sys_poll -> kmalloc -> __kmalloc -> kmalloc_slab.
Fix this by sanitizing `size` before using it to index size_index.
Signed-off-by: Dianzhang Chen <dianzhangchen0@...il.com>
---
mm/slab_common.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 58251ba..41c7e34 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -21,6 +21,7 @@
#include <asm/tlbflush.h>
#include <asm/page.h>
#include <linux/memcontrol.h>
+#include <linux/nospec.h>
#define CREATE_TRACE_POINTS
#include <trace/events/kmem.h>
@@ -1056,6 +1057,7 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
if (!size)
return ZERO_SIZE_PTR;
+ size = array_index_nospec(size, 193);
index = size_index[size_index_elem(size)];
} else {
if (WARN_ON_ONCE(size > KMALLOC_MAX_CACHE_SIZE))
--
2.7.4
Powered by blists - more mailing lists