diff options
-rw-r--r-- | include/linux/slab_def.h | 6 | ||||
-rw-r--r-- | mm/slab_common.c | 3 |
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) | |||
126 | if (!size) | 126 | if (!size) |
127 | return ZERO_SIZE_PTR; | 127 | return ZERO_SIZE_PTR; |
128 | 128 | ||
129 | if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE)) | ||
130 | return NULL; | ||
131 | |||
129 | i = kmalloc_index(size); | 132 | i = kmalloc_index(size); |
130 | 133 | ||
131 | #ifdef CONFIG_ZONE_DMA | 134 | #ifdef CONFIG_ZONE_DMA |
@@ -172,6 +175,9 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) | |||
172 | if (!size) | 175 | if (!size) |
173 | return ZERO_SIZE_PTR; | 176 | return ZERO_SIZE_PTR; |
174 | 177 | ||
178 | if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE)) | ||
179 | return NULL; | ||
180 | |||
175 | i = kmalloc_index(size); | 181 | i = kmalloc_index(size); |
176 | 182 | ||
177 | #ifdef CONFIG_ZONE_DMA | 183 | #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) | |||
373 | { | 373 | { |
374 | int index; | 374 | int index; |
375 | 375 | ||
376 | if (WARN_ON_ONCE(size > KMALLOC_MAX_SIZE)) | ||
377 | return NULL; | ||
378 | |||
376 | if (size <= 192) { | 379 | if (size <= 192) { |
377 | if (!size) | 380 | if (!size) |
378 | return ZERO_SIZE_PTR; | 381 | return ZERO_SIZE_PTR; |