mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiu Jianfeng <xiujianfeng@huawei.com>
To: <jgross@suse.com>, <boris.ostrovsky@oracle.com>,
	<tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
	<dave.hansen@linux.intel.com>, <hpa@zytor.com>, <jeremy@goop.org>
Cc: <x86@kernel.org>, <xen-devel@lists.xenproject.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] x86/xen: Fix memory leak in xen_smp_intr_init{_pv}()
Date: Sat, 19 Nov 2022 16:59:22 +0800	[thread overview]
Message-ID: <20221119085923.114889-2-xiujianfeng@huawei.com> (raw)
In-Reply-To: <20221119085923.114889-1-xiujianfeng@huawei.com>

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 <xiujianfeng@huawei.com>
---
 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;
 	}
-- 
2.17.1


  reply	other threads:[~2022-11-19  9:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-19  8:59 [PATCH 0/2] x86/xen: Fix memory leak issue Xiu Jianfeng
2022-11-19  8:59 ` Xiu Jianfeng [this message]
2022-11-19  8:59 ` [PATCH 2/2] x86/xen: Fix memory leak in xen_init_lock_cpu() Xiu Jianfeng
2022-11-23 15:23 ` [PATCH 0/2] x86/xen: Fix memory leak issue Juergen Gross
2022-11-23 16:03   ` xiujianfeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221119085923.114889-2-xiujianfeng@huawei.com \
    --to=xiujianfeng@huawei.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®