Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memcg: null dereference on allocation failure

The original code had a null dereference if alloc_percpu() failed. This
was introduced in commit 711d3d2c9bc3 ("memcg: cpu hotplug aware percpu
count updates")

Signed-off-by: Dan Carpenter <error27@gmail.com>
Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dan Carpenter and committed by
Linus Torvalds
d2e61b8d 1093736b

+9 -7
+9 -7
mm/memcontrol.c
··· 4208 4208 4209 4209 memset(mem, 0, size); 4210 4210 mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); 4211 - if (!mem->stat) { 4212 - if (size < PAGE_SIZE) 4213 - kfree(mem); 4214 - else 4215 - vfree(mem); 4216 - mem = NULL; 4217 - } 4211 + if (!mem->stat) 4212 + goto out_free; 4218 4213 spin_lock_init(&mem->pcp_counter_lock); 4219 4214 return mem; 4215 + 4216 + out_free: 4217 + if (size < PAGE_SIZE) 4218 + kfree(mem); 4219 + else 4220 + vfree(mem); 4221 + return NULL; 4220 4222 } 4221 4223 4222 4224 /*