Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Zenghui Yu <yuzenghui@huawei.com>
To: Guanrui Huang <guanrui.huang@linux.alibaba.com>
Cc: <maz@kernel.org>, <shannon.zhao@linux.alibaba.com>,
	<tglx@linutronix.de>, <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] irqchip/gic-v3-its: Fix double free on error
Date: Thu, 21 Mar 2024 20:43:32 +0800	[thread overview]
Message-ID: <aac642a4-85a1-6df4-1192-638ce0d5086e@huawei.com> (raw)
In-Reply-To: <20240321110454.89410-1-guanrui.huang@linux.alibaba.com>

On 2024/3/21 19:04, 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 checking if bitmap is empty in its_vpe_irq_domain_alloc.
> If bitmap is empty and i > 0, means that bitmap have been clear and free
> in its_vpe_irq_domain_free.
> 
> Signed-off-by: Guanrui Huang <guanrui.huang@linux.alibaba.com>
> ---
>  drivers/irqchip/irq-gic-v3-its.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index fca888b36680..98a1be90caef 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -4562,9 +4562,14 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virq
>  	}
>  
>  	if (err) {
> -		if (i > 0)
> +		if (i > 0) {
>  			its_vpe_irq_domain_free(domain, virq, i);
>  
> +			/* bitmap and vprop_page be freed in its_vpe_irq_domain_free */
> +			if (bitmap_empty(bitmap, nr_ids))

It looks like that 'bitmap' can't be non-empty if you managed to get
here. Right?

> +				return err;
> +		}
> +
>  		its_lpi_free(bitmap, base, nr_ids);
>  		its_free_prop_table(vprop_page);
>  	}

Is it possible that we handle these 2 cases together? I.e., does the
following approach help?

if (err)
	its_vpe_irq_domain_free(domain, virq, i);

Thanks,
Zenghui

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-03-21 12:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 11:04 [PATCH] irqchip/gic-v3-its: Fix double free on error Guanrui Huang
2024-03-21 12:43 ` Zenghui Yu [this message]
2024-03-22  2:38   ` huangguanrui.hgr
2024-03-26  9:43     ` Zenghui Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aac642a4-85a1-6df4-1192-638ce0d5086e@huawei.com \
    --to=yuzenghui@huawei.com \
    --cc=guanrui.huang@linux.alibaba.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=shannon.zhao@linux.alibaba.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox