Skip to content

Commit

Permalink
mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allo…
Browse files Browse the repository at this point in the history
…cation

Let the kememdup_array() take care about multiplication and possible
overflows.

v2:Add a new modification for reverse array.

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
Link: https://lore.kernel.org/r/20240823015542.3006262-1-yujiaoliang@vivo.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Yu Jiaoliang authored and brauner committed Aug 30, 2024
1 parent 3c58a95 commit 75e4c6b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fs/mnt_idmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ static int copy_mnt_idmap(struct uid_gid_map *map_from,
return 0;
}

forward = kmemdup(map_from->forward,
nr_extents * sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT);
forward = kmemdup_array(map_from->forward, nr_extents,
sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT);
if (!forward)
return -ENOMEM;

reverse = kmemdup(map_from->reverse,
nr_extents * sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT);
reverse = kmemdup_array(map_from->reverse, nr_extents,
sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT);
if (!reverse) {
kfree(forward);
return -ENOMEM;
Expand Down

0 comments on commit 75e4c6b

Please sign in to comment.