Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3877746rdb; Mon, 11 Dec 2023 02:41:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMoKvBetvX0cFTMdIajNHAO8LDa5nAr4ZA2Lpm0kuW8BTmEJN8pxn8Vy+Wqk2H4ER1zbW9 X-Received: by 2002:a17:903:187:b0:1cc:449b:689e with SMTP id z7-20020a170903018700b001cc449b689emr5276750plg.20.1702291293234; Mon, 11 Dec 2023 02:41:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702291293; cv=none; d=google.com; s=arc-20160816; b=DOkQcs72y5zkvLfvKyzmUmREsTIUCV5rWyaCbn/PxKxBzB7tkOq3NYnYGBb/pDRSff nuH8omkk2W7fz+OiOZcN1j7W1llLZrScE+tJRZ5rcyL3dp6heoRPB5WRTlKGv8AfyjQl FhOfXQXBaH3QvGZXAkP3T9Pxy9Jy46je4kZkO6dsLks8P6Sbj4WMjmvVWLGTcfjZExso r3JPQNriN9bbCnwL6FG3nW0KXWrSOKGLl6eA1r8x4YJzINExmwA1vS3uVyaa6re6ZAZb 27jyTUGe15shMaxegObs1KZpz7UO2uyCM0ITujzC+ZtBqJ+LpltW0vwuA3iDU7ClKDgE +Bkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=c0FIMVi9RUhWFUDDZY1aYoL1gur1Wu7HwuUFG2jAgXk=; fh=jtqErQ+m5GwZ5EmwIM4mndOkIPEoU4F4EM/Onzp+/vk=; b=vD7Gny1mBuu5Qd+4TLrPhbienHmU9A/31LHfnMw02BQ0SvSOSMYEXuO57AGy6s+Pwr Pyf0wEG+jzYzCB2YsWKC7M+/7ORKKkrsdKFUbUqlWr4shFCi1ax9NCzqzcXrmkftzJHE d0KdbCONa3aoIC8qCc1EATczglnj+zBgYJeG0LFOlOWpwtnNNgeGumzwwqsDIjisPa9S wKP+ib5RoMXbvAnfqbSQID1gs3GVAhDbxuta7fGzDhO+O0xlGV7y7kTZSz6SW7R6VbdW jTAns1406lGBGot/Hetbl4wf6VD7naPNr9djF/YJNbadz9/0IetxefL10IJ2VsVgVv1l zqXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="hDJDrPU/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u4-20020a17090282c400b001cfb4a3f2acsi5756154plz.11.2023.12.11.02.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 02:41:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="hDJDrPU/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 78BC180784F1; Mon, 11 Dec 2023 02:40:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234274AbjLKKke (ORCPT + 99 others); Mon, 11 Dec 2023 05:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234271AbjLKKk1 (ORCPT ); Mon, 11 Dec 2023 05:40:27 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68829D0; Mon, 11 Dec 2023 02:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702291233; x=1733827233; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=vyMlyPXqIZPj+eVxK9tCvSg1sTCHGTpqVhNwzAXe5W0=; b=hDJDrPU/+mwALc1t2ldK8WuQgB2ofylTFh/WsJ5djZbnJmtOQ642v5nu +5M98Kw2znrjVQ0SiJflHGoPY+74x2y6Oo7GTTiWDQO74oXAtSltw63Ov QcInb67I1ARqTdHCr1XVu19sUCDwa6LgjKWqA8hS+JL+bZRtZuqXffcsa JTxD2Z0FPknud0B6HAvurq9n/xw7MV+G5w4/Y3oTEsstzzotlDs5g862p 2VSZM+H7u0Z3btCHm33Uzsl8l8/UoRBTOhIH4xbdlawxkFR8MOWOoQ0lF v1jpQA4lWU9d/y2wHZihNUTT5mZ74W8YEAsFzUp0E3+lKVtVdOyybiPHw Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="374133041" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="374133041" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:40:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="21033126" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.46.23]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 02:40:20 -0800 Message-ID: <9e1a5dda-3da8-480b-a804-bc27070fb14d@intel.com> Date: Mon, 11 Dec 2023 12:40:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf/x86/uncore: fix a potential double-free in uncore_type_init Content-Language: en-US To: Dinghao Liu Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , 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 References: <20231205032709.9525-1-dinghao.liu@zju.edu.cn> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <20231205032709.9525-1-dinghao.liu@zju.edu.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 02:40:47 -0800 (PST) On 5/12/23 05:27, 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. > > Fixes: 629eb703d3e4 ("perf/x86/intel/uncore: Fix memory leaks on allocation failures") > Signed-off-by: Dinghao Liu Reviewed-by: Adrian Hunter > --- > arch/x86/events/intel/uncore.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.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_uncore_type *type, bool setid) > for (i = 0; i < type->num_boxes; i++) > kfree(pmus[i].boxes); > kfree(pmus); > + type->pmus = NULL; > > return -ENOMEM; > }