[v1,4/6] params: Use size_add() for kmalloc()

Message ID 20230912150551.401537-4-andriy.shevchenko@linux.intel.com
State New
Headers
Series [v1,1/6] params: Use sysfs_emit() to instead of scnprintf() |

Commit Message

Andy Shevchenko Sept. 12, 2023, 3:05 p.m. UTC
  Prevent allocations from integer overflow by using size_add().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 kernel/params.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/kernel/params.c b/kernel/params.c
index 930a5dc2f004..fd11c731475f 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -11,6 +11,7 @@ 
 #include <linux/moduleparam.h>
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/overflow.h>
 #include <linux/slab.h>
 #include <linux/ctype.h>
 #include <linux/security.h>
@@ -48,7 +49,7 @@  static void *kmalloc_parameter(unsigned int size)
 {
 	struct kmalloced_param *p;
 
-	p = kmalloc(sizeof(*p) + size, GFP_KERNEL);
+	p = kmalloc(size_add(sizeof(*p), size), GFP_KERNEL);
 	if (!p)
 		return NULL;