[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240828072340.1249310-1-ruanjinjie@huawei.com>
Date: Wed, 28 Aug 2024 15:23:40 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <brauner@...nel.org>, <akpm@...ux-foundation.org>, <kees@...nel.org>,
<zeming@...china.com>, <adobriyan@...il.com>, <rdunlap@...radead.org>,
<linux-kernel@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation
Let the kmemdup_array() take care about multiplication and possible
overflows.
Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
---
kernel/user_namespace.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 0b0b95418b16..aa0b2e47f2f2 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -853,9 +853,8 @@ static int sort_idmaps(struct uid_gid_map *map)
cmp_extents_forward, NULL);
/* Only copy the memory from forward we actually need. */
- map->reverse = kmemdup(map->forward,
- map->nr_extents * sizeof(struct uid_gid_extent),
- GFP_KERNEL);
+ map->reverse = kmemdup_array(map->forward, map->nr_extents,
+ sizeof(struct uid_gid_extent), GFP_KERNEL);
if (!map->reverse)
return -ENOMEM;
--
2.34.1
Powered by blists - more mailing lists