From: Bjorn Helgaas <helgaas@kernel.org>
To: Hans Zhang <18255117159@163.com>
Cc: lpieralisi@kernel.org, jingoohan1@gmail.com, mani@kernel.org,
kwilczynski@kernel.org, bhelgaas@google.com, robh@kernel.org,
ilpo.jarvinen@linux.intel.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 1/2] PCI: of: Remove max-link-speed generation validation
Date: Tue, 10 Mar 2026 17:37:17 -0500 [thread overview]
Message-ID: <20260310223717.GA835760@bhelgaas> (raw)
In-Reply-To: <20260308142629.75392-2-18255117159@163.com>
On Sun, Mar 08, 2026 at 10:26:28PM +0800, Hans Zhang wrote:
> The of_pci_get_max_link_speed() function currently validates the
> "max-link-speed" DT property to be in the range 1..4 (Gen1..Gen4).
> This imposes a maintenance burden because each new PCIe generation
> would require updating this validation.
>
> Remove the range check so the function returns the raw property value
> (or a negative error code if the property is missing or malformed).
> Callers must now validate the returned speed against the range they
> support. A subsequent patch adds such validation to the DWC driver,
> which is the primary user of this function.
>
> This change allows future PCIe generations to be supported without
> modifying drivers/pci/of.c.
>
> Signed-off-by: Hans Zhang <18255117159@163.com>
> Acked-by: Manivannan Sadhasivam <mani@kernel.org>
Mani's right that we shouldn't have a window without any validation.
I hope I didn't otherwise.
> ---
> drivers/pci/of.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/of.c b/drivers/pci/of.c
> index 9f8eb5df279e..cff5fd337c2b 100644
> --- a/drivers/pci/of.c
> +++ b/drivers/pci/of.c
> @@ -889,10 +889,11 @@ EXPORT_SYMBOL_GPL(of_pci_supply_present);
> int of_pci_get_max_link_speed(struct device_node *node)
> {
> u32 max_link_speed;
> + int ret;
>
> - if (of_property_read_u32(node, "max-link-speed", &max_link_speed) ||
> - max_link_speed == 0 || max_link_speed > 4)
> - return -EINVAL;
> + ret = of_property_read_u32(node, "max-link-speed", &max_link_speed);
> + if (ret)
> + return ret;
>
> return max_link_speed;
> }
From AI review (gemini/gemini-3.1-pro-preview):
By removing the upper bounds check here, the returned max_link_speed
value can now be arbitrarily large if configured incorrectly in the
device tree. While the commit message notes that a subsequent patch
adds validation to the DWC driver, there are several other callers
in the tree that assume the returned value is bounded. These drivers
remain vulnerable to out-of-bounds accesses and hardware
misconfiguration at the end of this patch series.
For example, in drivers/pci/controller/pcie-rzg3s-host.c, the
returned value is used directly as an array index. Could this cause
an out-of-bounds read on pcie_link_speed[]?
I think this is a valid concern, and I think we should protect
pcie_link_speed[] by making it static and accessing it via a function
that validates the index. It's too hard to enforce validation at
every place that uses it.
I think you're going to have to:
- Validate every use of dw_pcie.max_link_speed (set from
of_pci_get_max_link_speed()) in the dwc glue drivers
- Validate the return from of_pci_get_max_link_speed() at every
other caller. It looks like j721e_pcie_set_link_speed(),
brcm_pcie_probe(), mtk_pcie_setup(), rzg3s_pcie_probe() would need
that.
Right now we validate inside of_pci_get_max_link_speed(), which can
help avoid generic problems like indexing pcie_link_speed[], but it
can't account for individual driver restrictions. So I do still think
you're right to move it from drivers/pci/of.c to the individual
drivers because those drivers are where it's really important, and it
avoids changing a common place for driver-specific reasons. We're
just going to have to strictly enforce it in those drivers.
next prev parent reply other threads:[~2026-03-10 22:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 14:26 [PATCH v7 0/2] " Hans Zhang
2026-03-08 14:26 ` [PATCH v7 1/2] " Hans Zhang
2026-03-09 0:38 ` Shawn Lin
2026-03-09 14:21 ` Hans Zhang
2026-03-09 11:47 ` Manivannan Sadhasivam
2026-03-09 14:47 ` Hans Zhang
2026-03-10 22:37 ` Bjorn Helgaas [this message]
2026-03-12 16:18 ` Hans Zhang
2026-03-08 14:26 ` [PATCH v7 2/2] PCI: dwc: Validate max-link-speed property Hans Zhang
2026-03-08 18:10 ` kernel test robot
2026-03-09 14:45 ` Hans Zhang
2026-03-09 11:11 ` kernel test robot
2026-03-09 15:44 ` kernel test robot
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=20260310223717.GA835760@bhelgaas \
--to=helgaas@kernel.org \
--cc=18255117159@163.com \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jingoohan1@gmail.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@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®