public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steve Wise <swise@opengridcomputing.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: trivial@kernel.org, zygo.blaxell@xandros.com,
	linux-kernel@vger.kernel.org,
	Jes Sorensen <jes@trained-monkey.org>
Subject: Re: [PATCH] LIB: remove unmatched write_lock() in gen_pool_destroy
Date: Mon, 15 Jun 2009 19:27:30 -0500	[thread overview]
Message-ID: <4A36E6F2.5050708@opengridcomputing.com> (raw)
In-Reply-To: <20090615155424.14ad5c6a.akpm@linux-foundation.org>

Andrew Morton wrote:
> On Mon, 15 Jun 2009 17:30:32 -0500
> Steve Wise <swise@opengridcomputing.com> wrote:
>
>   
>> Andrew Morton wrote:
>>     
>>> On Mon, 15 Jun 2009 23:35:31 +0200 (CEST)
>>> Jiri Kosina <trivial@kernel.org> wrote:
>>>
>>>   
>>>       
>>>>> -	write_lock(&pool->lock);
>>>>>  	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
>>>>>  		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
>>>>>  		list_del(&chunk->next_chunk);
>>>>> -- 
>>>>> 1.5.6.5
>>>>>
>>>>>       
>>>>>           
>>>> Hi Zygo,
>>>>
>>>> this doesn't really qualify for trivial tree, as it introduces a 
>>>> significant code change. Adding some CCs.
>>>>     
>>>>         
>>> yep, I merged it, thanks.
>>>
>>> I wonder why drivers/infiniband/hw/cxgb3 users never noticed this.
>>>   
>>>       
>> I seem to remember trying to get this removed a few years ago and the 
>> owner didn't want it removed...
>>
>>     
>
> void gen_pool_destroy(struct gen_pool *pool)
> {
> 	struct list_head *_chunk, *_next_chunk;
> 	struct gen_pool_chunk *chunk;
> 	int order = pool->min_alloc_order;
> 	int bit, end_bit;
>
>
> 	write_lock(&pool->lock);
> 	list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
> 		chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
> 		list_del(&chunk->next_chunk);
>
> 		end_bit = (chunk->end_addr - chunk->start_addr) >> order;
> 		bit = find_next_bit(chunk->bits, end_bit, 0);
> 		BUG_ON(bit < end_bit);
>
> 		kfree(chunk);
> 	}
> 	kfree(pool);
> 	return;
> }
>
> The write_lock is unneeded and wrong.  Because if any other thread of
> control is concurrently playing with this pool, it will sometimes do a
> use-after-free.
>
> So no other thread of control should have access to this pool, so
> there's no need for the write_lock().
>   

Yup. 

My original patch adding gen_pool_destroy() didn't have the 
write_lock().  It was added as part of "reviewing" the patch. :)

Steve.


      reply	other threads:[~2009-06-16  0:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-12 17:37 [PATCH] LIB: remove unmatched write_lock() in gen_pool_destroy Zygo Blaxell
2009-06-15 21:35 ` Jiri Kosina
2009-06-15 22:04   ` Steve Wise
2009-06-15 22:29     ` Andrew Morton
2009-06-16  8:23       ` Jiri Kosina
2009-06-16  8:35         ` Andrew Morton
2009-06-15 22:26   ` Andrew Morton
2009-06-15 22:30     ` Steve Wise
2009-06-15 22:54       ` Andrew Morton
2009-06-16  0:27         ` Steve Wise [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A36E6F2.5050708@opengridcomputing.com \
    --to=swise@opengridcomputing.com \
    --cc=akpm@linux-foundation.org \
    --cc=jes@trained-monkey.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=trivial@kernel.org \
    --cc=zygo.blaxell@xandros.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox