All of lore.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: shao.mingyin@zte.com.cn
Cc: dlemoal@kernel.org, linux-ide@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] ata: ahci_dwc: reject invalid device tree port numbers
Date: Mon, 9 Nov 2026 16:19:56 +0100	[thread overview]
Message-ID: <avHknBRJnZPpAIke@ryzen> (raw)
In-Reply-To: <20261104221318841yKO89PGcSNeaV4KutBOUJ@zte.com.cn>

On Wed, Nov 04, 2026 at 10:13:18PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> ahci_dwc_init_dmacr() reads the "reg" property of every available child
> node and uses it directly as a port number, both to compute the port
> MMIO base and as an index into dpriv->dmacr[], which has AHCI_MAX_PORTS
> entries.  ahci_platform_get_resources(), which runs earlier, checks the
> same property against hpriv->nports and skips invalid child nodes, but
> this second walk does not.
> 
> A device tree that describes one valid port and one port with a "reg"
> value above AHCI_MAX_PORTS therefore makes the driver write past
> dpriv->dmacr[] and access MMIO beyond the mapped region.  Apply the same
> check as the resource loop and skip invalid child nodes with a warning.
> 
> Fixes: 33629d35090f ("ata: ahci: Add DWC AHCI SATA controller support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
> Tested on 7.3.0-next-20261030 (QEMU/TCG arm64 guest, KASAN) with a
> TEST-ONLY device tree.  The DT adds a snps,dwc-ahci node with port@0
> and port@100; the TEST-ONLY printk hook in ahci_dwc_init_dmacr() is
> applied to both kernels.  mem=512M keeps the fake MMIO window outside
> System RAM.
> 
>   unpatched                            patched
>   KASAN: slab-out-of-bounds            no KASAN report
>   in ahci_dwc_probe                    port 100 skipped, boot
> 
> diff --git a/drivers/ata/ahci_dwc.c b/drivers/ata/ahci_dwc.c
> index feb8a8539b8e..9094eb19e19f 100644
> --- a/drivers/ata/ahci_dwc.c
> +++ b/drivers/ata/ahci_dwc.c
> @@ -225,6 +225,12 @@ static int ahci_dwc_init_dmacr(struct ahci_host_priv *hpriv)
>  		if (of_property_read_u32(child, "reg", &port))
>  			return -EINVAL;
>  
> +		if (port >= hpriv->nports) {
> +			dev_warn(&dpriv->pdev->dev,
> +				 "invalid port number %u\n", port);
> +			continue;
> +		}

Again, this warning is reduntant, as it is already printed by
ahci_platform_get_resources().

Perhaps:
--- a/drivers/ata/ahci_dwc.c
+++ b/drivers/ata/ahci_dwc.c
@@ -225,6 +225,10 @@ static int ahci_dwc_init_dmacr(struct ahci_host_priv *hpriv)
             if (of_property_read_u32(child, "reg", &port))
                     return -EINVAL;

+            /* Already reported by ahci_platform_get_resources() */
+            if (port >= hpriv->nports)
+                    continue;
+
             port_mmio = __ahci_port_base(hpriv, port);


And please send this as a patch 2/2 with the libahci_platform patch as a
patch 1/2.


Kind regards,
Niklas

  parent reply	other threads:[~2026-11-09 15:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 14:13 [PATCH] ata: ahci_dwc: reject invalid device tree port numbers shao.mingyin
2026-11-05  3:05 ` Damien Le Moal
2026-11-09 15:19 ` Niklas Cassel [this message]
2026-11-09 16:02   ` shao.mingyin
2026-11-09 19:47     ` Niklas Cassel
2026-11-10  2:07       ` shao.mingyin

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=avHknBRJnZPpAIke@ryzen \
    --to=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shao.mingyin@zte.com.cn \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.