lkml.org 
[lkml]   [2014]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Memory allocator semantics
From
On Tue, Feb 11, 2014 at 2:14 PM, Paul E. McKenney
<paulmck@linux.vnet.ibm.com> wrote:
> In contrast, from kfree() to a kmalloc() returning some of the kfree()ed
> memory, I believe the kfree()/kmalloc() implementation must do any needed
> synchronization and ordering. But that is a different set of examples,
> for example, this one:
>
> CPU 0 CPU 1
> p->a = 42; q = kmalloc(...); /* returning p */
> kfree(p); q->a = 5;
> BUG_ON(q->a != 5);
>
> Unlike the situation with (A), (B), and (C), in this case I believe
> that it is kfree()'s and kmalloc()'s responsibility to ensure that
> the BUG_ON() never triggers.
>
> Make sense?

I'm not sure...

It's the caller's responsibility not to touch "p" after it's handed over to
kfree() - otherwise that's a "use-after-free" error. If there's some reordering
going on here, I'm tempted to blame the caller for lack of locking.

Pekka


\
 
 \ /
  Last update: 2014-02-11 14:41    [W:0.282 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site