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

Yu Jiaoliang posted 1 patch 1 year, 5 months ago
fs/mnt_idmapping.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
[PATCH v2] mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation
Posted by Yu Jiaoliang 1 year, 5 months ago
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>
---
 fs/mnt_idmapping.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/mnt_idmapping.c b/fs/mnt_idmapping.c
index 3c60f1eaca61..79491663dbc0 100644
--- a/fs/mnt_idmapping.c
+++ b/fs/mnt_idmapping.c
@@ -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;
-- 
2.34.1
Re: [PATCH v2] mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation
Posted by Christian Brauner 1 year, 5 months ago
On Fri, 23 Aug 2024 09:55:41 +0800, Yu Jiaoliang wrote:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> v2:Add a new modification for reverse array.
> 
> 

Applied to the vfs.misc branch of the vfs/vfs.git tree.
Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation
      https://git.kernel.org/vfs/vfs/c/639639c8ce66
Re: [PATCH v2] mnt_idmapping: Use kmemdup_array instead of kmemdup for multiple allocation
Posted by Jan Kara 1 year, 5 months ago
On Fri 23-08-24 09:55:41, Yu Jiaoliang wrote:
> 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>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/mnt_idmapping.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/mnt_idmapping.c b/fs/mnt_idmapping.c
> index 3c60f1eaca61..79491663dbc0 100644
> --- a/fs/mnt_idmapping.c
> +++ b/fs/mnt_idmapping.c
> @@ -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;
> -- 
> 2.34.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR