Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4048200pxb; Mon, 21 Feb 2022 10:54:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9dHri6gRpCKX450EBnXuuRkokH/tw4D7GXdacXhvoUcw58g0haCN4YMiP49nAtVbILacN X-Received: by 2002:a05:6a00:cc7:b0:4ec:c6f3:ad29 with SMTP id b7-20020a056a000cc700b004ecc6f3ad29mr17612211pfv.66.1645469672336; Mon, 21 Feb 2022 10:54:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645469672; cv=none; d=google.com; s=arc-20160816; b=mvHhlOCVYEg2MeUOb78lJCtcA8OxqvTvUUNTNht0Tvt+S7P1VCi7fCzL0lD25cBe2c qPWqSCTlPkoAAwpaZYg/dTa+evgCQvm6OTip+V0ZnST9EDA1IQhWajZ429R1Oc/Dk7I/ MSTBiGcrwrI0SzCYo8/o53UDQLfNp36tfzzOgLAZbodq9Ca6WIEq10EqUt0Gy6QWKQxb v/DzBAWxapxC5BFZrybfdI16irlt94v8wgdb2WRgCMpLAKjQt/jfikXCxFuIJSN9iik+ ZAW155WQaliD1s4oDcFHZ3FAhMGGarBCHfeB2L6QBtAF7x2F+redMicdSPz/tusW468s 1bkA== 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=mzKVPKUqN2Q9UW8G8LXcRu/mS4Fkc6zLfPz2OY98nFg=; b=r84phQqII+oIHDI4fmYSUORdd7SumGtJVXgI1qWz2qkWNutu9NkMrJ6LBQbAhxUx4s Fo2o8zqj4Qwiuj1iVEHEwxpnv7CO1npqBfbR0Hal81g7cMrigQxktbnR9GlQwle9yHYm jpIqLQrThIXhwAy5GWtQPr8yBjFwOHzRXfbFZZRB/WLWnC0CSK3JmRJgOiwURK5xFSrg Y6JdglNhwcu0x0WwWzey6H8TnTOuqrkC+anv+jcFvo6//ub08I1lUOVIDLX+gyPspRyn db8BVt1BFZvuF6W46jrlXo5/lY2iHpiq2FMXwF9Q9xapUjlS/8Sr8pymmQeoaoDplTWS EuJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kGwe1pok; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8si30018045plt.409.2022.02.21.10.54.16; Mon, 21 Feb 2022 10:54:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kGwe1pok; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1353474AbiBUJ52 (ORCPT + 99 others); Mon, 21 Feb 2022 04:57:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351314AbiBUJss (ORCPT ); Mon, 21 Feb 2022 04:48:48 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C013732046; Mon, 21 Feb 2022 01:22:32 -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 sin.source.kernel.org (Postfix) with ESMTPS id AB6C4CE0E8B; Mon, 21 Feb 2022 09:22:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90422C340E9; Mon, 21 Feb 2022 09:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435349; bh=08eY0msXADLduerMwecp2drQdDRqyeIrBiLp/rfWPzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kGwe1pok6DOzsV7cSuKJKg6RAPkPk3IfMjXydpYlwZxNSbBp2H39b3xaNSFogokGD Xq3NL2vLP9ECl72Nrb5WIcEzhrO81ycnpnMC8MroQCXUZMPVxIGt3EIlcyiabdDzAe DKv+wQut285bQJRSwPxKjCC3Hr6BQql0lK2abRdw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Ian Rogers , Jiri Olsa , Namhyung Kim , Wang ShaoBo , Arnaldo Carvalho de Melo Subject: [PATCH 5.16 132/227] perf bpf: Defer freeing string after possible strlen() on it Date: Mon, 21 Feb 2022 09:49:11 +0100 Message-Id: <20220221084939.247694791@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo commit 31ded1535e3182778a1d0e5c32711f55da3bc512 upstream. This was detected by the gcc in Fedora Rawhide's gcc: 50 11.01 fedora:rawhide : FAIL gcc version 12.0.1 20220205 (Red Hat 12.0.1-0) (GCC) inlined from 'bpf__config_obj' at util/bpf-loader.c:1242:9: util/bpf-loader.c:1225:34: error: pointer 'map_opt' may be used after 'free' [-Werror=use-after-free] 1225 | *key_scan_pos += strlen(map_opt); | ^~~~~~~~~~~~~~~ util/bpf-loader.c:1223:9: note: call to 'free' here 1223 | free(map_name); | ^~~~~~~~~~~~~~ cc1: all warnings being treated as errors So do the calculations on the pointer before freeing it. Fixes: 04f9bf2bac72480c ("perf bpf-loader: Add missing '*' for key_scan_pos") Cc: Adrian Hunter Cc: Ian Rogers Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang ShaoBo Link: https://lore.kernel.org/lkml/Yg1VtQxKrPpS3uNA@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/bpf-loader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -1214,9 +1214,10 @@ bpf__obj_config_map(struct bpf_object *o pr_debug("ERROR: Invalid map config option '%s'\n", map_opt); err = -BPF_LOADER_ERRNO__OBJCONF_MAP_OPT; out: - free(map_name); if (!err) *key_scan_pos += strlen(map_opt); + + free(map_name); return err; }