Re: [PATCH] pinctrl: starfive: jh7100: Reject malformed pin properties
From: Linus Walleij
Date: Thu Dec 03 2026 - 03:12:10 EST
On Wed, Nov 25, 2026 at 7:07 AM Zhiqi Zhang <zhiqizhangg@xxxxxxxxx> wrote:
> The JH7100 binding allows each pin group to specify either "pinmux" or
> "pins", but not both. starfive_dt_node_to_map() uses
> of_property_count_u32_elems() to decide which property is present, so a
> negative parser error is handled the same way as an absent property.
>
> A group that contains a malformed "pinmux" property and a valid "pins"
> property is therefore accepted as a "pins" group. Similarly, a malformed
> "pins" property can be ignored when a valid "pinmux" property is present.
> Both cases silently accept a device tree node that the binding rejects.
>
> Check property presence separately from array length. Reject groups that
> specify both or neither property, and require the selected property's u32
> array to contain at least one element before sizing and filling the maps.
>
> I found this issue. OpenAI Codex helped draft the fix, and I reviewed the
> result.
>
> Fixes: ec648f6b7686 ("pinctrl: starfive: Add pinctrl driver for StarFive SoCs")
> Signed-off-by: Zhiqi Zhang <zhiqizhangg@xxxxxxxxx>
What I want to know is if such a malformed pinmux property and pins
present condition passes the device tree schema validation for this
driver?
I guess we should check for this kind of stuff to some extent but it can
become overzealous and bloat the kernel with runtime checks of
device trees that wouldn't pass validation in the first place, and the
boot chain should protect against attackers inserting invalid device
trees so it's not really an attack vector.
> - if (npinmux > 0)
> + if (has_pinmux) {
> + npins = of_property_count_u32_elems(child, "pinmux");
> + if (npins < 1)
> + return npins ?: -EINVAL;
> +
> nmaps += 2;
> - else
> + } else {
> + npins = of_property_count_u32_elems(child, "pins");
> + if (npins < 1)
> + return npins ?: -EINVAL;
> +
(...)
> + } else {
> + npins = of_property_count_u32_elems(child, "pins");
> + if (npins < 1) {
> + ret = npins ?: -EINVAL;
> + goto free_map;
> + }
Three copies of very similar code?
Create a static helper function to check the property count.
Yours,
Linus Walleij