mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Dong Aisheng <aisheng.dong@nxp.com>,
	Fabio Estevam <festevam@gmail.com>, Frank Li <Frank.Li@nxp.com>,
	Jacky Bai <ping.bai@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	NXP S32 Linux Team <s32@nxp.com>,
	Linus Walleij <linusw@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Mehmet Fide <mehmet.fide@screeningeagle.com>,
	Shawn Guo <shawn.guo@linaro.org>,
	linux-gpio@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio()
Date: Wed,  2 Dec 2026 09:29:56 +0000	[thread overview]
Message-ID: <3ff7bc09afe8aee89aa7ddc76acd1a0cf4e1dc87.1796203691.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796203691.git.lee@kernel.org>

imx_pinctrl_parse_pin_mmio() derives *pin_id from mux_reg / 4 or
conf_reg / 4 and uses it directly to index ipctl->pin_regs[*pin_id] and
info->pins[*pin_id] without bounds checking against info->npins.  If a
device tree entry specifies an out-of-range register offset or sets both
mux_reg and conf_reg to 0 on a SoC without ZERO_OFFSET_VALID (making
conf_reg == -1 and *pin_id == 0x3fffffff), this results in an
out-of-bounds memory access.

Validate that *pin_id is less than info->npins and return -EINVAL on
invalid entries.

Fixes: e16415313c9b ("pinctrl: imx: move hard-coding data into device tree")
Closes: https://sashiko.dev/#/bug/linux-b67db85c-1fa1-4c97-9932-88c575b568f2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/pinctrl/freescale/pinctrl-imx.c | 32 ++++++++++++++++++-------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index ebcce9aeac8c..0a825f58448f 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -502,15 +502,16 @@ static const struct pinconf_ops imx_pinconf_ops = {
 #define FSL_PIN_SHARE_SIZE 20
 #define FSL_SCU_PIN_SIZE 12
 
-static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
-				       unsigned int *pin_id, struct imx_pin *pin,
-				       const __be32 **list_p,
-				       struct device_node *np)
+static int imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
+				      unsigned int *pin_id, struct imx_pin *pin,
+				      const __be32 **list_p,
+				      struct device_node *np)
 {
 	const struct imx_pinctrl_soc_info *info = ipctl->info;
 	struct imx_pin_mmio *pin_mmio = &pin->conf.mmio;
 	struct imx_pin_reg *pin_reg;
 	const __be32 *list = *list_p;
+	unsigned int id;
 	u32 mux_reg, conf_reg;
 	u32 config;
 
@@ -527,7 +528,14 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
 			conf_reg = -1;
 	}
 
-	*pin_id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
+	id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
+	if (id >= info->npins) {
+		dev_err(ipctl->dev, "Invalid pin id %u in node %pOF\n",
+			id, np);
+		return -EINVAL;
+	}
+
+	*pin_id = id;
 	pin_reg = &ipctl->pin_regs[*pin_id];
 	pin->pin = *pin_id;
 	pin_reg->mux_reg = mux_reg;
@@ -547,6 +555,8 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
 
 	dev_dbg(ipctl->dev, "%s: 0x%x 0x%08lx", info->pins[*pin_id].name,
 			     pin_mmio->mux_mode, pin_mmio->config);
+
+	return 0;
 }
 
 static int imx_pinctrl_parse_groups(struct device_node *np,
@@ -611,10 +621,16 @@ static int imx_pinctrl_parse_groups(struct device_node *np,
 
 	for (i = 0; i < grp->grp.npins; i++) {
 		pin = &((struct imx_pin *)(grp->data))[i];
-		if (info->flags & IMX_USE_SCU)
+		if (info->flags & IMX_USE_SCU) {
 			info->imx_pinctrl_parse_pin(ipctl, &pins[i], pin, &list);
-		else
-			imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin, &list, np);
+		} else {
+			int ret;
+
+			ret = imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin,
+							 &list, np);
+			if (ret)
+				return ret;
+		}
 	}
 
 	return 0;
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02  9:31 UTC|newest]

Thread overview: 15+ 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  9:29 ` Lee Jones [this message]
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  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=3ff7bc09afe8aee89aa7ddc76acd1a0cf4e1dc87.1796203691.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=aisheng.dong@nxp.com \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mehmet.fide@screeningeagle.com \
    --cc=ping.bai@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=s32@nxp.com \
    --cc=shawn.guo@linaro.org \
    --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®