[PATCH v1] mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation

From: Yu Jiaoliang
Date: Wed Aug 21 2024 - 06:55:37 EST


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

Signed-off-by: Yu Jiaoliang <yujiaoliang@xxxxxxxx>
---
fs/mnt_idmapping.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/mnt_idmapping.c b/fs/mnt_idmapping.c
index 3c60f1eaca61..fea0244a87ce 100644
--- a/fs/mnt_idmapping.c
+++ b/fs/mnt_idmapping.c
@@ -228,9 +228,9 @@ 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;

--
2.34.1