Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7646484rwb; Wed, 23 Nov 2022 09:01:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5MRj/E49fwZoOs3FfpcMJlka6/BJTjfKMd8nSMHlh+W2UPRbrGvf77kLddaQ3efZNe0Xn8 X-Received: by 2002:a17:906:9da4:b0:7ae:100a:8dc0 with SMTP id fq36-20020a1709069da400b007ae100a8dc0mr23448712ejc.424.1669222901888; Wed, 23 Nov 2022 09:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669222901; cv=none; d=google.com; s=arc-20160816; b=qTA1EXiXg0Jt5FmjHNdzYcPqGOaTHBNREW1B/n+6x/qyPluIXEYnEDbysoavbkwfVY 54y8AD5UP6RGG04AsAPKCdqLRBG3kldD3ZLpu5amG5oPBwVthnkzjaCmirI4iOpBj6dM reiHpPvGTaOHYOF1LgvEDZPhIP+N+zCMoIhnTwdtI7rql8qLAOayp+WQgXMD77AvLBa9 +zeR2Ob3LU/ZRUoT8z+jky+/KXcKHhKCJ+Hil2ZPReC88lgXUbHP5bHMCjyK5TQBtP4s cu8408lHQ56rQ4y/rHmBjnZRgoMCd5SaO1dWKruK2wCZP0E1sDJJMrp2qq20G5n4TJvD sceA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=To62y6QkhaWyW1JO6g3IuAtzrmtlvDI7Gl6nK1Ar/Bw=; b=r5BWqohzHCMYjMVR+hLX/23QhKuBKN/Vc/cdKNln5k8odDC0LV83HA3aMfJ0ppKify 1U0fUTLoOemlk3N7aOfIAeU9yx5SUNYQqL4BEB3X3zvZGRs4soATr5dsRzQR7ZqHEcJW 0lku27Phy5j4z9vX4FdpdxSyPJlj4UJVMxjvBojTUB+ao1pdcnXTqEKhdi4KGnookFny pZOg4rgVDEA35OhpWd7oY2M4ExVk3GgqriqCsIS9qoXBTMr7Q9lmbhaCZUIWbChXqTHO 497knmH3cENMWmpakbVU2GFdF6H0UTLJcAHnNYS4/eeNXBFcSiVEmXitvdBS/ohdHoni qW1g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a056402359200b00462e23be64fsi378605edc.578.2022.11.23.09.01.17; Wed, 23 Nov 2022 09:01:41 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238543AbiKWQCd (ORCPT + 88 others); Wed, 23 Nov 2022 11:02:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238772AbiKWQCH (ORCPT ); Wed, 23 Nov 2022 11:02:07 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71BFC4C22 for ; Wed, 23 Nov 2022 08:02:05 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHQq14xjjzRpDj; Thu, 24 Nov 2022 00:01:33 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 24 Nov 2022 00:02:03 +0800 From: Xiu Jianfeng To: , , , , , , , CC: , , Subject: [PATCH v2 2/2] x86/xen: Fix memory leak in xen_init_lock_cpu() Date: Wed, 23 Nov 2022 23:58:58 +0800 Message-ID: <20221123155858.11382-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221123155858.11382-1-xiujianfeng@huawei.com> References: <20221123155858.11382-1-xiujianfeng@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 In xen_init_lock_cpu(), the @name has allocated new string by kasprintf(), if bind_ipi_to_irqhandler() fails, it should be freed, otherwise may lead to a memory leak issue, fix it. Fixes: 2d9e1e2f58b5 ("xen: implement Xen-specific spinlocks") Signed-off-by: Xiu Jianfeng --- arch/x86/xen/spinlock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c index 043c73dfd2c9..5c6fc16e4b92 100644 --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -75,6 +75,7 @@ void xen_init_lock_cpu(int cpu) cpu, per_cpu(lock_kicker_irq, cpu)); name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); + per_cpu(irq_name, cpu) = name; irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, cpu, dummy_handler, @@ -85,7 +86,6 @@ void xen_init_lock_cpu(int cpu) if (irq >= 0) { disable_irq(irq); /* make sure it's never delivered */ per_cpu(lock_kicker_irq, cpu) = irq; - per_cpu(irq_name, cpu) = name; } printk("cpu %d spinlock event irq %d\n", cpu, irq); @@ -98,6 +98,8 @@ void xen_uninit_lock_cpu(int cpu) if (!xen_pvspin) return; + kfree(per_cpu(irq_name, cpu)); + per_cpu(irq_name, cpu) = NULL; /* * When booting the kernel with 'mitigations=auto,nosmt', the secondary * CPUs are not activated, and lock_kicker_irq is not initialized. @@ -108,8 +110,6 @@ void xen_uninit_lock_cpu(int cpu) unbind_from_irqhandler(irq, NULL); per_cpu(lock_kicker_irq, cpu) = -1; - kfree(per_cpu(irq_name, cpu)); - per_cpu(irq_name, cpu) = NULL; } PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen); -- 2.17.1