Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21406900ybl; Mon, 6 Jan 2020 04:04:56 -0800 (PST) X-Google-Smtp-Source: APXvYqy7RhG+gR38lGiTOlq2k4PXl22ausdUp5G9soD3NCWfCYR6TY3NUjc3bcYU9rJnpG16Cjsx X-Received: by 2002:aca:59c2:: with SMTP id n185mr5457745oib.170.1578312296727; Mon, 06 Jan 2020 04:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578312296; cv=none; d=google.com; s=arc-20160816; b=pkDJNCdDGtDnPh9DUDzJKzmVmY6BayyOCKadmw1mwo+OEKRT6dq2wqYMuof5GJpeVg lgSJok1j/1YGGSQOMtukRZMaDZyusCxirmP8WcArxXAB5vDO89Xb4Y9tCS1ULzvMmGEL yWNGcVL8ZxehzVl0LO3yqwcz3y2ZfXXITxTC0x6QkKmctGyEjWvYqKBHJ26kOnhUiV7I 7mjdLD+00TY/VO8uXRfEfxcK3JSZ/16U0m9p+3Y7xwAOjAyj2EZ7vXgwfNyXF6XJt7EH GzWDQaTI2Wpudd14g9SFrOgmYIg+OPgZX4/DeDX0op3yaIc9jS1Xodj1PDW9sESj1qYD MGzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=yukhhpns1w7BeaFqWo0b0xMzei9SoH/3AUHtLIruKmM=; b=qDRcY3/+ytGj5fM/pC7HgreWuC+unyzETA28wnEa0gGrvYdxvjpDolIpaq1Ed5hxFs g46id1fyXoz4/ylT/MO3Rs7+PhM+xqdNRaYJjowwRY+ctbXyw9OP2ej0nlZXYnp2CZ1r JT3++N6yKPZQLKSmny7pGeLOBLdsDgwwIUPb0yWrRMTNTwIPKQ3dOxgJIHAtdehYNjPQ EaWONxxO2TG61KdBcwVpC5FIu+AW9EdIA3WuZmW4LXywmZOv7pO/4y+7Dh/5rOzmufpG FgBm2N/0urJBI5an5CNM/Ge0BS64Tfa53t5plEEQCg1Swy/z92L3mNUAiC8NmZfuaUWB i/Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y18si24466243oix.27.2020.01.06.04.04.43; Mon, 06 Jan 2020 04:04:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgAFMDn (ORCPT + 99 others); Mon, 6 Jan 2020 07:03:43 -0500 Received: from foss.arm.com ([217.140.110.172]:43360 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbgAFMDn (ORCPT ); Mon, 6 Jan 2020 07:03:43 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6ABCC328; Mon, 6 Jan 2020 04:03:42 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 515583F534; Mon, 6 Jan 2020 04:03:41 -0800 (PST) Date: Mon, 6 Jan 2020 12:03:39 +0000 From: Mark Rutland To: Vince Weaver , Alexander Shishkin , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim Subject: [PATCH] perf: correctly handle failed perf_get_aux_event() (was: Re: [perf] perf_event_open() sometimes returning 0) Message-ID: <20200106120338.GC9630@lakrids.cambridge.arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 02, 2020 at 02:22:47PM -0500, Vince Weaver wrote: > On Thu, 2 Jan 2020, Vince Weaver wrote: > > > so I was tracking down some odd behavior in the perf_fuzzer which turns > > out to be because perf_even_open() sometimes returns 0 (indicating a file > > descriptor of 0) even though as far as I can tell stdin is still open. Yikes. > error is triggered if aux_sample_size has non-zero value. > > seems to be this line in kernel/events/core.c: > > > if (perf_need_aux_event(event) && !perf_get_aux_event(event, group_leader)) > goto err_locked; > > > (note, err is never set) Looks like that was introduced in commit: ab43762ef010967e ("perf: Allow normal events to output AUX data") I guess we should return -EINVAL in this case. Vince, does the below (untested) patch work for you? Thanks, Mark. ---->8---- From c79f31b42aaf85f3a924af9218794b3bc8b79892 Mon Sep 17 00:00:00 2001 From: Mark Rutland Date: Mon, 6 Jan 2020 11:51:06 +0000 Subject: [PATCH] perf: correctly handle failed perf_get_aux_event() Vince reports a worrying issue: | so I was tracking down some odd behavior in the perf_fuzzer which turns | out to be because perf_even_open() sometimes returns 0 (indicating a file | descriptor of 0) even though as far as I can tell stdin is still open. ... and further the cause: | error is triggered if aux_sample_size has non-zero value. | | seems to be this line in kernel/events/core.c: | | if (perf_need_aux_event(event) && !perf_get_aux_event(event, group_leader)) | goto err_locked; | | (note, err is never set) This seems to be a thinko in commit: ab43762ef010967e ("perf: Allow normal events to output AUX data") ... and we should probably return -EINVAL here, as this should only happen when the new event is mis-configured or does not have a compatible aux_event group leader. Fixes: ab43762ef010967e ("perf: Allow normal events to output AUX data") Reported-by: Vince Weaver Signed-off-by: Mark Rutland Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Alexander Shishkin --- kernel/events/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index a1f8bde19b56..2173c23c25b4 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11465,8 +11465,10 @@ SYSCALL_DEFINE5(perf_event_open, } } - if (perf_need_aux_event(event) && !perf_get_aux_event(event, group_leader)) + if (perf_need_aux_event(event) && !perf_get_aux_event(event, group_leader)) { + err = -EINVAL; goto err_locked; + } /* * Must be under the same ctx::mutex as perf_install_in_context(), -- 2.11.0