From patchwork Sat Nov 19 08:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 23242 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp628958wrr; Sat, 19 Nov 2022 01:26:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf61X2aTdZA+xFdKEvpt+HRXSa/312E+pDDcC24UQvvQVi6tPr9YBL7R6eq2XYJakgN9tG9J X-Received: by 2002:a17:902:e849:b0:187:2b22:e2af with SMTP id t9-20020a170902e84900b001872b22e2afmr3343452plg.0.1668850012565; Sat, 19 Nov 2022 01:26:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668850012; cv=none; d=google.com; s=arc-20160816; b=XtAbboScOP1fsK1VKAYiGfvFivEnp1V8pJYmv9WZ8Oi2DlaaF/ECP0blvd8V70SrGa +s0YcJa4vh2q5dTD22yIXWX4aJXIeuYB+nZCe1JbuTn0IC2Su0yVZbUbkV+r5pFcwpll qtssPaSQTVon25gHuvGT1mCbT9SKmIM5ZO0zKzFQoAmT1p2C1Anaw48FMH8J6XzDQoI7 ePV/twrhciYnPueG5kx7KA4G0MHyU5yPiaebljzdtUHyPM/pMCx+WwXLQIFf3wRjQJTB +K2uuMG0MYqAhjpVLAr4HpZHmDddJ2RecJWKHfFRND8loq673ABMwgxHB09brfTZ+2hR tCJQ== 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=4mWeMyTDhyfLNv3OpmNvW3UCwWvf0zOgm78z1t+Q0ks=; b=XWZqpushI0ddjoB1zUw8DK/qcumSk4rIVxTHenwkra4FLZzIBkfjg+1o0zyPTXsKMi H20ANW7SqfVU6c0XuPGQz7sdJZu3sSEwa3N28Gfy49kK+3sm3rJsujdlrmlXZkZxD/F3 NM2zDjaNbpZAQ9ne40luXOu4bjYovoVXIMqLDtPx3knrWaRhuXl5AZ0wuQcyXoBkPGuE Tv6+wpr0tLpvhHj/UBAgTWGmmWmNHLyCLCucptNYhly9XssnY+A+zDh7O9qAhcUYbXFl h6i6Mv7kFGrSreJK38fNM81ZsezOBJvFUT5YeE7NrWm6n1EAGmLkgNdIoMxYfH1gbssY wgiQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r138-20020a632b90000000b0046fabccb7ffsi5938012pgr.494.2022.11.19.01.26.38; Sat, 19 Nov 2022 01:26:52 -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 S232173AbiKSJCh (ORCPT + 99 others); Sat, 19 Nov 2022 04:02:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbiKSJCd (ORCPT ); Sat, 19 Nov 2022 04:02:33 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 509509DBA7 for ; Sat, 19 Nov 2022 01:02:32 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NDndf6QTTzFqQX; Sat, 19 Nov 2022 16:59:18 +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; Sat, 19 Nov 2022 17:02:30 +0800 From: Xiu Jianfeng To: , , , , , , , CC: , , Subject: [PATCH 1/2] x86/xen: Fix memory leak in xen_smp_intr_init{_pv}() Date: Sat, 19 Nov 2022 16:59:22 +0800 Message-ID: <20221119085923.114889-2-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221119085923.114889-1-xiujianfeng@huawei.com> References: <20221119085923.114889-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749916070577536828?= X-GMAIL-MSGID: =?utf-8?q?1749916070577536828?= These local variables @{resched|pmu|callfunc...}_name saves the new string allocated by kasprintf(), and when bind_{v}ipi_to_irqhandler() fails, it goes to the @fail tag, and calls xen_smp_intr_free{_pv}() to free resource, however the new string is not saved, which cause a memory leak issue. fix it. Fixes: 9702785a747a ("i386: move xen") Signed-off-by: Xiu Jianfeng --- arch/x86/xen/smp.c | 16 ++++++++++++---- arch/x86/xen/smp_pv.c | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c index c3e1f9a7d43a..6e9426b6b18a 100644 --- a/arch/x86/xen/smp.c +++ b/arch/x86/xen/smp.c @@ -71,8 +71,10 @@ int xen_smp_intr_init(unsigned int cpu) IRQF_PERCPU|IRQF_NOBALANCING, resched_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(resched_name); goto fail; + } per_cpu(xen_resched_irq, cpu).irq = rc; per_cpu(xen_resched_irq, cpu).name = resched_name; @@ -83,8 +85,10 @@ int xen_smp_intr_init(unsigned int cpu) IRQF_PERCPU|IRQF_NOBALANCING, callfunc_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(callfunc_name); goto fail; + } per_cpu(xen_callfunc_irq, cpu).irq = rc; per_cpu(xen_callfunc_irq, cpu).name = callfunc_name; @@ -94,8 +98,10 @@ int xen_smp_intr_init(unsigned int cpu) xen_debug_interrupt, IRQF_PERCPU | IRQF_NOBALANCING, debug_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(debug_name); goto fail; + } per_cpu(xen_debug_irq, cpu).irq = rc; per_cpu(xen_debug_irq, cpu).name = debug_name; } @@ -107,8 +113,10 @@ int xen_smp_intr_init(unsigned int cpu) IRQF_PERCPU|IRQF_NOBALANCING, callfunc_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(callfunc_name); goto fail; + } per_cpu(xen_callfuncsingle_irq, cpu).irq = rc; per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 480be82e9b7b..228d0207380c 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -124,8 +124,10 @@ int xen_smp_intr_init_pv(unsigned int cpu) IRQF_PERCPU|IRQF_NOBALANCING, callfunc_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(callfunc_name); goto fail; + } per_cpu(xen_irq_work, cpu).irq = rc; per_cpu(xen_irq_work, cpu).name = callfunc_name; @@ -135,8 +137,10 @@ int xen_smp_intr_init_pv(unsigned int cpu) xen_pmu_irq_handler, IRQF_PERCPU|IRQF_NOBALANCING, pmu_name, NULL); - if (rc < 0) + if (rc < 0) { + kfree(pmu_name); goto fail; + } per_cpu(xen_pmu_irq, cpu).irq = rc; per_cpu(xen_pmu_irq, cpu).name = pmu_name; } From patchwork Sat Nov 19 08:59:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 23241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp627306wrr; Sat, 19 Nov 2022 01:21:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf4gKUa+ZudEgo2Lvk3rY3Dut1NGkF33Dx0Jh6wgMEuwOHZwKsXiIAgCzLt5358FghFxiGKY X-Received: by 2002:a63:2017:0:b0:476:7fb0:916f with SMTP id g23-20020a632017000000b004767fb0916fmr9932590pgg.209.1668849675824; Sat, 19 Nov 2022 01:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668849675; cv=none; d=google.com; s=arc-20160816; b=gifoJ6Ka4a/60TCUAYhGnU0M+LI7m6ySqQA3El3aVJWyaO78+uXd7Kj2Dq56Yct9yl MfBvCwU+ar4WdbcrupZoMwkNVbARZHiXEQAXnywpKAn4mqcKG+xLEALvJJBP/HLuGbCQ ni4Ics1AzcY/lk9EEVzq5DNMv/+My9NTljWC48IDI+mjKB++G23omNUIeqBT/kS8xbPI 9AtvHu2Ft0EcExzuEgpLHY85OLnvVY9xWHnEn/rHSjYwjYGxU+eLlioVLGN+NBJoUscm bdGMZS+RG5NME8xBA+RMMWfv6msU2ji2nocYQ0mR+jEgwRhAP2idavvEoXzGNg5DTJPv uvdA== 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=3+idkMbADtGDpPRqk4DEwLrKhcTWkh5ZPEs36uKEKPE=; b=uMNtXLqqAKX/ciRI4kEsew7GUGvkPS94K+GgidteY9daDSRtBbjr3TgXScQTbcXmZW /6fexxhugVKuUs3GJdcqeKDhmiCl8pkPVYTJQWYlEN6jmZ7qiTjG13X3CUs7jixRm3pD EqP8JKlDNwm+fnbK67Ht1FHXTsaQhNlvmlQOMSBK9EQDsPF4JHsSxjcY0/7bguSFXFg5 3APUQvja0ikZ7EbtyLvMkmh06UMCfGAf/feUV7sG10UbwACKoWrfrhVlqHjYnrUP/Jo1 Go03HiLiNMz6RQqBdY0lyVTbb/SHuEXdDzb5iMQ4BvYqNsQleIKLBkeHD6D24D4rOeNz 67og== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a656944000000b00476c6b9cf69si5673424pgq.856.2022.11.19.01.20.57; Sat, 19 Nov 2022 01:21:15 -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 S232579AbiKSJCn (ORCPT + 99 others); Sat, 19 Nov 2022 04:02:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbiKSJCe (ORCPT ); Sat, 19 Nov 2022 04:02:34 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 692619A5DD for ; Sat, 19 Nov 2022 01:02:33 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NDnhk1qhNzHvsQ; Sat, 19 Nov 2022 17:01:58 +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; Sat, 19 Nov 2022 17:02:31 +0800 From: Xiu Jianfeng To: , , , , , , , CC: , , Subject: [PATCH 2/2] x86/xen: Fix memory leak in xen_init_lock_cpu() Date: Sat, 19 Nov 2022 16:59:23 +0800 Message-ID: <20221119085923.114889-3-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221119085923.114889-1-xiujianfeng@huawei.com> References: <20221119085923.114889-1-xiujianfeng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749915717736805339?= X-GMAIL-MSGID: =?utf-8?q?1749915717736805339?= 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c index 043c73dfd2c9..156d3e04c9ef 100644 --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -86,7 +86,8 @@ void xen_init_lock_cpu(int cpu) disable_irq(irq); /* make sure it's never delivered */ per_cpu(lock_kicker_irq, cpu) = irq; per_cpu(irq_name, cpu) = name; - } + } else + kfree(name); printk("cpu %d spinlock event irq %d\n", cpu, irq); }