Re: perf: use after free in perf_remove_from_context
From: Sasha Levin
Date: Thu May 29 2014 - 18:38:20 EST
On 05/29/2014 01:00 PM, Peter Zijlstra wrote:
> On Thu, May 29, 2014 at 06:50:57PM +0200, Peter Zijlstra wrote:
>> > On Thu, May 29, 2014 at 12:44:23PM -0400, Sasha Levin wrote:
>>> > > On 05/29/2014 11:07 AM, Peter Zijlstra wrote:
>>>> > > > On Thu, May 29, 2014 at 10:47:09AM -0400, Sasha Levin wrote:
>>>>> > > >> It doesn't work out well because we later lock a mutex in sync_child_event().
>>>>> > > >>
>>>> > > >
>>>> > > > Urgh, right you are. I'll go stare at it more. It shouldn't have
>>>> > > > mattered, because the mutex we take just before should ensure existence,
>>>> > > > but.. you know.. :-)
>>>> > > >
>>> > >
>>> > > So the only caller to sync_child_event() is that loop. According to what you said
>>> > > it should be safe to remove that mutex lock, but doing that triggers a list
>>> > > corruption:
>>> > >
>>> > > [ 1204.341887] WARNING: CPU: 20 PID: 12839 at lib/list_debug.c:62 __list_del_entry+0xa1/0xe0()
>>> > > [ 1204.347597] list_del corruption. next->prev should be ffff8806ca68b108, but was ffff88051a67c398
>>> > > [...]
>>> > >
>>> > > I don't see how that would happen :/
>> >
>> > No, what I said is that the mutex in perf_event_exit_task() should be
>> > sufficient to guard the list iteration calling __perf_event_exit_task().
>> >
>> > Ading the RCU was a bit of paranoia..
> Hmm, so can you try this..
>
> While that mutex should guard the elements, it doesn't guard against the
> use-after-free that's from list_for_each_entry_rcu().
> __perf_event_exit_task() can actually free the event.
>
> And because list addition/deletion is guarded by both ctx->mutex and
> ctx->lock, holding ctx->mutex is sufficient for reading the list, so we
> don't actually need the rcu list iteration.
Works for me, thanks!
Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/