diff options
author | Wang Weiyang <[email protected]> | 2022-01-14 14:05:42 -0800 |
---|---|---|
committer | Linus Torvalds <[email protected]> | 2022-01-15 16:30:27 +0200 |
commit | 06b2c3b08ce134c9555d91a1cf15cd03646cc287 (patch) | |
tree | 8efe1c53e245236a200f076b8c0dbdb1680b171b | |
parent | 5b3be698a872c490dbed524f3e2463701ab21339 (diff) |
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/[email protected]
Signed-off-by: Wang Weiyang <[email protected]>
Reviewed-by: Muchun Song <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r-- | mm/memcontrol.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index aa2a15298636..88e1be912aa7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5122,15 +5122,11 @@ static void mem_cgroup_free(struct mem_cgroup *memcg) 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); |