Skip to content

Commit 0fc79cb

Browse files
andy-shevkees
authored andcommitted
params: Use size_add() for kmalloc()
Prevent allocations from integer overflow by using size_add(). Reviewed-by: Luis Chamberlain <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent fd0cd05 commit 0fc79cb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/params.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/moduleparam.h>
1212
#include <linux/device.h>
1313
#include <linux/err.h>
14+
#include <linux/overflow.h>
1415
#include <linux/slab.h>
1516
#include <linux/ctype.h>
1617
#include <linux/security.h>
@@ -48,7 +49,7 @@ static void *kmalloc_parameter(unsigned int size)
4849
{
4950
struct kmalloced_param *p;
5051

51-
p = kmalloc(sizeof(*p) + size, GFP_KERNEL);
52+
p = kmalloc(size_add(sizeof(*p), size), GFP_KERNEL);
5253
if (!p)
5354
return NULL;
5455

0 commit comments

Comments
 (0)