]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sh: intc: Fix use-after-free bug in register_intc_controller()
authorDan Carpenter <dan.carpenter@linaro.org>
Wed, 23 Oct 2024 08:41:59 +0000 (11:41 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2024 09:59:42 +0000 (10:59 +0100)
[ Upstream commit 63e72e551942642c48456a4134975136cdcb9b3c ]

In the error handling for this function, d is freed without ever
removing it from intc_list which would lead to a use after free.
To fix this, let's only add it to the list after everything has
succeeded.

Fixes: 2dcec7a988a1 ("sh: intc: set_irq_wake() support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/sh/intc/core.c

index 46f0f322d4d8f7d4c2b4d373d74da5d58c8774d5..48fe5fab5693d9f16cc792e7c922fddefc2354e4 100644 (file)
@@ -194,7 +194,6 @@ int __init register_intc_controller(struct intc_desc *desc)
                goto err0;
 
        INIT_LIST_HEAD(&d->list);
-       list_add_tail(&d->list, &intc_list);
 
        raw_spin_lock_init(&d->lock);
        INIT_RADIX_TREE(&d->tree, GFP_ATOMIC);
@@ -380,6 +379,7 @@ int __init register_intc_controller(struct intc_desc *desc)
 
        d->skip_suspend = desc->skip_syscore_suspend;
 
+       list_add_tail(&d->list, &intc_list);
        nr_intc_controllers++;
 
        return 0;