mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Radu Rendec <radu@rendec.net>
To: Haofeng Li <lihaofeng@kylinos.cn>, tglx@kernel.org
Cc: linux-kernel@vger.kernel.org, "Haofeng Li" <13266079573@163.com>,
	"Anup Patel" <anup@brainfault.org>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Björn Töpel" <bjorn@rivosinc.com>,
	linux-riscv@lists.infradead.org
Subject: Re: [PATCH 01/16] irqchip/riscv-imsic: fix MMIO lookup OOB and NULL cleanup
Date: Sat, 25 Jul 2026 12:13:20 -0400	[thread overview]
Message-ID: <7a124c80a48d2ada6ad21c1ac27e9fd888ae1a56.camel@rendec.net> (raw)
In-Reply-To: <20260714122351.3274006-2-lihaofeng@kylinos.cn>

On Tue, 2026-07-14 at 20:23 +0800, Haofeng Li wrote:
> The MSI page lookup loop uses:
> 
> 	for (j = 0; nr_mmios; j++)
> 
> When nr_mmios is non-zero the condition is always true, so j is never
> bounded. If reloff does not fall in any MMIO region the loop indexes
> past mmios[] and may hang or fault.
> 
> Also, mmios_va starts as NULL. If its allocation fails, the out_iounmap
> path indexes mmios_va[i] and NULL-dereferences.
> 
> Bound the loop with j < nr_mmios, and guard the iounmap/kfree cleanup
> with if (mmios_va).
> 
> Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
> Signed-off-by: Haofeng Li <lihaofeng@kylinos.cn>
> ---
>  drivers/irqchip/irq-riscv-imsic-state.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
> index b8d1bbbf42f7..19f74cf79988 100644
> --- a/drivers/irqchip/irq-riscv-imsic-state.c
> +++ b/drivers/irqchip/irq-riscv-imsic-state.c
> @@ -896,7 +896,7 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
>  		index = nr_mmios;
>  		reloff = i * BIT(global->guest_index_bits) *
>  			 IMSIC_MMIO_PAGE_SZ;
> -		for (j = 0; nr_mmios; j++) {
> +		for (j = 0; j < nr_mmios; j++) {
>  			if (reloff < resource_size(&mmios[j])) {
>  				index = j;
>  				break;
> @@ -953,11 +953,13 @@ int __init imsic_setup_state(struct fwnode_handle *fwnode, void *opaque)
>  out_local_cleanup:
>  	imsic_local_cleanup();
>  out_iounmap:
> -	for (i = 0; i < nr_mmios; i++) {
> -		if (mmios_va[i])
> -			iounmap(mmios_va[i]);
> +	if (mmios_va) {
> +		for (i = 0; i < nr_mmios; i++) {
> +			if (mmios_va[i])
> +				iounmap(mmios_va[i]);
> +		}
> +		kfree(mmios_va);
>  	}
> -	kfree(mmios_va);
>  	kfree(mmios);
>  out_free_local:
>  	free_percpu(imsic->global.local);

Reviewed-by: Radu Rendec <radu@rendec.net>

  parent reply	other threads:[~2026-07-25 16:13 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 12:23 [PATCH 00/16] irqchip: harden initialization error paths Haofeng Li
2026-07-14 12:23 ` [PATCH 01/16] irqchip/riscv-imsic: fix MMIO lookup OOB and NULL cleanup Haofeng Li
2026-07-14 13:15   ` Anup Patel
2026-07-25 16:13   ` Radu Rendec [this message]
2026-07-14 12:23 ` [PATCH 02/16] irqchip/loongarch-ir: fix redirect free and alloc leaks Haofeng Li
2026-07-26  2:26   ` Radu Rendec
2026-07-14 13:24 ` [PATCH 03/16] irqchip/sifive-plic: do not iounmap devm mappings Haofeng Li
2026-07-14 15:05   ` Anup Patel
2026-08-20  6:36   ` Thomas Gleixner
     [not found] ` <20260714132453.3302672-1-920484857@qq.com>
2026-07-14 13:24   ` [PATCH 04/16] irqchip/crossbar: fix allocation and init cleanup Haofeng Li
2026-08-02 15:12     ` Radu Rendec
2026-08-20  6:52     ` Thomas Gleixner
2026-07-14 13:24   ` [PATCH 05/16] irqchip/bcm7038-l1: clean up init failure paths Haofeng Li
2026-07-28 17:36     ` Florian Fainelli
2026-07-14 13:24   ` [PATCH 06/16] irqchip/loongson-liointc: unmap per-core iomaps on error Haofeng Li
2026-08-02 16:31     ` Radu Rendec
2026-07-14 13:24   ` [PATCH 07/16] irqchip/mips-gic: clean up IRQ domain creation failure Haofeng Li
2026-08-02 19:19     ` Radu Rendec
2026-07-14 13:24   ` [PATCH 08/16] irqchip/mips-gic: clean up if IPI domain registration fails Haofeng Li
2026-08-02 19:26     ` Radu Rendec
2026-07-14 13:24   ` [PATCH 09/16] irqchip/econet: clean up VEIC initialization Haofeng Li
2026-07-23  1:09     ` Caleb James DeLisle
2026-07-14 13:24   ` [PATCH 10/16] irqchip/aspeed-vic: publish handler only after domain creation Haofeng Li
2026-07-14 13:24   ` [PATCH 11/16] irqchip/loongson-eiointc: preserve live state on cascade failure Haofeng Li
2026-07-14 13:24   ` [PATCH 12/16] irqchip/realtek-rtl: unmap per-CPU bases on init failure Haofeng Li
2026-07-15  6:12     ` AW: " Markus Stockhausen
2026-07-14 13:24   ` [PATCH 13/16] irqchip/realtek-rtl: dispose parent mapping on domain failure Haofeng Li
2026-07-14 13:24   ` [PATCH 14/16] irqchip/renesas-rzg2l: fix wrong errno in reset error log Haofeng Li
2026-07-14 13:24   ` [PATCH 15/16] irqchip/gic-v3: fail T241 quirk if alias ioremap fails Haofeng Li
2026-07-14 14:53     ` Marc Zyngier
2026-07-14 13:24   ` [PATCH 16/16] irqchip/bcm7120-l2: fix parent IRQ count error handling Haofeng Li
2026-07-28 15:57     ` Florian Fainelli
2026-07-25 16:29 ` [PATCH 00/16] irqchip: harden initialization error paths Radu Rendec
2026-08-20  7:49 ` Thomas Gleixner
2026-09-05  4:11   ` Nam Cao

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=7a124c80a48d2ada6ad21c1ac27e9fd888ae1a56.camel@rendec.net \
    --to=radu@rendec.net \
    --cc=13266079573@163.com \
    --cc=alex@ghiti.fr \
    --cc=anup@brainfault.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=bjorn@rivosinc.com \
    --cc=lihaofeng@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=tglx@kernel.org \
    /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

all inboxes | Powered by JetHome®