Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1064048ybl; Wed, 14 Aug 2019 10:07:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWoRs2TYp3tLadTnVcV4afwnbX08XgNKvi7C0HKq04US4IoknKhqlOkx2lglyGYVgaEsbJ X-Received: by 2002:a63:7245:: with SMTP id c5mr180755pgn.11.1565802474866; Wed, 14 Aug 2019 10:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802474; cv=none; d=google.com; s=arc-20160816; b=03tjw4KZXj8MHl7XZn/4SZl4NjKfsAhB8a+1Y1ZuDElzosOmWYrcd5z0iqSJo7UomY m8kgv96J1BU/6QxH7fmkJTi/NVDPB6ss4QUazrIM0y2XANR99k5fJEv8kwRl1Jds1LNj VvylNA2tnwNRHpp5AMuxpqojA+LZ3QylFt7sYAIu2bbm1tRTEVxogmpD9acd3JOUq42j FPAPyVO99H5/+GQKkCG4Aw6BT61vZkPtU0o9IZ4DDReQa+zCIRFHm3VVQYsmC5qTlpn8 rbNSX423tB05ZUt7wFKvZKaUK/72CWSG3Jogf9ncyqO7cmZqCybwmI5Drr2UB/qn4wSl i/Uw== 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=i+p/kcnaBseOMnhOFpbEZEZLqhpcOanzU0M6ImZsbl0=; b=U/ibbqw4o1bkfb0U6CJGRhIMSWuD1b0N1VFLEKLHBmSUlh0cNC1gdcGcknC3diqlqT zmht6Wjkt90IHhM2+nnf/8GbQvjsTXTymJ632bgC7tgs7Gm+t3njNS5k+lQqFu4OYvMy CKfR1B8PZ15pOfM6VJ1gFR9aeZj/JL4IlO9YVVhrVJvupN3kdk+hwnv8iek3dVeTGlhz b9+XtXN7s61I60vTn6sVSjrsos+TZ9HqT2k0BSRyEfFlSK+S2tHEqdiXEUR+niunfsQ/ s97rWUd9sMbvwBERwA2Yq0rG67pD9C1s45+xt9nBYniVcM3BLvJRCr7dpoQXrwJjs/ad KPlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qe881WzX; 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 z7si232311plk.350.2019.08.14.10.07.38; Wed, 14 Aug 2019 10:07:54 -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=qe881WzX; 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 S1729616AbfHNRGP (ORCPT + 99 others); Wed, 14 Aug 2019 13:06:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:55252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729601AbfHNRGL (ORCPT ); Wed, 14 Aug 2019 13:06:11 -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 5A8442173E; Wed, 14 Aug 2019 17:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802370; bh=/GYUwQmMt3TZzvvyIXHLIjoxIxXw+Hbgpp4fz82lAf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qe881WzX1/aC+R0JhXCYmzCXqWA45ip2r2x1435QrSDtI07C+E8bUkDogsPsueIKw d1BsbLPFL3z9HTm9dCDQQUxxDXYC7hshyxdqcJGnU2tPVACvQgQXFCpsVSPgQjmh3j F5f/InSb7+J2RdCTjIyNpfbGo5ic3JaYSOmSgQqE= 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 5.2 100/144] perf probe: Avoid calling freeing routine multiple times for same pointer Date: Wed, 14 Aug 2019 19:00:56 +0200 Message-Id: <20190814165804.067203232@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@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 8bb124e55c6d2..2c376f5b21200 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -698,6 +698,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