Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3294783pxk; Mon, 21 Sep 2020 09:55:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv/Tj6xCOTOJuvnFGS28aP76P1+3bu2ocPh7n64yVSUWzxGHonuc24Y6Mrzoelj8lQ//Nu X-Received: by 2002:aa7:ca4f:: with SMTP id j15mr565686edt.233.1600707338573; Mon, 21 Sep 2020 09:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707338; cv=none; d=google.com; s=arc-20160816; b=AKPvwVqznMT5jhVcpc1K3+qQqxB3SmJMRc5I/brslob81mH+b9LjBgevGx7EAKJOW+ RXoPQ8uEqhjVXRwgodG3Em8HRdoSTGEckyJhuxo+unjj7wdYAe4IGDovgmQbTMpv18Gj ylVpzUrCixrEX87lHiv3NLyxGvyKis1NXp1+LfIgAZ3zh9/69BOXzWgjyrNl0Avo5gpF UJz/ClcdjMqNa0n3YdJoo2sPUq+paVrWDkEMo5ItUPqwCh/Bhxi1KgYsvjfoSB1eJFvg wBJN1M3IEjuL5bBzH9shH/z1GK3omNhDSv6fSo1WkFgnhuTQjRnQRlRiQnP+8y44LYHH Yt2A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XTw1ebcoqDwJMIHEx61xsQ8ZiJbBdS0gafNk3pvOe/g=; b=H9AMJjNYUJ7VqibXE5LWCDT0EnajX2etn3Ua0lV0EONk0KyJL7YSIsEhVZ/tyhDVgv 7p5ear2StXBZD7T4xvFPc9xE7/QhRNiaL0U8zyaHLZ44YiT1sDMZfKr7WSAS1bCKRUX6 GYz40pCctJuTXUlHz2tT8YWliZN+HRFEn5nitrw4SIgdMpnWp5F5aSp8uXdBQDH9OQJo N5RHegdYzZp5vFeetmzGpKJnuwclqpyAlNeyQQNH5iBU3dyIIS/DrAsKWTXgW8C5HYqO gMKG/kB0xPMYAVnj+qKg3/UQmbZAKdNW9a+3l+/BrzIWyC1RjsFtpLl5ijKg8XMchIOP Xwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DZOXs2CC; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd11si8592285ejb.184.2020.09.21.09.55.14; Mon, 21 Sep 2020 09:55:38 -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=DZOXs2CC; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729917AbgIUQyX (ORCPT + 99 others); Mon, 21 Sep 2020 12:54:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:52484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728908AbgIUQqV (ORCPT ); Mon, 21 Sep 2020 12:46:21 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 E69AB20874; Mon, 21 Sep 2020 16:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706780; bh=QvwBaKynKIcaRCg4H/lA0B3uWE21ENvqez4JsxjTgYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DZOXs2CCEfYUCxcAloVk1BDuPwzys9FLcr8qFkbnewllvqGU2uZnVGRofiX3rs9M2 ym7IHHDMbf1QqluYOWDnzuI/aNmEM65XF0rvYn6tjpEih1m7NGKFF3ikGtvnFt+7as LJ0N2gteqX6mYROghuB2Jupo1mAeEz++GurHcpNg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Jiri Olsa , Alexander Shishkin , Andi Kleen , Ian Rogers , Mark Rutland , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.8 062/118] perf parse-event: Fix memory leak in evsel->unit Date: Mon, 21 Sep 2020 18:27:54 +0200 Message-Id: <20200921162039.236342889@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namhyung Kim [ Upstream commit b12eea5ad8e77f8a380a141e3db67c07432dde16 ] The evsel->unit borrows a pointer of pmu event or alias instead of owns a string. But tool event (duration_time) passes a result of strdup() caused a leak. It was found by ASAN during metric test: Direct leak of 210 byte(s) in 70 object(s) allocated from: #0 0x7fe366fca0b5 in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x920b5) #1 0x559fbbcc6ea3 in add_event_tool util/parse-events.c:414 #2 0x559fbbcc6ea3 in parse_events_add_tool util/parse-events.c:1414 #3 0x559fbbd8474d in parse_events_parse util/parse-events.y:439 #4 0x559fbbcc95da in parse_events__scanner util/parse-events.c:2096 #5 0x559fbbcc95da in __parse_events util/parse-events.c:2141 #6 0x559fbbc28555 in check_parse_id tests/pmu-events.c:406 #7 0x559fbbc28555 in check_parse_id tests/pmu-events.c:393 #8 0x559fbbc28555 in check_parse_cpu tests/pmu-events.c:415 #9 0x559fbbc28555 in test_parsing tests/pmu-events.c:498 #10 0x559fbbc0109b in run_test tests/builtin-test.c:410 #11 0x559fbbc0109b in test_and_print tests/builtin-test.c:440 #12 0x559fbbc03e69 in __cmd_test tests/builtin-test.c:695 #13 0x559fbbc03e69 in cmd_test tests/builtin-test.c:807 #14 0x559fbbc691f4 in run_builtin /home/namhyung/project/linux/tools/perf/perf.c:312 #15 0x559fbbb071a8 in handle_internal_command /home/namhyung/project/linux/tools/perf/perf.c:364 #16 0x559fbbb071a8 in run_argv /home/namhyung/project/linux/tools/perf/perf.c:408 #17 0x559fbbb071a8 in main /home/namhyung/project/linux/tools/perf/perf.c:538 #18 0x7fe366b68cc9 in __libc_start_main ../csu/libc-start.c:308 Fixes: f0fbb114e3025 ("perf stat: Implement duration_time as a proper event") Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ian Rogers Cc: Mark Rutland Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20200915031819.386559-6-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4476de0e678aa..c1120d8196fae 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -410,7 +410,7 @@ static int add_event_tool(struct list_head *list, int *idx, return -ENOMEM; evsel->tool_event = tool_event; if (tool_event == PERF_TOOL_DURATION_TIME) - evsel->unit = strdup("ns"); + evsel->unit = "ns"; return 0; } -- 2.25.1