Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9434203pxu; Mon, 28 Dec 2020 16:24:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqLFEtJTrfskIdENHu1ZFvr7Gr5BdLur+q9W3LqgoDYtJAUDJeeYx8DFnzZqTYvs25OFv0 X-Received: by 2002:a50:ee1a:: with SMTP id g26mr44388063eds.68.1609201486014; Mon, 28 Dec 2020 16:24:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609201486; cv=none; d=google.com; s=arc-20160816; b=0yDKRMHb6Mg1VtvX2yyb65aWzUqaToDjkVxvFeBbAPNMTdJ+kscHho+B9oBoKr+Aho sMOXx6cUsDVHmen8HogPyN7CLLYC/lzvKciqOZWdgNkx4A6mzFN2M+unWMT0hwOg07RQ 9RYLxKCY4JFAWIBjOJNmad663S6oqVLSBFc5KJpRSFXAKVgsKMdZBr4LwolQMDj8v38a PSxjdvn/vHZhYPbsyeiClWLXUS1BTnw0Xer45aDF8LRi8bEFzfDrEtMcPMLWj+fCtiJU zYtkVd59kP2RZNOUkTSubIZzD21u6pUhrC9ddEj0m/hk6Ct2QSgjTytZyBMvSOtzurS3 3jDw== 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=C8zQEZ8c8x+8GnoHIcc3K8fKsSoeDtfVZmPblMxOTH0=; b=kSOxpe1iOzku3HEKZkcYFzOu2DRI37XNmzJYnz+zO9qEBix4YWSeVny5hudFm4nmAS ymsAKCWvxVT3QBLcDYmXSkV4Pc+Sz1nAOkga/9u32zgxMm3m3xGZ8ONdiwJtTTWnh2Os H82/yIZ4MVb+bgiQ5VRO6UuszXtagt1Q/XGkDMlT2dhL5Re9CHSPWBb7HaqKFcM81IgI 0RiyGCTyAQqmEXNcbOQH3oMoo6IL839PGYPXHCfZUtwzXcXOdjQyjQ5rfDKgrEWPGqwL nDGRogK1pIeFzy8ohqaqxIu0BBjbeu37bcWI0LzoCZ5IXaFvwE5yA7W/8faHIX9QpIYs zUUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AOo1cjKW; 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 c10si18500167ejf.281.2020.12.28.16.24.24; Mon, 28 Dec 2020 16:24:46 -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=AOo1cjKW; 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 S2408576AbgL1Pey (ORCPT + 99 others); Mon, 28 Dec 2020 10:34:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:55884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407374AbgL1Nxz (ORCPT ); Mon, 28 Dec 2020 08:53:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 675B22072C; Mon, 28 Dec 2020 13:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609163594; bh=b9g8ysgoLDr1ZfY0IDETC9mH3H9RUvJFUYrxjrObQVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOo1cjKW4l9cYkSLsdCXrDyWOP9a97A/pCa02t8iAbB62/DJKHcEagApC9CW+au1B HvFNE3MtWNA68gXThJAJ8jXekeIqzNsca0Trec/n0O/ca729kgHKTCSzUiU9xOdH4W FUSHtnPCwivWjAa8MQjCUA4JpZIway+ETVBts9GM= 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.4 310/453] perf probe: Fix memory leak when synthesizing SDT probes Date: Mon, 28 Dec 2020 13:49:06 +0100 Message-Id: <20201228124952.130935643@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@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 bf50f464234fe..f778f8e7e65a3 100644 --- a/tools/perf/util/probe-file.c +++ b/tools/perf/util/probe-file.c @@ -777,7 +777,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; @@ -799,12 +799,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