lkml.org 
[lkml]   [2013]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH] devres: Freeing the drs after all release() are called
Date
Hello Greg,

> -----Original Message-----
> From: Greg KH [mailto:gregkh@linuxfoundation.org]
> Sent: Wednesday, November 06, 2013 4:59 PM
> To: Liu, Chuansheng
> Cc: dmitry.torokhov@gmail.com; tj@kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] devres: Freeing the drs after all release() are called
>
> On Wed, Nov 06, 2013 at 02:40:18PM +0800, Chuansheng Liu wrote:
> >
> > In release_nodes(), it will call dr->node.release() and kfree
> > dr one by one.
> >
> > But sometimes the previous dr maybe be used by next .release(),
> > such as:
> > [50314.855534] [<c12b172f>] ? synchronize_irq+0x3f/0xb0
> > [50314.861193] [<c12b18e9>] __free_irq+0x149/0x200
> > [50314.866367] [<c12b19e3>] free_irq+0x43/0xa0
> > [50314.871152] [<c12b4864>] devm_irq_release+0x14/0x20
> > [50314.876713] [<c169e806>] release_nodes+0x136/0x1b0
> > [50314.882178] [<c169ee79>] devres_release_all+0x39/0x60
> > [50314.887935] [<c169b411>] __device_release_driver+0x71/0xd0
> >
> > the free_irq() will sync the last irq handling, which maybe use
> > freed dr, then it will cause memory corruption.
> >
> > Here split the dr kfreeing actions after all dr->node.release().
>
> But you aren't really solving any problems here, how is dr being used
> after the release function is called? Who is doing it in such a way
> that this change would really fix anything?
>
The driver code is as below:
_INIT() {

A = devm_kzalloc();
B= devm_request_threaded_irq(isr_handler);
C = devm_kzalloc();
}

When driver _EXIT, the devres_release_all () will be called.
The C will be kfreed before B, but when freeing irq B, the pending isr_handler() possibly
will access the memory B which has been freed.
Then the memory corruption occurred.

This patch can solve this scenario.
Thanks.





\
 
 \ /
  Last update: 2013-11-07 02:01    [W:0.064 / U:2.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site