mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sh: intc: use after free in register_intc_controller()
@ 2024-10-23  8:41 Dan Carpenter
  2024-11-30 12:37 ` John Paul Adrian Glaubitz
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2024-10-23  8:41 UTC (permalink / raw)
  To: Magnus Damm
  Cc: Yoshinori Sato, Rich Felker, John Paul Adrian Glaubitz,
	Ricardo B. Marliere, Greg Kroah-Hartman, Paul Mundt, linux-sh,
	linux-kernel, kernel-janitors

In the error handling, for this function, we kfree(d) without ever
removing it from the &intc_list which would lead to a use after free.  To
fix this, lets 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>
---
This patch is highly speculative and I am not able to test it.  Please,
review with care.

 drivers/sh/intc/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index 74350b5871dc..ea571eeb3078 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -209,7 +209,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);
@@ -369,6 +368,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;
-- 
2.45.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sh: intc: use after free in register_intc_controller()
  2024-10-23  8:41 [PATCH] sh: intc: use after free in register_intc_controller() Dan Carpenter
@ 2024-11-30 12:37 ` John Paul Adrian Glaubitz
  0 siblings, 0 replies; 2+ messages in thread
From: John Paul Adrian Glaubitz @ 2024-11-30 12:37 UTC (permalink / raw)
  To: Dan Carpenter, Magnus Damm
  Cc: Yoshinori Sato, Rich Felker, Ricardo B. Marliere,
	Greg Kroah-Hartman, Paul Mundt, linux-sh, linux-kernel,
	kernel-janitors

On Wed, 2024-10-23 at 11:41 +0300, Dan Carpenter wrote:
> In the error handling, for this function, we kfree(d) without ever
> removing it from the &intc_list which would lead to a use after free.  To
> fix this, lets 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>
> ---
> This patch is highly speculative and I am not able to test it.  Please,
> review with care.
> 
>  drivers/sh/intc/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
> index 74350b5871dc..ea571eeb3078 100644
> --- a/drivers/sh/intc/core.c
> +++ b/drivers/sh/intc/core.c
> @@ -209,7 +209,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);
> @@ -369,6 +368,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;

I think this approach is more sensible than the one suggested by Ridong Chen
and I'm therefor egoing to pick this one over the other solution.

Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-30 12:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-23  8:41 [PATCH] sh: intc: use after free in register_intc_controller() Dan Carpenter
2024-11-30 12:37 ` John Paul Adrian Glaubitz

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®