Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp130288rdb; Tue, 5 Dec 2023 00:13:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHos+CC1viBGafIPN1lgHHaEWcf012k0Eqg68ZE+GeWx+HuBbNkTsAhwg8N8HK5eBDlXsDz X-Received: by 2002:a05:6358:3417:b0:170:17eb:377b with SMTP id h23-20020a056358341700b0017017eb377bmr7512519rwd.35.1701764004796; Tue, 05 Dec 2023 00:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701764004; cv=none; d=google.com; s=arc-20160816; b=zRbOJc/dLiKBjULI4M5KXR3aoYOy97A9sTem+GH4usCi4inc5yaWT0Lykju4qAOJ7S rCDX1aYpyKMoU4+OKXbSRNlBp3BiFkZfwHBiFwqnoVstPpPUiwxjS333nyWNgzMlPrIA eeDbxpaklWwsaCI46fhyLV9yWOuqSkCVnj8ASfrcympw4DJVr+NgJ+O3rxp0WENyQ9Yl pvxgar21vlMukKE1/g/7oKdKwtRf7IT5utse8HsOrmVcVeQPfog3auzy8TajG4z2Hgxp /gMONXQTG4Wm/dMbKetZimlSAal9exAMvMiVaAy7vQzcWQFVKHaH3DsJBuJAdzltKP/w eXdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=kCh0Iuj9nmCyaztMAOvG3o5bIkWUSuDDC5HL8wGvlqQ=; fh=HmbUI1sU2zu19WzL6dwW1GNTCyP9+oIx7X/FNRmMYVc=; b=HvL5eLM08H9eFBInRP4esRLf6RfbpmhmDbImtM0UeRBByiY83Bs3KjBLVWQdcB2WLa riYUFVxzcv/8suXXIKQt9uIdYnTCQuX5U2BRkSh8KMJ1Yl1tXwWu9Vjlj9bzgkhpn8Js uSY03tj9IreOePRLzO8oILoNBXjHCF/U7VPoX1M/7ZIQNRyNKoHIQ5hMxqIPZXHrVYxL t7uBDWndkwSDhsHFhgeoOrNL3/gBDTdLz7UcKPhu80luW72/tdK4aJahgGMeE8vwMnNO TnTaoTeQziKbjkbNzWJ528AxQkcsksuRMYl2pcLd6GoA7Yh/F19Y8XfP7EYR0z7Gg+ch CYoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Uq7Qf1Rb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bx26-20020a056a00429a00b006cc03f4e54bsi2888354pfb.393.2023.12.05.00.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:13:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Uq7Qf1Rb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 923968040EF1; Tue, 5 Dec 2023 00:13:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231743AbjLEINK (ORCPT + 99 others); Tue, 5 Dec 2023 03:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234856AbjLEING (ORCPT ); Tue, 5 Dec 2023 03:13:06 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C699192; Tue, 5 Dec 2023 00:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701763991; x=1733299991; h=date:from:to:cc:subject:message-id:reply-to:references: mime-version:in-reply-to; bh=+5S4F3T/FBDoxciqj9rGoi4n0Xagz4XSh13nmg+mktk=; b=Uq7Qf1RbDBwdNnTRTyDazhTfI+I00U9aGN9VEs78OrzmCyPdfYHl5vxM MTawhsKgMtu3zDeNbo535aisirfXVmPZKnCf2Zt03zNA6nylwV8yYXJvt SyiAAOSQ+cJbKW4wmFGZVCBKC8l3b9urYUrl55CH87WOAiZs5dn9ov7IE 3/NonXjDERdSzbeLT1wsre2IEbZVLz+vHm22/xsl3gaboE0WToAaaFgvn 192iVHEyGJ8VqG3lFOiJCrQWnLtZeI4IHro//O46yM/b3l/Fjq/GGfQYH 6jykj6I/s6KAzum8MgU+N/6mfZGyTrkta9KTwygmQhS2g5VzSQ9d/43dS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="425020290" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="asc'?scan'208";a="425020290" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 00:13:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1102374087" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="asc'?scan'208";a="1102374087" Received: from debian-skl.sh.intel.com (HELO debian-skl) ([10.239.160.45]) by fmsmga005.fm.intel.com with ESMTP; 05 Dec 2023 00:13:06 -0800 Date: Tue, 5 Dec 2023 16:12:08 +0800 From: Zhenyu Wang To: Dinghao Liu Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Colin Ian King , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf/x86/uncore: fix a potential double-free in uncore_type_init Message-ID: Reply-To: Zhenyu Wang References: <20231205032709.9525-1-dinghao.liu@zju.edu.cn> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/cosUcUmE3dfT48V" Content-Disposition: inline In-Reply-To: <20231205032709.9525-1-dinghao.liu@zju.edu.cn> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 00:13:23 -0800 (PST) --/cosUcUmE3dfT48V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023.12.05 11:27:09 +0800, Dinghao Liu wrote: > When kzalloc for pmus[i].boxes fails, we should clean up pmus > to prevent memleak. However, when kzalloc for attr_group fails, > pmus has been assigned to type->pmus, and freeing will be done > later on by the callers. The chain is: uncore_type_init -> > uncore_types_init -> uncore_pci_init -> uncore_types_exit -> > uncore_type_exit. Therefore, freeing pmus in uncore_type_init > may cause a double-free. Fix this by setting type->pmus to > NULL after kfree. Change is ok but the call trace you wrote here is reversed or malformed?? With that fixed or cleared. Reviewed-by: Zhenyu Wang >=20 > Fixes: 629eb703d3e4 ("perf/x86/intel/uncore: Fix memory leaks on allocati= on failures") > Signed-off-by: Dinghao Liu > --- > arch/x86/events/intel/uncore.c | 1 + > 1 file changed, 1 insertion(+) >=20 > diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncor= e.c > index 01023aa5125b..d80445a24011 100644 > --- a/arch/x86/events/intel/uncore.c > +++ b/arch/x86/events/intel/uncore.c > @@ -1041,6 +1041,7 @@ static int __init uncore_type_init(struct intel_unc= ore_type *type, bool setid) > for (i =3D 0; i < type->num_boxes; i++) > kfree(pmus[i].boxes); > kfree(pmus); > + type->pmus =3D NULL; > =20 > return -ENOMEM; > } > --=20 > 2.17.1 >=20 --/cosUcUmE3dfT48V Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQTXuabgHDW6LPt9CICxBBozTXgYJwUCZW7bUwAKCRCxBBozTXgY J/bDAKCOA0aNY/nPoT08vmvKOA1I+3JF7QCgi4vd8mjY23YX1OMaIspmA7NwJLI= =n/Bj -----END PGP SIGNATURE----- --/cosUcUmE3dfT48V--