Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp877929pxk; Thu, 17 Sep 2020 20:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxec1i6ptaVBWk+oS6q11WnDZwv5ZkX9AlnBiPast2qDavejSbnVyUeFDbqHdV/JD8CP6k6 X-Received: by 2002:a05:6402:6d6:: with SMTP id n22mr35792730edy.79.1600398378808; Thu, 17 Sep 2020 20:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398378; cv=none; d=google.com; s=arc-20160816; b=LmRmhxexvAmq6QY2gB9DxmAOjuKCwEz8W4tFyP/NUQkPaO4U9BD894m1Od57d8P1ld SrtjFmM1rY7Ubfe10Uy7XmM5Y8IbRmWsc2Yt1hohjfE/K9Ab7aRzIsB8LHaGaeW9G1XX dOQ9DIlXlTX82dY32KG3wuQfl0e071k6Skouk5B/a9vJQz9BdOVaCK8e1gbnX3MeDam9 JjNQls+hqqY3Xo4I5l/nxKtboQCkW6G5ylj/nBUlDFrbtQV62mMIlBXueWzpktrtu8Xe HcU2b2el+TbWLyiBWEcfQIdeJKvGgZai9cgJC1+P6sPaX+GQNQCWXsXgWA/lW73UzB0L Un2g== 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=LR06A7SaRpt/Fl1tPudcGwU3k4upD/UpBRBDOHLAtbw=; b=zvhaT1vZSWn0qZcZHRkcCUg0JBiL0aO7P/XlEEuKa0kLS8IFCFKgdvZOMEEe/BZact R7ASc3kgO1722zdHdjCDO15xwd18+uLe4lqKVn+zumH0kM6xtytOj68NBO935SnABAHb FRBwI44eYlPlbX6R3KPJDxRnuOBjbzy10DVAn/rZN0KH5bNfanF+DukaKQAdHHBdElr5 Aa+XT6CUE3GE6b0c1iPWsyHtp5Sc5Mj+yYAVrYDETJomxxqV8iOk8EXX33VxQohDG2jV qbIyAR/AuL3AbiMc209s6Mz0P+2z4So3fe3Y7pp4CRZ8Wt3xdZiu+5/naE9y3XSLe08e hKWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GVvtQsJ9; 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 dm15si1139535edb.236.2020.09.17.20.05.55; Thu, 17 Sep 2020 20:06:18 -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=GVvtQsJ9; 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 S1726586AbgIRDDi (ORCPT + 99 others); Thu, 17 Sep 2020 23:03:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:52904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727414AbgIRCFA (ORCPT ); Thu, 17 Sep 2020 22:05:00 -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 5080B238EE; Fri, 18 Sep 2020 02:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394699; bh=54q9jwXQM2ZlOMlWtE3Sa/lenqEuk2jlTO1voiYQku8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GVvtQsJ96YcnzL355XoenMiGXeUuzD8liVRJxvVbY9rbpKG/DavM1oG7YwnrQta+D Ym5t6PPdxKoVhmYdyd4DGSZWQ6uThzALskVDQzWrYhObIQDNcNrP493+Ihn3bGltkR evctLt2lHubuaAUWO0giVgT9cCCD3TV2E7DnQge0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Andi Kleen , Leo Yan , Mark Rutland , Namhyung Kim , Peter Zijlstra , Stephane Eranian , clang-built-linux@googlegroups.com, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.4 186/330] perf parse-events: Fix 3 use after frees found with clang ASAN Date: Thu, 17 Sep 2020 21:58:46 -0400 Message-Id: <20200918020110.2063155-186-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: Ian Rogers [ Upstream commit d4953f7ef1a2e87ef732823af35361404d13fea8 ] Reproducible with a clang asan build and then running perf test in particular 'Parse event definition strings'. Signed-off-by: Ian Rogers Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Leo Yan Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Cc: clang-built-linux@googlegroups.com Link: http://lore.kernel.org/lkml/20200314170356.62914-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a844715a352d8..dfc982baecab4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1254,6 +1254,7 @@ void perf_evsel__exit(struct evsel *evsel) perf_thread_map__put(evsel->core.threads); zfree(&evsel->group_name); zfree(&evsel->name); + zfree(&evsel->pmu_name); perf_evsel__object.fini(evsel); } diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 422ad1888e74f..2a97a5e3aa91e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1344,7 +1344,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats, NULL); if (evsel) { - evsel->pmu_name = name; + evsel->pmu_name = name ? strdup(name) : NULL; evsel->use_uncore_alias = use_uncore_alias; return 0; } else { @@ -1385,7 +1385,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, evsel->snapshot = info.snapshot; evsel->metric_expr = info.metric_expr; evsel->metric_name = info.metric_name; - evsel->pmu_name = name; + evsel->pmu_name = name ? strdup(name) : NULL; evsel->use_uncore_alias = use_uncore_alias; evsel->percore = config_term_percore(&evsel->config_terms); } -- 2.25.1