summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2013-05-03 15:43:18 +0000
committerPekka Enberg <penberg@kernel.org>2013-05-06 09:24:16 +0300
commit6286ae97d10ea2b5cd90532163797ab217bfdbdf (patch)
tree0724efb47d735ce835709d2402de02de4dd61f07
parent14e50c6a9bc2b283bb4021026226268312ceefdd (diff)
slab: Return NULL for oversized allocations
The inline path seems to have changed the SLAB behavior for very large kmalloc allocations with commit e3366016 ("slab: Use common kmalloc_index/kmalloc_size functions"). This patch restores the old behavior but also adds diagnostics so that we can figure where in the code these large allocations occur. Reported-and-tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Christoph Lameter <cl@linux.com> Link: http://lkml.kernel.org/r/201305040348.CIF81716.OStQOHFJMFLOVF@I-love.SAKURA.ne.jp [ penberg@kernel.org: use WARN_ON_ONCE ] Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r--include/linux/slab_def.h6
-rw-r--r--mm/slab_common.c3
2 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
index 113ec080313f..cd401580bdd3 100644
--- a/include/linux/slab_def.h
+++ b/include/linux/slab_def.h
@@ -126,6 +126,9 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
if (!size)
return ZERO_SIZE_PTR;
+ if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE))
+ return NULL;
+
i = kmalloc_index(size);
#ifdef CONFIG_ZONE_DMA
@@ -172,6 +175,9 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
if (!size)
return ZERO_SIZE_PTR;
+ if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE))
+ return NULL;
+
i = kmalloc_index(size);
#ifdef CONFIG_ZONE_DMA
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 2f0e7d5976cb..c5d352e73d81 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -373,6 +373,9 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
{
int index;
+ if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE))
+ return NULL;
+
if (size <= 192) {
if (!size)
return ZERO_SIZE_PTR;