[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250421062423.740605-1-suhui@nfschina.com>
Date: Mon, 21 Apr 2025 14:24:24 +0800
From: Su Hui <suhui@...china.com>
To: sj@...nel.org,
akpm@...ux-foundation.org
Cc: Su Hui <suhui@...china.com>,
damon@...ts.linux.dev,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH] mm/damon/sysfs-schemes: using kmalloc_array() and size_add()
It's safer to using kmalloc_array() and size_add() because it can
prevent possible overflow problem.
Signed-off-by: Su Hui <suhui@...china.com>
---
mm/damon/sysfs-schemes.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 23b562df0839..79220aba436f 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -465,7 +465,8 @@ static ssize_t memcg_path_store(struct kobject *kobj,
{
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
struct damon_sysfs_scheme_filter, kobj);
- char *path = kmalloc(sizeof(*path) * (count + 1), GFP_KERNEL);
+ char *path = kmalloc_array(size_add(count, 1), sizeof(*path),
+ GFP_KERNEL);
if (!path)
return -ENOMEM;
@@ -2035,7 +2036,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
if (!memcg_path)
return -EINVAL;
- path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
+ path = kmalloc_array(PATH_MAX, sizeof(*path), GFP_KERNEL);
if (!path)
return -ENOMEM;
--
2.30.2
Powered by blists - more mailing lists