Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874111pxk; Thu, 17 Sep 2020 19:58:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTnpzOcXJeJ6Dqw5xBZMtc61Z6gM7fLZNiIPQc0fUj2e4XQnmW5rxzVnltH486RbJKgsC1 X-Received: by 2002:a17:906:a981:: with SMTP id jr1mr32140189ejb.99.1600397890255; Thu, 17 Sep 2020 19:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600397890; cv=none; d=google.com; s=arc-20160816; b=VmyX7IJjvZjEUJGyA+/mHn8r1fg8rFMxHdOIpgy2IqCKN334JzqtZkZPqJmX5QS4zE +fT7WepCkqZK92TO7/QZ8gfgphMVA7tMU/8h+NJKLlQVo26geZtBhyA0xZJiqXS1DbzB 2KhX0X4B0dFNGNTzHGQhGbMWRFPwqqgdTLpU+v6lXbdcqPfHHm9PdrImM5lkm/lXjUcE dWWSheiLcpwnlBCVAkGwy1JDg79twvxIoznXxHFWsaQII/THHkBR2Ki5BPv9Bu8ELH6z Yn5BUc5mPnlfa9okbmTPXLfu7omuJCddfHG0KP0dmDHQFMjIwwqzGDbbABVPjtpGEij2 8CLQ== 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=zl6sIfwQmbPzwXVFp0FbEx9z6vI1yws+qUnZkWPESyw=; b=btbxPlMlKzxJl4s71OedFtw1J6EEIGmhDcQucUQ/D304zndbFCiWd3xhPu/l/DarmY GrualfyrFCPXHhW2EkJ7YuXgsOQeC1EDk/MbETtbhw3+sMnI15Uz8pEhXaicgpnBx/gA 2T0U60Sk3jKOQO5N2VJtPJg2Fchuua5sIQMEfjDO4P5pb1sXWVWNSEj8TNGbZhNfc1bJ 29xvpuXyWzP3n5FczE/UyzYANnoL9ze7qRxiuFK7qHhAomr1+rYfszAD+//Kv95KuFgy IHeoOPtZTwU5iU58mkeHUKPhkJ736JbDsTJRdrtGr7U7tM8eoDOCRhRRTxwpY63yyhsC TPqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lbVdn7DA; 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 bo17si1221740ejb.391.2020.09.17.19.57.47; Thu, 17 Sep 2020 19:58:10 -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=lbVdn7DA; 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 S1728316AbgIRCz4 (ORCPT + 99 others); Thu, 17 Sep 2020 22:55:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:57224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727854AbgIRCHI (ORCPT ); Thu, 17 Sep 2020 22:07:08 -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 9EB6F2388E; Fri, 18 Sep 2020 02:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394827; bh=dMHxrPz7Vugty7pq9fbMpWAu3aJ4+zZiqbt/XoxiBNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lbVdn7DAVoj1PcrTf1U6tfK6R4aZvW7wdNlEXkZW1AJSXquWM7LGx3hMF4VYcEM5z jK1kDiDav5EVVs0WbwzUalaWqhexyAuptcTmsvQP9QbVt/VB6hDd8qifdzFFBa6G50 uBrVtLXi6fYCvPRYJ8PPDgEQ6dVYUZM0/vhiSH7M= 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 5.4 291/330] perf parse-events: Fix incorrect conversion of 'if () free()' to 'zfree()' Date: Thu, 17 Sep 2020 22:00:31 -0400 Message-Id: <20200918020110.2063155-291-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-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 5fadad158db59..f16748cfcb262 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1370,7 +1370,8 @@ 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