Commit 75e4c6bc authored by Yu Jiaoliang's avatar Yu Jiaoliang Committed by Christian Brauner

mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation

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

v2:Add a new modification for reverse array.
Signed-off-by: default avatarYu Jiaoliang <yujiaoliang@vivo.com>
Link: https://lore.kernel.org/r/20240823015542.3006262-1-yujiaoliang@vivo.comReviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 3c58a957
...@@ -228,15 +228,15 @@ static int copy_mnt_idmap(struct uid_gid_map *map_from, ...@@ -228,15 +228,15 @@ static int copy_mnt_idmap(struct uid_gid_map *map_from,
return 0; return 0;
} }
forward = kmemdup(map_from->forward, forward = kmemdup_array(map_from->forward, nr_extents,
nr_extents * sizeof(struct uid_gid_extent), sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT); GFP_KERNEL_ACCOUNT);
if (!forward) if (!forward)
return -ENOMEM; return -ENOMEM;
reverse = kmemdup(map_from->reverse, reverse = kmemdup_array(map_from->reverse, nr_extents,
nr_extents * sizeof(struct uid_gid_extent), sizeof(struct uid_gid_extent),
GFP_KERNEL_ACCOUNT); GFP_KERNEL_ACCOUNT);
if (!reverse) { if (!reverse) {
kfree(forward); kfree(forward);
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment