From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH v1 4/6] params: Use size_add() for kmalloc()
Date: Tue, 12 Sep 2023 18:05:49 +0300 [thread overview]
Message-ID: <20230912150551.401537-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230912150551.401537-1-andriy.shevchenko@linux.intel.com>
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(-)
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;
--
2.40.0.1.gaa8946217a0b
next prev parent reply other threads:[~2023-09-12 15:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 15:05 [PATCH v1 1/6] params: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 2/6] params: Introduce the param_unknown_fn type Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 3/6] params: Do not go over the limit when getting the string length Andy Shevchenko
2023-09-12 15:24 ` Andy Shevchenko
2023-09-12 15:05 ` Andy Shevchenko [this message]
2023-09-12 15:05 ` [PATCH v1 5/6] params: Sort headers Andy Shevchenko
2023-09-12 15:05 ` [PATCH v1 6/6] params: Fix multi-line comment style Andy Shevchenko
2023-09-18 16:57 ` [PATCH v1 1/6] params: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-09-21 0:32 ` Luis Chamberlain
2023-09-21 9:36 ` Andy Shevchenko
2023-09-21 13:34 ` kernel test robot
2023-09-21 15:36 ` Andy Shevchenko
2023-09-21 16:18 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230912150551.401537-4-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox