Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3972041pxb; Tue, 25 Jan 2022 00:19:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIi7b5RvJrJQnjDa8+1abR3INr5AC559bJ1SkIS8Tc7baC+ETLAIJMPOR/tTeP3A7NJvcQ X-Received: by 2002:a17:906:76c5:: with SMTP id q5mr15745192ejn.523.1643098775409; Tue, 25 Jan 2022 00:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643098775; cv=none; d=google.com; s=arc-20160816; b=eabEkG5ofMuj9Efv4uvlHyTKgEuQP5UdlvstnQy8s43dWEWEP4t2kzsZF7TtwOFYV8 tzsgVZG1K/B+T+0DJF69ewwxbfAsC/0xha1oNNCQzkHEXpIj7GX4IVBFrVkxhG8fV0va 1a8uunD/GWs22PZRaOAyY82egivgQ7/zpg2K8HzA9P0Na6bGiIMykx6EMZakYFOc5bT8 JJa6r3ROz9aKx6HKKePox9zn8iBHX+LNBywLEvdsOA2+omsuQ0sJRU3HotSJ2PywAnI8 wkypBK9kbqtwYeMOYuIXfpTN+3sk7bN09wYmZB+KRKznr2E0POS+ygjbbnFHPnlsWMDI dXxg== 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=faHEBpsmYXjIrIdtFgnkmVvD+zEBJ+KYjzqFFe2ZjD4=; b=hEGN3RhQQm6tP+vmiuj1lXQUlmH5b0GYJxJZXCbKLV9M40krvuHDl+q/JW98SRwhzj TdzWbOROto4PkfWSB13/JAr01/5RnxtnXAA5TRIrREIMHwWLXOQDmab1JuAKMArkZdQn +c35A10h7zuRx35WEoT/WXXjdIu3cf2iR/EJq5x4NL3Kcb5W3bHgLwzbgOzPsd54zsif 7vJanN5MEv7IhmDCV3wTHsknmX0XDsHfj/iUAg+txeMyHohWBCxkf/s3rIl19DI4AdLv OdeEf4VFF4jPy9+MuAHpF9+1B2imVSt4ZPB9jKZAAX/SwhFpx702Mh2TM4UCP1rNbFyt rF0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FxKqOfVu; 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 w5si9539940edq.559.2022.01.25.00.19.11; Tue, 25 Jan 2022 00:19:35 -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=FxKqOfVu; 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 S3413289AbiAYAio (ORCPT + 99 others); Mon, 24 Jan 2022 19:38:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2364531AbiAXXs2 (ORCPT ); Mon, 24 Jan 2022 18:48:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F17C07E317; Mon, 24 Jan 2022 13:43:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC7FF6150B; Mon, 24 Jan 2022 21:43:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64B82C340E5; Mon, 24 Jan 2022 21:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060601; bh=JTTDe9f3qMJahSvlrR4RZimV75aBNE+Q8blwnO21DLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxKqOfVus/eM2tSe7TKpjLdBok1fiafJuIFg6dt7IvR8sOhqP8vx0hlke63Y4DQ/I maSTa8Lnmk33+1gEGh7+FwS9Zgei7YqSEPDcZ0gjqIcG4VoND+7ssYRcDD/4ADUxTZ r5tutyDt8B+XpFMIE9rd/FyUExOVMgvXxVMUilXs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Alexander Shishkin , Andi Kleen , Ian Rogers , Jiri Olsa , John Garry , Mark Rutland , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 5.16 1002/1039] perf metricgroup: Fix use after free in metric__new() Date: Mon, 24 Jan 2022 19:46:31 +0100 Message-Id: <20220124184158.967660423@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: José Expósito commit e000ea0beffb5497425054b151369fe37a792ece upstream. We shouldn't free() something that will be used in the next line, fix it. Fixes: b85a4d61d3022608 ("perf metric: Allow modifiers on metrics") Addresses-Coverity-ID: 1494000 Signed-off-by: José Expósito Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ian Rogers Cc: Jiri Olsa Cc: John Garry Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20211208171113.22089-1-jose.exposito89@gmail.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/metricgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -209,8 +209,8 @@ static struct metric *metric__new(const m->metric_name = pe->metric_name; m->modifier = modifier ? strdup(modifier) : NULL; if (modifier && !m->modifier) { - free(m); expr__ctx_free(m->pctx); + free(m); return NULL; } m->metric_expr = pe->metric_expr;