linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] memcg: null dereference on allocation failure
@ 2010-10-28 11:12 Dan Carpenter
  2010-10-28 15:52 ` Balbir Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-10-28 11:12 UTC (permalink / raw)
  To: Balbir Singh
  Cc: Daisuke Nishimura, KAMEZAWA Hiroyuki, linux-mm, linux-kernel,
	kernel-janitors

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

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 9a99cfa..2efa8ea 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4208,15 +4208,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 	memset(mem, 0, size);
 	mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
-	if (!mem->stat) {
-		if (size < PAGE_SIZE)
-			kfree(mem);
-		else
-			vfree(mem);
-		mem = NULL;
-	}
+	if (!mem->stat)
+		goto out_free;
 	spin_lock_init(&mem->pcp_counter_lock);
 	return mem;
+
+out_free:
+	if (size < PAGE_SIZE)
+		kfree(mem);
+	else
+		vfree(mem);
+	return NULL;
 }
 
 /*

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] memcg: null dereference on allocation failure
  2010-10-28 11:12 [patch] memcg: null dereference on allocation failure Dan Carpenter
@ 2010-10-28 15:52 ` Balbir Singh
  2010-10-28 23:39 ` KAMEZAWA Hiroyuki
  2010-10-29  0:38 ` Daisuke Nishimura
  2 siblings, 0 replies; 4+ messages in thread
From: Balbir Singh @ 2010-10-28 15:52 UTC (permalink / raw)
  To: Dan Carpenter, Daisuke Nishimura, KAMEZAWA Hiroyuki, linux-mm,
	linux-kernel, kernel-janitors

* Dan Carpenter <error27@gmail.com> [2010-10-28 13:12:41]:

> The original code had a null dereference if alloc_percpu() failed.
> This was introduced in 711d3d2c9bc3 "memcg: cpu hotplug aware percpu
> count updates"
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 9a99cfa..2efa8ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4208,15 +4208,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
> 
>  	memset(mem, 0, size);
>  	mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
> -	if (!mem->stat) {
> -		if (size < PAGE_SIZE)
> -			kfree(mem);
> -		else
> -			vfree(mem);
> -		mem = NULL;
> -	}
> +	if (!mem->stat)
> +		goto out_free;
>  	spin_lock_init(&mem->pcp_counter_lock);
>  	return mem;
> +
> +out_free:
> +	if (size < PAGE_SIZE)
> +		kfree(mem);
> +	else
> +		vfree(mem);
> +	return NULL;
>  }

Good catch!
Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com>
 

-- 
	Three Cheers,
	Balbir

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] memcg: null dereference on allocation failure
  2010-10-28 11:12 [patch] memcg: null dereference on allocation failure Dan Carpenter
  2010-10-28 15:52 ` Balbir Singh
@ 2010-10-28 23:39 ` KAMEZAWA Hiroyuki
  2010-10-29  0:38 ` Daisuke Nishimura
  2 siblings, 0 replies; 4+ messages in thread
From: KAMEZAWA Hiroyuki @ 2010-10-28 23:39 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Balbir Singh, Daisuke Nishimura, linux-mm, linux-kernel, kernel-janitors

On Thu, 28 Oct 2010 13:12:41 +0200
Dan Carpenter <error27@gmail.com> wrote:

> The original code had a null dereference if alloc_percpu() failed.
> This was introduced in 711d3d2c9bc3 "memcg: cpu hotplug aware percpu
> count updates"
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>


Ah, my fault. Thank you for catching.

Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] memcg: null dereference on allocation failure
  2010-10-28 11:12 [patch] memcg: null dereference on allocation failure Dan Carpenter
  2010-10-28 15:52 ` Balbir Singh
  2010-10-28 23:39 ` KAMEZAWA Hiroyuki
@ 2010-10-29  0:38 ` Daisuke Nishimura
  2 siblings, 0 replies; 4+ messages in thread
From: Daisuke Nishimura @ 2010-10-29  0:38 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Andrew Morton, Balbir Singh, KAMEZAWA Hiroyuki, linux-mm,
	linux-kernel, kernel-janitors, Daisuke Nishimura

(I add Andrew to CC-list)

On Thu, 28 Oct 2010 13:12:41 +0200
Dan Carpenter <error27@gmail.com> wrote:

> The original code had a null dereference if alloc_percpu() failed.
> This was introduced in 711d3d2c9bc3 "memcg: cpu hotplug aware percpu
> count updates"
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 

Acked-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 9a99cfa..2efa8ea 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4208,15 +4208,17 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
>  
>  	memset(mem, 0, size);
>  	mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
> -	if (!mem->stat) {
> -		if (size < PAGE_SIZE)
> -			kfree(mem);
> -		else
> -			vfree(mem);
> -		mem = NULL;
> -	}
> +	if (!mem->stat)
> +		goto out_free;
>  	spin_lock_init(&mem->pcp_counter_lock);
>  	return mem;
> +
> +out_free:
> +	if (size < PAGE_SIZE)
> +		kfree(mem);
> +	else
> +		vfree(mem);
> +	return NULL;
>  }
>  
>  /*

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-10-29  0:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28 11:12 [patch] memcg: null dereference on allocation failure Dan Carpenter
2010-10-28 15:52 ` Balbir Singh
2010-10-28 23:39 ` KAMEZAWA Hiroyuki
2010-10-29  0:38 ` Daisuke Nishimura

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox