From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796203905; b=gUAF7gyRWV4TFWbW8LeZ9jlUPyuLklP3y3HuCIYjzhJWOcynr/3yHnhF7c+8iseGyJLN 46cA+xXD38KhdUvXowaRJN5Dfxcc/R7e43PMRD9IX86wXOEEbKpSc2KQgTo56XtH/QCjr wO++6WyOOjcJjUhN/J98FfYITmbSXfXI8CLMdbtZtfCeePqL+LvBaxUgOYyHDdcZgvseD gdRtE93ZnxEQBaTffXZ2AXlnRvP+iCABPwEAUjT71J3RManAlvtw4Hkl3XlPZy0T/MAiW FbbfAFwRNqCvx8ro3ca1w1XyTCmOcDz0wWul9LhoD369HL2EUCFYVkbmw2zgl8LHSOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796203905; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=LL5vfFkkPExfRatN1jOau7oUnJrL8HZy3CyTug0llmY=; b=3FXKeAuRUlAcUKZ8KMFTrehV19vKbBE6btYnyy2KooVOe/7kBNwjp0MwGC4uQnl8APmX 3W+idQo2G/KkzB7vzwtZAn7ubHid7BWojTuqmMhGkLBrzOQ8b73pyCkpHnWjLv6qYn9hM i3j49XHAsV1hasWHKXX/NdDf32nvroc+d6fZGsrwuexwu6MAH1PePPK9WQULlQle7u+br B9Ld7g5W76bhYty/89FeLul2Mg3hvSXLLlfKg0GJI1r8bCj597U+LwQrNIoEJCZAxZLqf diBooWjDVrIf9oqNeEWWTBYOpXPA22SdeZVtxuVRAqSnf5uJPX8dNJltUQfZl1KjA3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="FTB/EAmj"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C407606A33E; Wed, 2 Dec 2026 09:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FTB/EAmj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 959151F00923; Wed, 2 Dec 2026 09:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796203905; bh=LL5vfFkkPExfRatN1jOau7oUnJrL8HZy3CyTug0llmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FTB/EAmjhTt790MPxzxynZWYiGoRWHlmIdSWwHJHnOacbu387NZeXBkc08V2aIMk7 xVHYCW9SgJs/zaaxUkk3cd0Qwh4Wp4NYOc8jucsJOo9Kz+dikhzHfGLnwU7cCL4LdB 9i1lrqxZjxr4RUIxy6oMOEbRR2KSAjYDIuf68jih4nbqvcqHsmf+F1gsIbxFI+Hzu/ Oe1/RrzzjdlUI5UJzDcEC5icicZKuyOKMzdIEuPkVLwimzGyjAqSlalV8BbkirqQCB 9iwD21PnJpkXr+btYcDSy7NTBqeHJfHghMv/lM6m8Zr99Uyt6QL1ta6pI0Pli5AwrL NVOpS2LgI5OnQ== From: Lee Jones To: lee@kernel.org, Dong Aisheng , Fabio Estevam , Frank Li , Jacky Bai , Pengutronix Kernel Team , NXP S32 Linux Team , Linus Walleij , Sascha Hauer , Mehmet Fide , Shawn Guo , 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 Message-ID: <3ff7bc09afe8aee89aa7ddc76acd1a0cf4e1dc87.1796203691.git.lee@kernel.org> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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