The patch titled Subject: mm/memcg: use struct_size() helper in kzalloc() has been added to the -mm tree. Its filename is mm-memcg-use-struct_size-helper-in-kzalloc.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-memcg-use-struct_size-helper-in-kzalloc.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-memcg-use-struct_size-helper-in-kzalloc.patch 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 and is updated there every 3-4 working days ------------------------------------------------------ From: Wang Weiyang <wangweiyang2@xxxxxxxxxx> Subject: mm/memcg: use struct_size() helper in kzalloc() Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Link: https://github.com/KSPP/linux/issues/160 Link: https://lkml.kernel.org/r/20211216022024.127375-1-wangweiyang2@xxxxxxxxxx Signed-off-by: Wang Weiyang <wangweiyang2@xxxxxxxxxx> Reviewed-by: Muchun Song <songmuchun@xxxxxxxxxxxxx> Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memcontrol.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) --- a/mm/memcontrol.c~mm-memcg-use-struct_size-helper-in-kzalloc +++ a/mm/memcontrol.c @@ -5122,15 +5122,11 @@ static void mem_cgroup_free(struct mem_c static struct mem_cgroup *mem_cgroup_alloc(void) { struct mem_cgroup *memcg; - unsigned int size; int node; int __maybe_unused i; long error = -ENOMEM; - size = sizeof(struct mem_cgroup); - size += nr_node_ids * sizeof(struct mem_cgroup_per_node *); - - memcg = kzalloc(size, GFP_KERNEL); + memcg = kzalloc(struct_size(memcg, nodeinfo, nr_node_ids), GFP_KERNEL); if (!memcg) return ERR_PTR(error); _ Patches currently in -mm which might be from wangweiyang2@xxxxxxxxxx are mm-memcg-use-struct_size-helper-in-kzalloc.patch