Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp751252ybl; Sat, 18 Jan 2020 10:06:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxCxJIBq/HLbU/heqGA5xzRLLI6PihvKQR81kP6DG9pxVlshxleRE3ZbAVFEo26tnw04jJq X-Received: by 2002:a9d:7593:: with SMTP id s19mr10001193otk.219.1579370808327; Sat, 18 Jan 2020 10:06:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579370808; cv=none; d=google.com; s=arc-20160816; b=tq1rL7SLHXRZ7hyt6DGKCjodCiSr7mNJG8kt0JBCjH9iQADuBqnpFRCyZrLeBD8Kr7 iP9Hyx9jawxu+Kt2Ru3W/cHIV8c+nRiNLlYd7PugeB0ZazYfMlEI4zAVIv8c5qcZFlfD EK2b/E+1hpgVO61DxWj4N700NU86cRAuJ2vPo9lFhnQ5y3EiT1T1R0QIjasCypeU8F+e PXtqTSSgvfD9mvgLFLD5OTp9BwmufkwDI6nJo3EKzdPbt6K4XVm7eW2A15scERD7U042 Qwhz++FxUvqzA8cUH895ifkO2h2DmFrYn8/g/1bRov9UV+SiiSaTc9EK4d1XeW9mU+LB 801Q== 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:dkim-signature; bh=jd8LOECtGgkjQMzMELux70cWFLm7vLIXL4uMj5c+Mc4=; b=nDAcijLnHK4EUwd9decYHWRGg/1mTDf263574fJe2OFlYxhnw9j6Zoalf5JC0cq7oS 6rpOXDqxkqgeWidyZ1ElgrlV79qZcH4gJOuQfuQLqkkyWb4As/9PiCywXCJuYr+mpG42 llHXEYD4S0g3JiEdpwDJ5KFTgah0WKXdoenBoDiazWWEx38+BAbtGugdQPTBZ8hX+rK9 LZhaw2K8mya2ZxvN70Z5XuOeZwEGBreY7Fw23sjKU9YrmQt5F5ufFH4oTncmhOw6laSE 3h7jK+onhCbKiXYvPDBES2KfoiLUzmliUSMc/lreaaJGDBCHYD+/6PJfftnrVL6XEOY9 SdZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ppRY61cl; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m90si17026444otc.259.2020.01.18.10.06.34; Sat, 18 Jan 2020 10:06:48 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ppRY61cl; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbgARSFe (ORCPT + 99 others); Sat, 18 Jan 2020 13:05:34 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50843 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726490AbgARSFe (ORCPT ); Sat, 18 Jan 2020 13:05:34 -0500 Received: by mail-wm1-f65.google.com with SMTP id a5so10471436wmb.0; Sat, 18 Jan 2020 10:05:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jd8LOECtGgkjQMzMELux70cWFLm7vLIXL4uMj5c+Mc4=; b=ppRY61cluOh/i7kCa+pc0aMlJG19WXrLn2uCj6i+5EZVSAF6ZLoXNZcXUrDyjKOGFz 166xcAlAeR7kqtUslev2cUmUa8m8JUYidG1OMCEPi23dhmWMKSJW1kneupbMv0xSiwk3 fULR8JHaIuedXStAENnQ06JcCrsSf+mDPfNpYsIVuB32EmJkQQ6AHJLsQRKXiwLWd09Z 8Bu0Piw3OS5xZ0ZflhV2d1syR8QMmHlu8JxW+zIeTRJZ9amLpzouiABWf9oMCaO8zP6c s9hqOSkf9MCFRIuOkJNDfHvJ11gTdin0JifzToRmOOaEWIFeDPH/fucm0uhHP/M7Peb2 Xo6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=jd8LOECtGgkjQMzMELux70cWFLm7vLIXL4uMj5c+Mc4=; b=fFQRCXFTDs3e4Y1MxvOSDgdS7bYpv5+lgfiwmsUWJu7YWycP353b2ysBJ/F0PKiGlJ WDIZA/hXw8SkkfC/CnHzWfUYFR8nAMxgPU446bwphjrS/r8+2dslROFmODaZXvxo4SGt hGLanWsZYw0IjPg8nsyD1VLYXfh/35+NPDwdnEv12dnYHyHznJUlNQllsNPecCGbZldY g1YE6lm44RNE0h7cFf+33FgRfWwZ6NnLxXZjNrGb5U6dcuhcujgorKNwBnnJ3ulz4FHf n02cuOWzy/OUZBgmpJz4Cd9BOeuGJGJRUB+AAV8QMra0ON/nVFG4LRyDUPRuC8GDIhba eXAA== X-Gm-Message-State: APjAAAVsg5jbLChs1ELvXpHdTQ1gf92fzV4ENHOp87IeLEr+mF8FB0cB fMmN5iOjRBwaTtxwS12b+9Q= X-Received: by 2002:a7b:c389:: with SMTP id s9mr10277060wmj.7.1579370731944; Sat, 18 Jan 2020 10:05:31 -0800 (PST) Received: from gmail.com (54033286.catv.pool.telekom.hu. [84.3.50.134]) by smtp.gmail.com with ESMTPSA id m10sm39740892wrx.19.2020.01.18.10.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jan 2020 10:05:31 -0800 (PST) Date: Sat, 18 Jan 2020 19:05:29 +0100 From: Ingo Molnar To: Vince Weaver Cc: Mark Rutland , Alexander Shishkin , Peter Zijlstra , linux-kernel@vger.kernel.org, Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Greg Kroah-Hartman , stable kernel team Subject: [PATCH, v5.4] perf: Correctly handle failed perf_get_aux_event() Message-ID: <20200118180529.GA70028@gmail.com> References: <20200106120338.GC9630@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Vince Weaver wrote: > On Mon, 6 Jan 2020, Vince Weaver wrote: > > > On Mon, 6 Jan 2020, Mark Rutland wrote: > > > > > On Thu, Jan 02, 2020 at 02:22:47PM -0500, Vince Weaver wrote: > > > > On Thu, 2 Jan 2020, Vince Weaver wrote: > > > > > > > Vince, does the below (untested) patch work for you? > > > > > > yes, this patch fixes things for me. > > > > Tested-by: Vince Weaver > > > > is this patch going to make it upstream? It's a fairly major correctness > bug with perf_event_open(). I just sent it to Linus. In hindsight this should have been marked Cc: stable for v5.4 - we should forward it to Greg once Linus has pulled it: da9ec3d3dd0f: ("perf: Correctly handle failed perf_get_aux_event()") Note that in the v5.4 cherry-pick there's a conflict due to interaction with another recent commit - I've attached the ported fix against v5.4, but have only test built it. Thanks, Ingo ==============> From 703595681c934d2a88a91e8a41f7f63eeb1573e0 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Sat, 18 Jan 2020 19:03:55 +0100 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 Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Acked-by: Alexander Shishkin Tested-by: Vince Weaver (cherry picked from commit da9ec3d3dd0f1240a48920be063448a2242dbd90) --- 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 00a014670ed0..291fe3e2165f 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -11184,8 +11184,10 @@ SYSCALL_DEFINE5(perf_event_open, } } - if (event->attr.aux_output && !perf_get_aux_event(event, group_leader)) + if (event->attr.aux_output && !perf_get_aux_event(event, group_leader)) { + err = -EINVAL; goto err_locked; + } /* * Must be under the same ctx::mutex as perf_install_in_context(),