Devicetree
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
To: sashiko-reviews@lists.linux.dev
Cc: Ernest Van Hoecke <ernestvanhoecke@gmail.com>,
	 devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 4/7] of: property: fw_devlink: Follow PWM nexus maps
Date: Fri, 18 Sep 2026 15:54:39 +0200	[thread overview]
Message-ID: <aq1CSswlo57jZpMH@monoceros> (raw)
In-Reply-To: <20260910143106.B457C1F000FF@smtp.kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3280 bytes --]

On Thu, Sep 10, 2026 at 02:31:06PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [Critical] Missing bounds check in `of_parse_phandle_with_args_map` allows a malformed Devicetree to trigger a stack buffer overflow.
> - [High] Missing cycle detection in `of_parse_phandle_with_args_map` allows a malformed Devicetree to cause an infinite loop.
> --
> 
> commit 17ae1bc408452875cfad3c0d990add52c676f9b9
> Author: Ernest Van Hoecke <ernest.vanhoecke@toradex.com>
> 
> of: property: fw_devlink: Follow PWM nexus maps
> 
> PWM consumers use of_parse_phandle_with_args_map() to resolve specifiers
> through pwm-map properties. fw_devlink instead parses the pwms property
> as a direct phandle reference, so it records the nexus node as the
> supplier rather than the mapped PWM provider.
> 
> Use the map-aware parser for pwms so fw_devlink resolves the same
> provider as the PWM consumer API. Direct PWM references continue to work
> because the map-aware parser returns the original provider when no
> pwm-map property is present.
> 
> Link: https://lore.kernel.org/all/juuc4af7ndbajcl7gzf4tg5qz2q2j5tt3rvql4jbauradujrre@gc5nbdhhixaf/
> 
> > diff --git a/drivers/of/property.c b/drivers/of/property.c
> > index eba7e9fe6c386..a9c51d639a2b5 100644
> > --- a/drivers/of/property.c
> > +++ b/drivers/of/property.c
> > @@ -1426,7 +1435,7 @@ DEFINE_SIMPLE_PROP(extcon, "extcon", NULL)
> >  DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells")
> >  DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells")
> >  DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)
> > -DEFINE_SIMPLE_PROP(pwms, "pwms", "#pwm-cells")
> > +DEFINE_SIMPLE_NEXUS_PROP(pwms, "pwms", "pwm")
> 
> [Severity: Critical]
> This isn't a bug introduced by this patch, but this change exposes a
> pre-existing stack buffer overflow in of_parse_phandle_with_args_map() by
> parsing pwms properties automatically during early boot.
> 
> Does this code overflow initial_match_array[]?  If a provider node in a
> malformed Devicetree has a #pwm-cells property larger than MAX_PHANDLE_ARGS
> (16), list_size is read without bounds checking:
> 
> drivers/of/base.c:of_parse_phandle_with_args_map() {
>     ...
> 	/* Precalculate the match array - this simplifies match loop */
> 	for (i = 0; i < list_size; i++)
> 		initial_match_array[i] = cpu_to_be32(out_args->args[i]);
>     ...
> }
> 
> Because fw_devlink now automatically calls parse_nexus_prop() and
> of_parse_phandle_with_args_map() for all pwms properties, this regression can
> now be trivially triggered without requiring consumer drivers to probe.

Does this need

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d71ae0449360..68d3eaa86742 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1579,6 +1579,9 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
 	if (ret < 0)
 		goto put;
 
+	if (list_size > MAX_PHANDLE_ARGS)
+		return -EINVAL;
+
 	/* Precalculate the match array - this simplifies match loop */
 	for (i = 0; i < list_size; i++)
 		initial_match_array[i] = cpu_to_be32(out_args->args[i]);

?

Best regards
Uwe


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-09-18 13:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 14:16 [PATCH v2 0/7] of: property: Make fw_devlink follow GPIO, PWM and clock nexus maps Ernest Van Hoecke
2026-09-10 14:16 ` [PATCH v2 1/7] of: property: fw_devlink: Follow GPIO " Ernest Van Hoecke
2026-09-10 14:28   ` sashiko-bot
2026-09-11  7:51   ` Bartosz Golaszewski
2026-09-16 17:14   ` Linus Walleij
2026-09-16 17:43   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 2/7] of: property: fw_devlink: Report unsupported supplier linking Ernest Van Hoecke
2026-09-10 14:28   ` sashiko-bot
2026-09-16 17:44   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 3/7] of: unittest: Test fw_devlink with GPIO nexus maps Ernest Van Hoecke
2026-09-11  7:51   ` Bartosz Golaszewski
2026-09-16 17:14   ` Linus Walleij
2026-09-16 17:51   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 4/7] of: property: fw_devlink: Follow PWM " Ernest Van Hoecke
2026-09-10 14:31   ` sashiko-bot
2026-09-18 13:54     ` Uwe Kleine-König [this message]
2026-09-16 17:52   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 5/7] of: unittest: Test fw_devlink with " Ernest Van Hoecke
2026-09-16 17:54   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 6/7] of: property: fw_devlink: Follow clock " Ernest Van Hoecke
2026-09-10 14:29   ` sashiko-bot
2026-09-16 18:15   ` Herve Codina
2026-09-10 14:16 ` [PATCH v2 7/7] of: unittest: Test fw_devlink with " Ernest Van Hoecke
2026-09-16 18:19   ` Herve Codina

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=aq1CSswlo57jZpMH@monoceros \
    --to=u.kleine-koenig@baylibre.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ernestvanhoecke@gmail.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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