Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9108311pxu; Mon, 28 Dec 2020 06:51:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjBXLGy9Y4TeUpLP4noZqdqkE5ooJ7w7ZzOOTWIjKG+0Sw1XzgEVwozpjXeiHL/1annC5P X-Received: by 2002:a17:906:c00c:: with SMTP id e12mr31410793ejz.103.1609167087183; Mon, 28 Dec 2020 06:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609167087; cv=none; d=google.com; s=arc-20160816; b=NoiXUqwrtui06XooIiobd30NDSb5g5WTavHdxi/hyvY0GkQW4U6kQTG4+vlX1O2pNk HG1OqUe2D/jZR8mpw/jfvdY4MNosJ+LbSWzZEoH75m7b+jRRGIdt3qqZJNAAPDNMdj0g qj0GGKQJel/bfLQDVIPhdwvR0voAgMcr5nRGyt9s/BlXd7iZWVxPT0HQMHuO1Qo9GuDQ EFolWybuH38muU8SeX06i+AffNcgQLPE8krTOLKQfVEvG8cYqaXJC4CPy0wuLGqGH+UY VkgG/dT2zmF0yk29oJCCj1+iyQ3UHa9RfYrZfl50zOg/4Q+89nIZJ+V3sz6uy9ZrMlw7 vWKw== 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=iPcXIWk7pju+bfX3TP+sW+IjJ6Zi6TTTK3qhwJXhTvI=; b=Nnt47Au81V0lT3zvPC9iHtVKaShJWFEpelEadCFpjZ/OmfAzRYSgjaf8WehzZ9MQZS 1isQvf48TNWBKJsewisWdBJ1389VF03y4+LImQnzAav+ZO/NUIPaZIxoW56cZQKEYdEU sw0F9QeqAqkY0mD6ySkdARvjH3EqSYxVxFXEPXAgkZnYMnar9sYSmWD1dxu952hIZ5c8 NXe/g0nCryRlq8afFNBX/BS9eLfn68WttGaVJv3hoegb49DkoOhtarwFoPD0SNg9O2p7 g1sTB9HXlocCNbpOy38TKAkrj0F/c//UnzEb3C9hiU4jDbBASmA05JqX42rZMedTGdqc W/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T4hAWyY2; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a89si15429723edf.215.2020.12.28.06.51.04; Mon, 28 Dec 2020 06:51:27 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=T4hAWyY2; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502856AbgL1Orx (ORCPT + 99 others); Mon, 28 Dec 2020 09:47:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:58386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439209AbgL1OXE (ORCPT ); Mon, 28 Dec 2020 09:23:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A944207B2; Mon, 28 Dec 2020 14:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165369; bh=Tj44dTdXaFk23UtGG7HF/SNLeLwIp4umRsHOGWmOdzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T4hAWyY2QoOzB4QcLo0AqaiLsLmf0GtB4q53LkbM68s2J0A4Wnrx6YZ68ZVWCobT8 E2OASFvLxsG/nEP/tKy5xTZAW4J3XgD432A+ot7VeHjcdQXJZIGZtDCLQvhobHGxcn DODz6YsCstjA6IUZ4qwxt/cMguUBoeCBE8slctG0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Alexander Shishkin , Alexandre Truong , Alexis Berlemont , He Zhe , Ian Rogers , Ingo Molnar , Jiri Olsa , John Garry , Mark Rutland , Masami Hiramatsu , Mathieu Poirier , Namhyung Kim , Peter Zijlstra , Sumanth Korikkar , Thomas Richter , Will Deacon , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.10 505/717] perf probe: Fix memory leak when synthesizing SDT probes Date: Mon, 28 Dec 2020 13:48:23 +0100 Message-Id: <20201228125045.154010502@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Arnaldo Carvalho de Melo [ Upstream commit 5149303fdfe5c67ddb51c911e23262f781cd75eb ] The argv_split() function must be paired with argv_free(), else we must keep a reference to the argv array received or do the freeing ourselves, in synthesize_sdt_probe_command() we were simply leaking that argv[] array. Fixes: 3b1f8311f6963cd1 ("perf probe: Add sdt probes arguments into the uprobe cmd string") Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexandre Truong Cc: Alexis Berlemont Cc: He Zhe Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: John Garry Cc: Mark Rutland Cc: Masami Hiramatsu Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Sumanth Korikkar Cc: Thomas Richter Cc: Will Deacon Link: https://lore.kernel.org/r/20201224135139.GF477817@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/probe-file.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c index 064b63a6a3f31..bbecb449ea944 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -791,7 +791,7 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, const char *sdtgrp) { struct strbuf buf; - char *ret = NULL, **args; + char *ret = NULL; int i, args_count, err; unsigned long long ref_ctr_offset; @@ -813,12 +813,19 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note, goto out; if (note->args) { - args = argv_split(note->args, &args_count); + char **args = argv_split(note->args, &args_count); + + if (args == NULL) + goto error; for (i = 0; i < args_count; ++i) { - if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) + if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) { + argv_free(args); goto error; + } } + + argv_free(args); } out: -- 2.27.0