Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1160958

Re: [PATCH] zsmalloc: fix a null pointer dereference in destroy_handle_cache()

From Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] zsmalloc: fix a null pointer dereference in destroy_handle_cache()
Date 2015-06-09 06:00 +0200
Message-ID <pziRI-34C-7@gated-at.bofh.it> (permalink)
References <pxXPj-6Ru-9@gated-at.bofh.it> <pzcjg-1MZ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On (06/08/15 13:55), Andrew Morton wrote:
[..]
> > zs_destroy_pool()->destroy_handle_cache() invoked from
> > zs_create_pool() can pass a NULL ->handle_cachep pointer
> > to kmem_cache_destroy(), which will dereference it.
> >
> 
> That's slightly lacking in details (under what circumstances will it
> crash) so I changed it to
> 
> : If zs_create_pool()->create_handle_cache()->kmem_cache_create() fails,
> : zs_create_pool()->destroy_handle_cache() will dereference the NULL
> : pool->handle_cachep.
> :
> : Modify destroy_handle_cache() to avoid this.
> 

Oh, sorry I first received "+ zsmalloc-fix-a-null-pointer-dereference-in-
destroy_handle_cache.patch added to -mm tree" message, so I replied
there. fetchmail works somewhat confusing over the last weeks.

> > ...
> >
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -285,7 +285,8 @@ static int create_handle_cache(struct zs_pool *pool)
> >  
> >  static void destroy_handle_cache(struct zs_pool *pool)
> >  {
> > -	kmem_cache_destroy(pool->handle_cachep);
> > +	if (pool->handle_cachep)
> > +		kmem_cache_destroy(pool->handle_cachep);
> >  }
> >  
> >  static unsigned long alloc_handle(struct zs_pool *pool)
> 
> I'll apply this, but...  from a bit of grepping I'm estimating that we
> have approximately 200 instances of
> 
> 	if (foo)
> 		kmem_cache_destroy(foo);
> 
> so obviously kmem_cache_destroy() should be doing the check.

Yes, I thought about this.

A naive grepping gave me 563 occurrences

 git grep kmem_cache_destroy | wc -l
 563

So I decided to hold this activity. Well, I think I can create this
patch bomb, it's trivial.

	-ss
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH] zsmalloc: fix a null pointer dereference in  destroy_handle_cache() Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-06-09 06:00 +0200

csiph-web