user_namespace: use kmemdup_array() instead of kmemdup() for multiple allocation
Let the kmemdup_array() take care about multiplication and possible overflows. Link: https://lkml.kernel.org/r/20240828072340.1249310-1-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Reviewed-by: Kees Cook <kees@kernel.org> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Li zeming <zeming@nfschina.com> Cc: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
0aa75a2b3f
commit
546f02823d
@ -853,9 +853,8 @@ static int sort_idmaps(struct uid_gid_map *map)
|
|||||||
cmp_extents_forward, NULL);
|
cmp_extents_forward, NULL);
|
||||||
|
|
||||||
/* Only copy the memory from forward we actually need. */
|
/* Only copy the memory from forward we actually need. */
|
||||||
map->reverse = kmemdup(map->forward,
|
map->reverse = kmemdup_array(map->forward, map->nr_extents,
|
||||||
map->nr_extents * sizeof(struct uid_gid_extent),
|
sizeof(struct uid_gid_extent), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!map->reverse)
|
if (!map->reverse)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user