Skip to content

Commit 546f028

Browse files
Jinjie Ruanakpm00
authored andcommitted
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/[email protected] Signed-off-by: Jinjie Ruan <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Li zeming <[email protected]> Cc: Randy Dunlap <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0aa75a2 commit 546f028

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/user_namespace.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,8 @@ static int sort_idmaps(struct uid_gid_map *map)
853853
cmp_extents_forward, NULL);
854854

855855
/* Only copy the memory from forward we actually need. */
856-
map->reverse = kmemdup(map->forward,
857-
map->nr_extents * sizeof(struct uid_gid_extent),
858-
GFP_KERNEL);
856+
map->reverse = kmemdup_array(map->forward, map->nr_extents,
857+
sizeof(struct uid_gid_extent), GFP_KERNEL);
859858
if (!map->reverse)
860859
return -ENOMEM;
861860

0 commit comments

Comments
 (0)