Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/xen: Fix memory leak in xen_init_lock_cpu()

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 <xiujianfeng@huawei.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/20221123155858.11382-3-xiujianfeng@huawei.com
Signed-off-by: Juergen Gross <jgross@suse.com>

authored by

Xiu Jianfeng and committed by
Juergen Gross
ca84ce15 69143f60

+3 -3
+3 -3
arch/x86/xen/spinlock.c
··· 75 75 cpu, per_cpu(lock_kicker_irq, cpu)); 76 76 77 77 name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 78 + per_cpu(irq_name, cpu) = name; 78 79 irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 79 80 cpu, 80 81 dummy_handler, ··· 86 85 if (irq >= 0) { 87 86 disable_irq(irq); /* make sure it's never delivered */ 88 87 per_cpu(lock_kicker_irq, cpu) = irq; 89 - per_cpu(irq_name, cpu) = name; 90 88 } 91 89 92 90 printk("cpu %d spinlock event irq %d\n", cpu, irq); ··· 98 98 if (!xen_pvspin) 99 99 return; 100 100 101 + kfree(per_cpu(irq_name, cpu)); 102 + per_cpu(irq_name, cpu) = NULL; 101 103 /* 102 104 * When booting the kernel with 'mitigations=auto,nosmt', the secondary 103 105 * CPUs are not activated, and lock_kicker_irq is not initialized. ··· 110 108 111 109 unbind_from_irqhandler(irq, NULL); 112 110 per_cpu(lock_kicker_irq, cpu) = -1; 113 - kfree(per_cpu(irq_name, cpu)); 114 - per_cpu(irq_name, cpu) = NULL; 115 111 } 116 112 117 113 PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen);