arch: x86: xen: check the return value of kasprintf()
Subsystems (2)
PATCH 1/1 arch: x86: xen: check the return value of kasprintf()
The function kasprintf() can fail, but there is no check of its return value. To fix this bug, its return value should be checked with new error handling code.
--- arch/x86/xen/smp.c | 2 ++ arch/x86/xen/smp_pv.c | 2 ++ arch/x86/xen/spinlock.c | 2 ++ 3 files changed, 6 insertions(+)
arch/x86/xen/smp.c +2 -0
@@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu)char *resched_name, *callfunc_name, *debug_name; resched_name =kasprintf (GFP_KERNEL ,"resched%d" , cpu); +if (!resched_name) +return -ENOMEM ; rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, cpu, xen_reschedule_interrupt,
arch/x86/xen/smp_pv.c +2 -0
@@ -118,6 +118,8 @@ int xen_smp_intr_init_pv(unsigned int cpu)char *callfunc_name, *pmu_name; callfunc_name =kasprintf (GFP_KERNEL ,"irqwork%d" , cpu); +if (!callfunc_name) +return -ENOMEM ; rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR, cpu, xen_irq_work_interrupt,
arch/x86/xen/spinlock.c +2 -0
@@ -75,6 +75,8 @@ void xen_init_lock_cpu(int cpu) cpu, per_cpu(lock_kicker_irq, cpu)); name =kasprintf (GFP_KERNEL ,"spinlock%d" , cpu); +if (!name) +return ; irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, cpu, dummy_handler,
Signature · 1 line
2.17.1
Juergen Gross
maintainerQuoted 20 lines · Jia-Ju Bai
The function
kasprintf()can fail, but there is no check of its return value. To fix this bug, its return value should be checked with new error handling code.Fixes f87e4cac4f4e ("xen: SMP guest support")Fixes 83b96794e0ea ("x86/xen: split off smp_pv.c")Fixes d5de8841355a ("x86: split spinlock implementations out into their own files")Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>--- arch/x86/xen/smp.c | 2 ++ arch/x86/xen/smp_pv.c | 2 ++ arch/x86/xen/spinlock.c | 2 ++ 3 files changed, 6 insertions(+)arch/x86/xen/smp.c +0
-0
arch/x86/xen/smp.c int xen_smp_intr_init(unsigned int cpu) · line 69
Quoted 5 lines
arch/x86/xen/smp.c +2
-0@@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu)char *resched_name, *callfunc_name, *debug_name; resched_name =kasprintf (GFP_KERNEL ,"resched%d" , cpu); +if (!resched_name) +return -ENOMEM ;
There are 3 more instances of kasprintf() in this function.
arch/x86/xen/smp_pv.c int xen_smp_intr_init_pv(unsigned int cpu) · line 122
Quoted 13 lines
arch/x86/xen/smp.c +0
-0rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, cpu, xen_reschedule_interrupt,arch/x86/xen/smp_pv.c +2
-0@@ -118,6 +118,8 @@ int xen_smp_intr_init_pv(unsigned int cpu)char *callfunc_name, *pmu_name; callfunc_name =kasprintf (GFP_KERNEL ,"irqwork%d" , cpu); +if (!callfunc_name) +return -ENOMEM ;
And in here is another one, too.
arch/x86/xen/spinlock.c void xen_init_lock_cpu(int cpu) · line 79
Quoted 13 lines
arch/x86/xen/smp_pv.c +0
-0rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR, cpu, xen_irq_work_interrupt,arch/x86/xen/spinlock.c +2
-0@@ -75,6 +75,8 @@ void xen_init_lock_cpu(int cpu) cpu, per_cpu(lock_kicker_irq, cpu)); name =kasprintf (GFP_KERNEL ,"spinlock%d" , cpu); +if (!name) +return ;
Just failing silently is not nice.
arch/x86/xen/spinlock.c void xen_init_lock_cpu(int cpu) · line 82
Quoted 3 lines
arch/x86/xen/spinlock.c +0
-0irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, cpu, dummy_handler,
Juergen