Skip to content

Commit de4a758

Browse files
author
Mamatha Inamdar
committed
powerpc/xive: Add some error handling code to 'xive_spapr_init()'
JIRA: https://issues.redhat.com/browse/RHEL-80849 CVE: CVE-2022-49437 commit e414e29 Author: Christophe JAILLET <[email protected]> Date: Tue Feb 1 13:31:16 2022 +0100 powerpc/xive: Add some error handling code to 'xive_spapr_init()' 'xive_irq_bitmap_add()' can return -ENOMEM. In this case, we should free the memory already allocated and return 'false' to the caller. Also add an error path which undoes the 'tima = ioremap(...)' Signed-off-by: Christophe JAILLET <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/564998101804886b151235c8a9f93020923bfd2c.1643718324.git.christophe.jaillet@wanadoo.fr Signed-off-by: Mamatha Inamdar <[email protected]>
1 parent 5150d3a commit de4a758

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

arch/powerpc/sysdev/xive/spapr.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ static int xive_irq_bitmap_add(int base, int count)
6969
return 0;
7070
}
7171

72+
static void xive_irq_bitmap_remove_all(void)
73+
{
74+
struct xive_irq_bitmap *xibm, *tmp;
75+
76+
list_for_each_entry_safe(xibm, tmp, &xive_irq_bitmaps, list) {
77+
list_del(&xibm->list);
78+
kfree(xibm->bitmap);
79+
kfree(xibm);
80+
}
81+
}
82+
7283
static int __xive_irq_bitmap_alloc(struct xive_irq_bitmap *xibm)
7384
{
7485
int irq;
@@ -802,7 +813,7 @@ bool __init xive_spapr_init(void)
802813
u32 val;
803814
u32 len;
804815
const __be32 *reg;
805-
int i;
816+
int i, err;
806817

807818
if (xive_spapr_disabled())
808819
return false;
@@ -827,23 +838,26 @@ bool __init xive_spapr_init(void)
827838
}
828839

829840
if (!xive_get_max_prio(&max_prio))
830-
return false;
841+
goto err_unmap;
831842

832843
/* Feed the IRQ number allocator with the ranges given in the DT */
833844
reg = of_get_property(np, "ibm,xive-lisn-ranges", &len);
834845
if (!reg) {
835846
pr_err("Failed to read 'ibm,xive-lisn-ranges' property\n");
836-
return false;
847+
goto err_unmap;
837848
}
838849

839850
if (len % (2 * sizeof(u32)) != 0) {
840851
pr_err("invalid 'ibm,xive-lisn-ranges' property\n");
841-
return false;
852+
goto err_unmap;
842853
}
843854

844-
for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2)
845-
xive_irq_bitmap_add(be32_to_cpu(reg[0]),
846-
be32_to_cpu(reg[1]));
855+
for (i = 0; i < len / (2 * sizeof(u32)); i++, reg += 2) {
856+
err = xive_irq_bitmap_add(be32_to_cpu(reg[0]),
857+
be32_to_cpu(reg[1]));
858+
if (err < 0)
859+
goto err_mem_free;
860+
}
847861

848862
/* Iterate the EQ sizes and pick one */
849863
of_property_for_each_u32(np, "ibm,xive-eq-sizes", prop, reg, val) {
@@ -854,10 +868,16 @@ bool __init xive_spapr_init(void)
854868

855869
/* Initialize XIVE core with our backend */
856870
if (!xive_core_init(np, &xive_spapr_ops, tima, TM_QW1_OS, max_prio))
857-
return false;
871+
goto err_mem_free;
858872

859873
pr_info("Using %dkB queues\n", 1 << (xive_queue_shift - 10));
860874
return true;
875+
876+
err_mem_free:
877+
xive_irq_bitmap_remove_all();
878+
err_unmap:
879+
iounmap(tima);
880+
return false;
861881
}
862882

863883
machine_arch_initcall(pseries, xive_core_debug_init);

0 commit comments

Comments
 (0)