Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp863741pxk; Thu, 17 Sep 2020 19:33:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNTEsLyUTmWCf+jIUjCUfNho92h0uwsOy0tT0Ny5oLHW9Qs2+AR6USzOHwKRQ4xt+iFaad X-Received: by 2002:a05:6402:1254:: with SMTP id l20mr36178272edw.312.1600396396760; Thu, 17 Sep 2020 19:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600396396; cv=none; d=google.com; s=arc-20160816; b=uc4yDl8FJw3tLP1mkx+ksL3386wA9psKhOc9Ec2BNDq+PqVfWG9U6sRItbInkervJ4 Gg52wuBNKtfHNbC4GUsH52mcbm3oVmFxTGodpX7+fV4lGqrDSga6TpJoawQ7fG10ypys zRbX9o/NLUb/XXudRRqjo3i8s2E8IblgvilHIpDkY08cSHGxtBdXaB2u/infPXn1D2Em rPsy2M2c+FlS67DG9HVnK9BAveeaKCsLpgLyREsHrXavv7t24+NNHrhvhoJIONCkjg9F 3YyOOYUbfNf748dl1Tm4Wi1UErKWXKt1n8LrTI+8GL2ry5spU0mpan5fTyGPcXDot+IA 4H4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9nm5FVXEARC/728ZQpKlt7WtWWh59PZu6I7VD9+/lZg=; b=m9hyFhXAq2jheh1WQYqyp30iE1OkSgG4bXbXRvEJTSdZuADuj0MCnkSZgZbo7mPtcR 4+lZ1RKfe0OIHTxSNV38tjAI7veN8sPyQJck6B2gYF/T1o0rSCwuPwM3oo44uJ0ez0ze Tn4jssZVdfDYE1PP5XDzeO/SeGtwcqgp9JGOGDc02JKUr0W2Rjg9xlwXeyvDVjAhDNUq khkvrQjdHth0Noz4wPxo+RpmYO60v2oPJgrkYF/Ueo9vkIKEj6ClcAYZsnCo4lbnjhty LhpPzpU8liq+19a/LRBVigCJbboP3Y3LSLufhczUpp/Pt30RoBsNW5cH40vQ9eWjRkc7 HPRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=owRycwnc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si1089751edy.401.2020.09.17.19.32.53; Thu, 17 Sep 2020 19:33:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=owRycwnc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728571AbgIRCam (ORCPT + 99 others); Thu, 17 Sep 2020 22:30:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729105AbgIRCOe (ORCPT ); Thu, 17 Sep 2020 22:14:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3E3A235F9; Fri, 18 Sep 2020 02:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600395274; bh=/G49LB43JSt49hW9SPXAELq6kzohbtmxMKQDZYyFeI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=owRycwncwgsLSi3NSkLwmkMSUYwsz2sC9WCVyp7klk6A1ZzHaH/yxTfkvWWC+6ijv w7JL3Y0ObX1yVycHhZK/32xCNt5r3Yab6BiwqE4u0QlTkPToTbGoMA4Kq6skN5uUxd XA4afJ5dYHxLbQITxSQmtCMjSlDygnDmvPx2c8Lc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnaldo Carvalho de Melo , Ian Rogers , Adrian Hunter , Alexander Shishkin , Andi Kleen , clang-built-linux@googlegroups.com, Jiri Olsa , Leo Yan , Mark Rutland , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Sasha Levin Subject: [PATCH AUTOSEL 4.14 112/127] perf parse-events: Fix incorrect conversion of 'if () free()' to 'zfree()' Date: Thu, 17 Sep 2020 22:12:05 -0400 Message-Id: <20200918021220.2066485-112-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918021220.2066485-1-sashal@kernel.org> References: <20200918021220.2066485-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo [ Upstream commit 7fcdccd4237724931d9773d1e3039bfe053a6f52 ] When applying a patch by Ian I incorrectly converted to zfree() an expression that involved testing some other struct member, not the one being freed, which lead to bugs reproduceable by: $ perf stat -e i/bs,tsc,L2/o sleep 1 WARNING: multiple event parsing errors Segmentation fault (core dumped) $ Fix it by restoring the test for pos->free_str before freeing pos->val.str, but continue using zfree(&pos->val.str) to set that member to NULL after freeing it. Reported-by: Ian Rogers Fixes: e8dfb81838b1 ("perf parse-events: Fix memory leaks found on parse_events") Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: clang-built-linux@googlegroups.com Cc: Jiri Olsa Cc: Leo Yan Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/parse-events.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 2733cdfdf04c6..ba973bdfaa657 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1258,7 +1258,8 @@ static int __parse_events_add_pmu(struct parse_events_state *parse_state, list_for_each_entry_safe(pos, tmp, &config_terms, list) { list_del_init(&pos->list); - zfree(&pos->val.str); + if (pos->free_str) + zfree(&pos->val.str); free(pos); } return -EINVAL; -- 2.25.1