Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1073839ybl; Wed, 14 Aug 2019 10:16:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi9BtSmEtyhtjeW/c2Bfj546LGNLSeyRnKO3ztH2W3AsBQs6Zs0aaftpKwD0TGxLu/IRYW X-Received: by 2002:a05:6a00:c7:: with SMTP id e7mr1045734pfj.52.1565802972033; Wed, 14 Aug 2019 10:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802972; cv=none; d=google.com; s=arc-20160816; b=ieUWPJ8bzmwxZb95O6rjSd5XPvAqfmVSUce42X5iyCxFJAKHXO262HSFii5QsIL2SH gAeTOFSIuBAf7PUJ2+sPvnbRabbeRHrG50wrfb2C44EW8607Mb0rps/dWowc4yMC9u3p 2f+WxJ5MhqPC/mO4CTB2JrCsdfwDJvpFWJPQwUiyDqRxY3qSs0zpwovy6ZlWnU8ksIg9 YorQo/hALBb1lhFb5D+HM2s6647asEZhl02wVPUXcTLL7NtdSJF4r3j2kSkLfIqiHUfg CkEB5Bbiq8/ea4K+cPgbCM2v7mswkXlCp4s5RxLNWkMpqy7OTGuAjOWehqFvBA5uT4MD 7jjw== 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=TYltTtYHno6ktIM8GU/y0ZPRpS7dMpRtKe89NM5OROY=; b=VEJDilUAB1deEooJO2c9TRkJje/r3hxU+zFjHZ/iKko+NgG7BAzSkbpASN1WD08WAq QJ2yFZJAjBM4vZgE5LeiRP0QKsi6QGekhjAFw9K/U8olX2QrafI6xqybm4HHHWnuuMp+ U98eBcmlJrGDApTFTgA7+CmJv7xcwuTq34woULg73r+l52C2AahOhPI5+ertUQmN56x2 V0F94ZQT71OYW5f4RkLXE2G1Qlvt+pFdRTCCCjosse126owQ4ezDJavjMG2+r+J5bUaV oGfLIdMX7YzuGO55RwknLci8sV6gm/bBqHCNZKq9eBWkHQtNJTfxLq23fo0JvS4Z4d7a drmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eeTohfxx; 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 h186si158662pge.110.2019.08.14.10.15.56; Wed, 14 Aug 2019 10:16:12 -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=eeTohfxx; 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 S1729548AbfHNRPY (ORCPT + 99 others); Wed, 14 Aug 2019 13:15:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:39974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731222AbfHNRPV (ORCPT ); Wed, 14 Aug 2019 13:15:21 -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 425C821743; Wed, 14 Aug 2019 17:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802920; bh=com3TRxcRZ4072zwSKf4aPMzXa1qbohAh+UwbVWjgAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eeTohfxxyvmZiErx7KUVzRsg38BelEpykxyPujHBlOgrwXuN/xGpuxBzm2R++Q7Rz mo3troRVIAXJHuEndMgdyYdsvdpj8BgEYVikFm43cJotwHSoQOBhyUOzsbsTpXgE5z rN4sMD1+Mlk6s2+8crf6HsrqX3+dUuaaa7HSlLfk= 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.14 41/69] perf probe: Avoid calling freeing routine multiple times for same pointer Date: Wed, 14 Aug 2019 19:01:39 +0200 Message-Id: <20190814165748.197878283@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165744.822314328@linuxfoundation.org> References: <20190814165744.822314328@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 c0065923a525f..e1ac51aaedcff 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -712,6 +712,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