summaryrefslogtreecommitdiffstats
path: root/include/linux/mm.h
diff options
context:
space:
mode:
authorKees Cook2018-05-08 21:55:26 +0200
committerKees Cook2018-06-05 21:16:51 +0200
commit3b3b1a29eb89ba93f91213cbebb332a2ac31fa8b (patch)
treef163f64ea43d4afee78f1bc0ad5eadc882e40343 /include/linux/mm.h
parentmm: Use overflow helpers in kmalloc_array*() (diff)
downloadkernel-qcow2-linux-3b3b1a29eb89ba93f91213cbebb332a2ac31fa8b.tar.gz
kernel-qcow2-linux-3b3b1a29eb89ba93f91213cbebb332a2ac31fa8b.tar.xz
kernel-qcow2-linux-3b3b1a29eb89ba93f91213cbebb332a2ac31fa8b.zip
mm: Use overflow helpers in kvmalloc()
Instead of open-coded multiplication and bounds checking, use the new overflow helper. Additionally prepare for vmalloc() users to add array_size()-family helpers in the future. Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'include/linux/mm.h')
-rw-r--r--include/linux/mm.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 1ac1f06a4be6..7cb1c6a6bf82 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -25,6 +25,7 @@
#include <linux/err.h>
#include <linux/page_ref.h>
#include <linux/memremap.h>
+#include <linux/overflow.h>
struct mempolicy;
struct anon_vma;
@@ -560,10 +561,12 @@ static inline void *kvzalloc(size_t size, gfp_t flags)
static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags)
{
- if (size != 0 && n > SIZE_MAX / size)
+ size_t bytes;
+
+ if (unlikely(check_mul_overflow(n, size, &bytes)))
return NULL;
- return kvmalloc(n * size, flags);
+ return kvmalloc(bytes, flags);
}
extern void kvfree(const void *addr);