From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752266AbdCNN00 (ORCPT ); Tue, 14 Mar 2017 09:26:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56568 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752177AbdCNN0X (ORCPT ); Tue, 14 Mar 2017 09:26:23 -0400 Date: Tue, 14 Mar 2017 14:24:27 +0100 From: Oleg Nesterov To: Peter Zijlstra 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: <20170314132427.GA27369@redhat.com> References: <20170306131459.GC6515@twins.programming.kicks-ass.net> <20170307140414.GA31678@redhat.com> <20170307165131.GA6097@redhat.com> <20170314125508.GK3343@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170314125508.GK3343@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 14 Mar 2017 13:26:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Oleg.