Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp40581rdb; Mon, 4 Dec 2023 19:37:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiI61EdV2UleFFu+7JJ8NxoW2EN1LmDH3GkWd/TRfpqmgvN0DZIM+YiyD/4m/VAOoXQ1Rm X-Received: by 2002:a05:6a20:3d1c:b0:15d:4cf1:212e with SMTP id y28-20020a056a203d1c00b0015d4cf1212emr1090504pzi.4.1701747476015; Mon, 04 Dec 2023 19:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701747475; cv=none; d=google.com; s=arc-20160816; b=bZ+hNsW+agOnGCUGAaQwGHPqV82/5GDCzpjIE0JqPx0FRtQk+eO2IuYFU3KTI2/YXT 99TsBq9F7fBiwbL4z7a1EeV9iB2lDmRPYdb6SSdul3nGrJws1LUvZwLE80Drn/5wE57l sc1pVEf4TN8xk0grg52ND3RAAYlxv6H23EKlJBIa9Q0RbMDusDrhNl4c2Bxfp3CnQU9t Wt84oBRlKn10SrbekwEZnZAuJ3vnmuFyv8wNufWDcig0bzWYzOxWCY1I8haeqZ1ytcEB iXqVp5AK5yOf2VbpODcsVRZ3Fm6J/1hOFkGMVKJrrBggMlMznslcSi+bgqaDjiBeUekN S/4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=sxjGVA6Eyn3d+SyeuQ0zb2721MNPFOp5FMQ1fKaUtdI=; fh=yuZm4u8hK5dqS9NGz1/Md+oh1X+xqTLWI0u2DRVcoFw=; b=J/0PDLBxx30pCewaUX6hu8xGkojo2aG0uxc5gkug+CucV4npi1coeBvxfhfSSBtDIM GiBqymdAvQvIjWDkgUyRxUu0jP0UZ3o02K6BNgZjZkzrAahifipJYl492FY1ksFdYroV L4CyVwJrLNrskUN2YYsAszHbxlnbB3zeCDQFyPNDE5o0cQoQ7fSTmlpD/3pLM7B285mt i9BxeiS4NuvBRmw88KriqDOLVy8XbXNXr/u3gC/Eu5fKTYp1hu+GfXnlUwQYoduIm84D Gm+T/LBerHPlSBrd/rsdjhCgLyu/YDjQyv4qxiY/UDL82RuQM+gsQPNIzCLXWpNex6/q t2vw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w4-20020a63d744000000b005c2203bfc01si9218919pgi.170.2023.12.04.19.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 19:37:55 -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; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DBA2B80AD942; Mon, 4 Dec 2023 19:37:53 -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 S1344208AbjLEDhj (ORCPT + 99 others); Mon, 4 Dec 2023 22:37:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbjLEDhi (ORCPT ); Mon, 4 Dec 2023 22:37:38 -0500 X-Greylist: delayed 71681 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 04 Dec 2023 19:37:41 PST Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.231.56.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6AC95B4 for ; Mon, 4 Dec 2023 19:37:41 -0800 (PST) Received: from localhost.localdomain (unknown [10.190.70.5]) by mail-app2 (Coremail) with SMTP id by_KCgBHvdS4mG5l3TBKAA--.35678S4; Tue, 05 Dec 2023 11:28:00 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn 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: [PATCH] perf/x86/uncore: fix a potential double-free in uncore_type_init Date: Tue, 5 Dec 2023 11:27:09 +0800 Message-Id: <20231205032709.9525-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgBHvdS4mG5l3TBKAA--.35678S4 X-Coremail-Antispam: 1UD129KBjvdXoW7JFWfGr13Aw17Aw47AryrJFb_yoWkArX_WF 1UJaykJr4Ska95W348AFW5Grn7Kw48Z3yrGr1FqF4kAry5tF1DCFs7Gr9ayw4xWrWDZFW8 ArZxKr1jvw18AjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbskFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AK wVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20x vE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4UJVW0owA2z4x0Y4vEx4A2 jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52 x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWU GwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY 0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26r4fKr1UJr1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E 87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjfUoOJ5UUUUU X-CM-SenderInfo: qrrzjiaqtzq6lmxovvfxof0/1tbiAgoTBmVsUQg4xgAMs- X-Spam-Status: No, score=-0.8 required=5.0 tests=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, 04 Dec 2023 19:37:54 -0800 (PST) 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 --- 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; } -- 2.17.1