mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] irqchip/gic-v3-its: Fix double free on error
@ 2024-04-12  2:15 Guanrui Huang
  2024-04-12  3:05 ` Zenghui Yu
  2024-04-15 13:06 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Guanrui Huang @ 2024-04-12  2:15 UTC (permalink / raw)
  To: maz
  Cc: yuzenghui, shannon.zhao, tglx, linux-arm-kernel, linux-kernel,
	Guanrui Huang

In its_vpe_irq_domain_alloc, when its_vpe_init() returns an error
with i > 0, its_vpe_irq_domain_free may free bitmap and vprop_page,
and then there is a double free in its_vpe_irq_domain_alloc.

Fix it by calling its_vpe_irq_domain_free directly, bitmap and
vprop_page will be freed in this function.

Signed-off-by: Guanrui Huang <guanrui.huang@linux.alibaba.com>
---
 drivers/irqchip/irq-gic-v3-its.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index fca888b36680..55c83e19719d 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -4521,8 +4521,6 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
 	struct page *vprop_page;
 	int base, nr_ids, i, err = 0;
 
-	BUG_ON(!vm);
-
 	bitmap = its_lpi_alloc(roundup_pow_of_two(nr_irqs), &base, &nr_ids);
 	if (!bitmap)
 		return -ENOMEM;
@@ -4561,13 +4559,8 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
 		irqd_set_resend_when_in_progress(irq_get_irq_data(virq + i));
 	}
 
-	if (err) {
-		if (i > 0)
-			its_vpe_irq_domain_free(domain, virq, i);
-
-		its_lpi_free(bitmap, base, nr_ids);
-		its_free_prop_table(vprop_page);
-	}
+	if (err)
+		its_vpe_irq_domain_free(domain, virq, i);
 
 	return err;
 }
-- 
2.36.1


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

* Re: [PATCH v3] irqchip/gic-v3-its: Fix double free on error
  2024-04-12  2:15 [PATCH v3] irqchip/gic-v3-its: Fix double free on error Guanrui Huang
@ 2024-04-12  3:05 ` Zenghui Yu
  2024-04-15 13:06 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Zenghui Yu @ 2024-04-12  3:05 UTC (permalink / raw)
  To: Guanrui Huang; +Cc: maz, shannon.zhao, tglx, linux-arm-kernel, linux-kernel

Hi Guanrui,

On 2024/4/12 10:15, Guanrui Huang wrote:
> In its_vpe_irq_domain_alloc, when its_vpe_init() returns an error
> with i > 0, its_vpe_irq_domain_free may free bitmap and vprop_page,
> and then there is a double free in its_vpe_irq_domain_alloc.
> 
> Fix it by calling its_vpe_irq_domain_free directly, bitmap and
> vprop_page will be freed in this function.
> 
> Signed-off-by: Guanrui Huang <guanrui.huang@linux.alibaba.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index fca888b36680..55c83e19719d 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -4521,8 +4521,6 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
>  	struct page *vprop_page;
>  	int base, nr_ids, i, err = 0;
>  
> -	BUG_ON(!vm);
> -

The BUG_ON() is indeed useless, though it'd be better to remove it in a
separate patch, with a commit message explaining why it is not needed.

>  	bitmap = its_lpi_alloc(roundup_pow_of_two(nr_irqs), &base, &nr_ids);
>  	if (!bitmap)
>  		return -ENOMEM;
> @@ -4561,13 +4559,8 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
>  		irqd_set_resend_when_in_progress(irq_get_irq_data(virq + i));
>  	}
>  
> -	if (err) {
> -		if (i > 0)
> -			its_vpe_irq_domain_free(domain, virq, i);
> -
> -		its_lpi_free(bitmap, base, nr_ids);
> -		its_free_prop_table(vprop_page);
> -	}
> +	if (err)
> +		its_vpe_irq_domain_free(domain, virq, i);

This looks good,

Reviewed-by: Zenghui Yu <yuzenghui@huawei.com>

Thanks for the fix.

Zenghui

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

* Re: [PATCH v3] irqchip/gic-v3-its: Fix double free on error
  2024-04-12  2:15 [PATCH v3] irqchip/gic-v3-its: Fix double free on error Guanrui Huang
  2024-04-12  3:05 ` Zenghui Yu
@ 2024-04-15 13:06 ` Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2024-04-15 13:06 UTC (permalink / raw)
  To: Guanrui Huang, linux-arm-kernel, kernel-janitors, Marc Zyngier,
	Zenghui Yu
  Cc: LKML, Shannon Zhao, Thomas Gleixner

> In its_vpe_irq_domain_alloc, when its_vpe_init() returns an error
> with i > 0, its_vpe_irq_domain_free may free bitmap and vprop_page,
> and then there is a double free in its_vpe_irq_domain_alloc.
>
> Fix it by calling its_vpe_irq_domain_free directly, bitmap and
> vprop_page will be freed in this function.

I find this change description improvable.

Would you like to add the tag “Fixes” accordingly?


…
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -4521,8 +4521,6 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
>  	struct page *vprop_page;
>  	int base, nr_ids, i, err = 0;
>
> -	BUG_ON(!vm);
…

Please improve the patch granularity.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc4#n81

Regards,
Markus

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

end of thread, other threads:[~2024-04-15 13:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12  2:15 [PATCH v3] irqchip/gic-v3-its: Fix double free on error Guanrui Huang
2024-04-12  3:05 ` Zenghui Yu
2024-04-15 13:06 ` Markus Elfring

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®