From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752817AbdCNNrY (ORCPT ); Tue, 14 Mar 2017 09:47:24 -0400 Received: from merlin.infradead.org ([205.233.59.134]:57354 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750780AbdCNNrV (ORCPT ); Tue, 14 Mar 2017 09:47:21 -0400 Date: Tue, 14 Mar 2017 14:47:15 +0100 From: Peter Zijlstra To: Oleg Nesterov Cc: Dmitry Vyukov , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , LKML , Mathieu Desnoyers , syzkaller Subject: Re: perf: use-after-free in perf_release Message-ID: <20170314134715.GF3328@twins.programming.kicks-ass.net> References: <20170306131459.GC6515@twins.programming.kicks-ass.net> <20170307140414.GA31678@redhat.com> <20170307165131.GA6097@redhat.com> <20170314125508.GK3343@twins.programming.kicks-ass.net> <20170314132427.GA27369@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170314132427.GA27369@redhat.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 14, 2017 at 02:24:27PM +0100, Oleg Nesterov wrote: > On 03/14, Peter Zijlstra wrote: > > > > On Tue, Mar 07, 2017 at 05:51:32PM +0100, Oleg Nesterov wrote: > > > > > inherit_event() returns NULL under is_orphaned_event() check, not ERR_PTR(). > > > Is it correct? > > > > Yes. This is all a tad tricky, but it seems to be correct. > > > > By returning NULL, not an error, we affect the silent discard of > > orphaned events. This is correct, because otherwise > > perf_event_release_kernel() would have come by and explicitly discarded > > those events for us anyway. > > Thanks... I'll try to understand this later. > > > @@ -10608,7 +10627,6 @@ inherit_task_group(struct perf_event *event, struct task_struct *parent, > > * First allocate and initialize a context for the > > * child. > > */ > > - > > child_ctx = alloc_perf_context(parent_ctx->pmu, child); > > if (!child_ctx) > > return -ENOMEM; > > @@ -10670,7 +10688,7 @@ static int perf_event_init_context(struct task_struct *child, int ctxn) > > ret = inherit_task_group(event, parent, parent_ctx, > > child, ctxn, &inherited_all); > > if (ret) > > - break; > > + goto out_unlock; > > } > > > > /* > > @@ -10686,7 +10704,7 @@ static int perf_event_init_context(struct task_struct *child, int ctxn) > > ret = inherit_task_group(event, parent, parent_ctx, > > child, ctxn, &inherited_all); > > if (ret) > > - break; > > + goto out_unlock; > > With this change you can also simplify inherit_task_group() a little bit, > it no longer needs to nullify *inherited_all if inherit_group() fails. Ah, that last one is broken because then we forget to re-enable parent_ctx->rotate_disable. So if we keep that a break, we still need that inherited_all thing as well.