mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Antonio Borneo <antonio.borneo@foss.st.com>
To: Lee Jones <lee@kernel.org>, Linus Walleij <linusw@kernel.org>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Ju Nan <junan76@163.com>,
	Fabien Dessenne <fabien.dessenne@foss.st.com>,
	<linux-gpio@vger.kernel.org>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK
Date: Wed, 2 Dec 2026 17:13:52 +0100	[thread overview]
Message-ID: <c2218c6b4470ef6933bf674f66d72eaa370f7cf3.camel@foss.st.com> (raw)
In-Reply-To: <f9d705abea198f76ecff99e40577e7de5a984f1f.1796203691.git.lee@kernel.org>

On Wed, 2026-12-02 at 09:29 +0000, Lee Jones wrote:
> stm32_gpiolib_register_bank() computes npins from the device tree
> "gpio-ranges" property as args.args[0] + args.args[2] without checking
> that the resulting value fits within STM32_GPIO_PINS_PER_BANK (16).
> Because bank->pin_backup[] is a fixed-size array of
> STM32_GPIO_PINS_PER_BANK elements and the hardware registers only have
> 16 lines per bank, a larger npins value leads to out-of-bounds array
> accesses and shift overflows.
> 
> Validate that npins is within 1..STM32_GPIO_PINS_PER_BANK.
> 
> Fixes: b67210cc217f ("pinctrl: stm32: consider the GPIO offset to expose all the GPIO lines")
> Closes: https://sashiko.dev/#/bug/linux-efdf6da1-70b0-4c56-add9-2bc97a4c140d
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>  drivers/pinctrl/stm32/pinctrl-stm32.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index bf16e5814bf8..01c8a646d9a0 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -1657,13 +1657,26 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
>                 bank->gpio_chip.base = args.args[1];
>  
>                 /* get the last defined gpio line (offset + nb of pins) */
> +               if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
> +                   args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
> +                       fwnode_handle_put(args.fwnode);
> +                       return -EINVAL;
> +               }
>                 npins = args.args[0] + args.args[2];
>                 fwnode_handle_put(args.fwnode);
>  
>                 while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) {
> +                       if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
> +                           args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
> +                               fwnode_handle_put(args.fwnode);
> +                               return -EINVAL;
> +                       }
>                         npins = max(npins, (int)(args.args[0] + args.args[2]));
>                         fwnode_handle_put(args.fwnode);
>                 }
> +
> +               if (!npins)
> +                       return -EINVAL;
>         } else {
>                 bank_nr = pctl->nbanks;
>                 bank->gpio_chip.base = bank_nr * STM32_GPIO_PINS_PER_BANK;

Hi Lee,

I agree, this change fixes the case of incorrect values for the DT property
"gpio-ranges", values not checked by 'make dtbs_check'.

I thought we should trust the DT as correct, avoiding too many checks in the drivers.
Is there any news I have missed?
Or is this a special case, as it involves a potential out-of-bounds array access?

Anyway,
Reviewed-by: Antonio Borneo <antonio.borneo@foss.st.com>

Thanks,
Antonio

  reply	other threads:[~2026-12-02 16:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:29 [PATCH 00/12] pinctrl: Fix Critical and High issues reported by Sashiko (batch 3) Lee Jones
2026-12-02  9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
2026-12-02 16:13   ` Antonio Borneo [this message]
2026-12-02  9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
2026-12-02  9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
2026-12-02 14:08   ` Bartosz Golaszewski
2026-12-02  9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
2026-12-02  9:29 ` [PATCH 05/12] pinctrl: tegra: Require at least one register bank in tegra_pinctrl_probe() Lee Jones
2026-12-02  9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
2026-12-02  9:30 ` [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs Lee Jones
2026-12-02  9:30 ` [PATCH 08/12] pinctrl: keembay: Check src before calling keembay_find_free_slot() Lee Jones
2026-12-02  9:30 ` [PATCH 09/12] pinctrl: ti: iodelay: Protect generic group addition with pctldev->mutex Lee Jones
2026-12-02  9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
2026-12-02  9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
2026-12-02 15:28   ` Antonio Borneo
2026-12-02  9:30 ` [PATCH 12/12] pinctrl: sx150x: Register threaded IRQ after adding GPIO chip Lee Jones
2026-12-02  9:35   ` Neil Armstrong

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=c2218c6b4470ef6933bf674f66d72eaa370f7cf3.camel@foss.st.com \
    --to=antonio.borneo@foss.st.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=fabien.dessenne@foss.st.com \
    --cc=junan76@163.com \
    --cc=lee@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --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 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®