* [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation
@ 2024-08-28 7:23 Jinjie Ruan
2024-08-29 1:32 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Jinjie Ruan @ 2024-08-28 7:23 UTC (permalink / raw)
To: brauner, akpm, kees, zeming, adobriyan, rdunlap, linux-kernel; +Cc: ruanjinjie
Let the kmemdup_array() take care about multiplication and possible
overflows.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation
2024-08-28 7:23 [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation Jinjie Ruan
@ 2024-08-29 1:32 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2024-08-29 1:32 UTC (permalink / raw)
To: Jinjie Ruan; +Cc: brauner, akpm, zeming, adobriyan, rdunlap, linux-kernel
On Wed, Aug 28, 2024 at 03:23:40PM +0800, Jinjie Ruan wrote:
> Let the kmemdup_array() take care about multiplication and possible
> overflows.
>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-29 1:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-28 7:23 [PATCH -next] user_namespace: Use kmemdup_array() instead of kmemdup() for multiple allocation Jinjie Ruan
2024-08-29 1:32 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®