Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1080331ybl; Wed, 14 Aug 2019 10:22:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBJ0l7PSJZFVNgq0H8j6beomf6L9deUzwCxA4otHWb8VcAOxRy/oO1wHSxDzhWbcwZTofx X-Received: by 2002:a62:cdc3:: with SMTP id o186mr1068099pfg.168.1565803351439; Wed, 14 Aug 2019 10:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803351; cv=none; d=google.com; s=arc-20160816; b=UqRcBY7ZO4ecdArqqa4Ebh6OBrEU5y2u3XEPVN+ez4N6LfpZo44RtNieKhQri3kI/H hi/mVnMGqsLvPJXvl8Pqg6ZIXJ3ToQPorKYijXfz8n0Xr8fa83GrSBqxnP8ivObzjzou WkbE2N2hsAfmHzjj3IWM5Ni5gaskZGIqZB1w+EDoyacNTZKddZgSXqvqUa8q50KshURE XzSaI6bYl39mq9lf/1wBGI5BOyBEF9KKuVvoLOxWWF0vP8QRxzZwzCbSqRRBEKMhoJ1o XICmkiYlFDSE8IqR5UHOmjctmDQd7oTjdi5oe/GUFybzjNLcopeucmrrWcsZjw3Yil1S Dmfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RsPWz7OhpuiPln7zugKkISR+Tta553Gf03jZN0V22DY=; b=vvwl5xK34rTQyqCuIhoKnj5P5FiQt5vQqKw/3gs+dTAokVGebkbpY7SoaQAi0xRqUm cOICurS9B0IQyx+6gs1wCTgmXaovV50u3yLQGfobRJVYm+IevZtyu8/ONliMj8Ohmvrw ANXJcRtK1EJR18RmlvmPS88xMs09F9eWkKooEQkfrXy3h+RQtMOx4ylGP+BZH9E8UmG2 PATxDb0pWcRiD2CH4YiTcPXK0U3OdLwHxGdEfIwd2D9LjyAujkU1m7Bsc81q7XYUC8Q4 eW/ZGOKScteNcOBLJgnJvjVm/DnlQ1fatiutVZq37XmNaUJAl9If6EnISw370fm+B7Cf qyjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MDwqL2k9; 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 k192si173796pge.222.2019.08.14.10.22.15; Wed, 14 Aug 2019 10:22:31 -0700 (PDT) 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=pass header.i=@kernel.org header.s=default header.b=MDwqL2k9; 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 S1730240AbfHNRKm (ORCPT + 99 others); Wed, 14 Aug 2019 13:10:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:33400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730220AbfHNRKe (ORCPT ); Wed, 14 Aug 2019 13:10:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 432BA208C2; Wed, 14 Aug 2019 17:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802633; bh=EHaAD9qiC6h7RKmfVt1UQ+1y1ZhRwFEYxLMl9PI7pG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MDwqL2k93OuXskLgEX0IoEF9o6RfLJ6umPeOXedHoshgaIzy0zCauDzgPSwfIWu52 4jlh5Mc9pZgAXcAKsHuWDI3lqye5DNYQSQRbRyG138TSKKcMNK765zhdUjBVL67HY3 HPxrD6AmKExALq7wG/ZTi7S9udIbdU+6tyNJaqsU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Jiri Olsa , Masami Hiramatsu , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 57/91] perf probe: Avoid calling freeing routine multiple times for same pointer Date: Wed, 14 Aug 2019 19:01:20 +0200 Message-Id: <20190814165752.016176295@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d95daf5accf4a72005daa13fbb1d1bd8709f2861 ] When perf_add_probe_events() we call cleanup_perf_probe_events() for the pev pointer it receives, then, as part of handling this failure the main 'perf probe' goes on and calls cleanup_params() and that will again call cleanup_perf_probe_events()for the same pointer, so just set nevents to zero when handling the failure of perf_add_probe_events() to avoid the double free. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Link: https://lkml.kernel.org/n/tip-x8qgma4g813z96dvtw9w219q@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-probe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 99de91698de1e..0bdb34fee9d81 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -711,6 +711,16 @@ __cmd_probe(int argc, const char **argv) ret = perf_add_probe_events(params.events, params.nevents); if (ret < 0) { + + /* + * When perf_add_probe_events() fails it calls + * cleanup_perf_probe_events(pevs, npevs), i.e. + * cleanup_perf_probe_events(params.events, params.nevents), which + * will call clear_perf_probe_event(), so set nevents to zero + * to avoid cleanup_params() to call clear_perf_probe_event() again + * on the same pevs. + */ + params.nevents = 0; pr_err_with_code(" Error: Failed to add events.", ret); return ret; } -- 2.20.1