linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* slob: Check for NULL pointer before calling ctor()
@ 2013-01-17 17:13 Steven Rostedt
  2013-01-17 17:54 ` [PATCH] " Steven Rostedt
  2013-02-05 14:16 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Steven Rostedt @ 2013-01-17 17:13 UTC (permalink / raw)
  To: LKML, linux-mm
  Cc: Andrew Morton, Christoph Lameter, Pekka Enberg, Matt Mackall

[ Sorry for the duplicate email, it's linux-mm@kvack.org not linux-mm@vger.kernel.org ] 

While doing some code inspection, I noticed that the slob constructor
method can be called with a NULL pointer. If memory is tight and slob
fails to allocate with slob_alloc() or slob_new_pages() it still calls
the ctor() method with a NULL pointer. Looking at the first ctor()
method I found, I noticed that it can not handle a NULL pointer (I'm
sure others probably can't either):

static void sighand_ctor(void *data)
{
        struct sighand_struct *sighand = data;

        spin_lock_init(&sighand->siglock);
        init_waitqueue_head(&sighand->signalfd_wqh);
}

The solution is to only call the ctor() method if allocation succeeded.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/mm/slob.c b/mm/slob.c
index a99fdf7..48fcb90 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -554,7 +554,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
 					    flags, node);
 	}
 
-	if (c->ctor)
+	if (b && c->ctor)
 		c->ctor(b);
 
 	kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);



--
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 related	[flat|nested] 5+ messages in thread

* [PATCH] slob: Check for NULL pointer before calling ctor()
  2013-01-17 17:13 slob: Check for NULL pointer before calling ctor() Steven Rostedt
@ 2013-01-17 17:54 ` Steven Rostedt
  2013-02-05 14:16 ` Steven Rostedt
  1 sibling, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2013-01-17 17:54 UTC (permalink / raw)
  To: LKML; +Cc: linux-mm, Andrew Morton, Christoph Lameter, Pekka Enberg,
	Matt Mackall

I'm not doing so well. I forgot to add [PATCH] to the subject.

Having all these scripts to push out patches in my normal work flow, has
made me incompetent in sending out patches manually. :-(

-- Steve


--
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] 5+ messages in thread

* Re: [PATCH] slob: Check for NULL pointer before calling ctor()
  2013-01-17 17:13 slob: Check for NULL pointer before calling ctor() Steven Rostedt
  2013-01-17 17:54 ` [PATCH] " Steven Rostedt
@ 2013-02-05 14:16 ` Steven Rostedt
  2013-02-05 14:58   ` Christoph Lameter
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2013-02-05 14:16 UTC (permalink / raw)
  To: LKML; +Cc: linux-mm, Andrew Morton, Christoph Lameter, Pekka Enberg,
	Matt Mackall

Ping?

-- Steve


On Thu, 2013-01-17 at 12:13 -0500, Steven Rostedt wrote:
> [ Sorry for the duplicate email, it's linux-mm@kvack.org not linux-mm@vger.kernel.org ] 
> 
> While doing some code inspection, I noticed that the slob constructor
> method can be called with a NULL pointer. If memory is tight and slob
> fails to allocate with slob_alloc() or slob_new_pages() it still calls
> the ctor() method with a NULL pointer. Looking at the first ctor()
> method I found, I noticed that it can not handle a NULL pointer (I'm
> sure others probably can't either):
> 
> static void sighand_ctor(void *data)
> {
>         struct sighand_struct *sighand = data;
> 
>         spin_lock_init(&sighand->siglock);
>         init_waitqueue_head(&sighand->signalfd_wqh);
> }
> 
> The solution is to only call the ctor() method if allocation succeeded.
> 
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> 
> diff --git a/mm/slob.c b/mm/slob.c
> index a99fdf7..48fcb90 100644
> --- a/mm/slob.c
> +++ b/mm/slob.c
> @@ -554,7 +554,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
>  					    flags, node);
>  	}
>  
> -	if (c->ctor)
> +	if (b && c->ctor)
>  		c->ctor(b);
>  
>  	kmemleak_alloc_recursive(b, c->size, 1, c->flags, flags);
> 
> 


--
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] 5+ messages in thread

* Re: [PATCH] slob: Check for NULL pointer before calling ctor()
  2013-02-05 14:16 ` Steven Rostedt
@ 2013-02-05 14:58   ` Christoph Lameter
  2013-07-07 16:19     ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Lameter @ 2013-02-05 14:58 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, linux-mm, Andrew Morton, Pekka Enberg, Matt Mackall

On Tue, 5 Feb 2013, Steven Rostedt wrote:

> Ping?

Obviously correct.

Acked-by: Christoph Lameter <cl@linux.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] 5+ messages in thread

* Re: [PATCH] slob: Check for NULL pointer before calling ctor()
  2013-02-05 14:58   ` Christoph Lameter
@ 2013-07-07 16:19     ` Pekka Enberg
  0 siblings, 0 replies; 5+ messages in thread
From: Pekka Enberg @ 2013-07-07 16:19 UTC (permalink / raw)
  To: Christoph Lameter
  Cc: Steven Rostedt, LKML, linux-mm, Andrew Morton, Matt Mackall

On 2/5/13 4:58 PM, Christoph Lameter wrote:
> On Tue, 5 Feb 2013, Steven Rostedt wrote:
>
>> Ping?
>
> Obviously correct.
>
> Acked-by: Christoph Lameter <cl@linux.com>

Applied, thanks a lot!

--
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] 5+ messages in thread

end of thread, other threads:[~2013-07-07 16:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-17 17:13 slob: Check for NULL pointer before calling ctor() Steven Rostedt
2013-01-17 17:54 ` [PATCH] " Steven Rostedt
2013-02-05 14:16 ` Steven Rostedt
2013-02-05 14:58   ` Christoph Lameter
2013-07-07 16:19     ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).