From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Antonio Borneo <antonio.borneo@foss.st.com>,
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: [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK
Date: Wed, 2 Dec 2026 09:29:55 +0000 [thread overview]
Message-ID: <f9d705abea198f76ecff99e40577e7de5a984f1f.1796203691.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796203691.git.lee@kernel.org>
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;
--
2.56.1.911.g883d8bcb20-goog
next parent reply other threads:[~2026-12-02 9:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1796203691.git.lee@kernel.org>
2026-12-02 9:29 ` Lee Jones [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 9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() 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 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
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=f9d705abea198f76ecff99e40577e7de5a984f1f.1796203691.git.lee@kernel.org \
--to=lee@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=antonio.borneo@foss.st.com \
--cc=fabien.dessenne@foss.st.com \
--cc=junan76@163.com \
--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