The patch titled Subject: user_namespace: use kmemdup_array() instead of kmemdup() for multiple allocation has been added to the -mm mm-nonmm-unstable branch. Its filename is user_namespace-use-kmemdup_array-instead-of-kmemdup-for-multiple-allocation.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/user_namespace-use-kmemdup_array-instead-of-kmemdup-for-multiple-allocation.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Jinjie Ruan <ruanjinjie@xxxxxxxxxx> Subject: user_namespace: use kmemdup_array() instead of kmemdup() for multiple allocation Date: Wed, 28 Aug 2024 15:23:40 +0800 Let the kmemdup_array() take care about multiplication and possible overflows. Link: https://lkml.kernel.org/r/20240828072340.1249310-1-ruanjinjie@xxxxxxxxxx Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx> Reviewed-by: Kees Cook <kees@xxxxxxxxxx> Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Christian Brauner <brauner@xxxxxxxxxx> Cc: Li zeming <zeming@xxxxxxxxxxxx> Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/user_namespace.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/kernel/user_namespace.c~user_namespace-use-kmemdup_array-instead-of-kmemdup-for-multiple-allocation +++ a/kernel/user_namespace.c @@ -853,9 +853,8 @@ static int sort_idmaps(struct uid_gid_ma cmp_extents_forward, NULL); /* Only copy the memory from forward we actually need. */ - map->reverse = kmemdup(map->forward, - map->nr_extents * sizeof(struct uid_gid_extent), - GFP_KERNEL); + map->reverse = kmemdup_array(map->forward, map->nr_extents, + sizeof(struct uid_gid_extent), GFP_KERNEL); if (!map->reverse) return -ENOMEM; _ Patches currently in -mm which might be from ruanjinjie@xxxxxxxxxx are crash-fix-crash-memory-reserve-exceed-system-memory-bug.patch user_namespace-use-kmemdup_array-instead-of-kmemdup-for-multiple-allocation.patch