From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33C7B606A32F for ; Wed, 2 Dec 2026 09:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DaAZe3z6; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=FTB/EAmj DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=LL5vfFkkPExfRatN1jOau7oUnJrL8HZy3CyTug0llmY=; b=DaAZe3z60qtj4Y E/8bdaoXcYnWBJ2oFEE/Rfv72C6dMviFlLtBG2zsInEaJ7Ncr3bSF/AEpXsLwrIahbeAdUJnfXMiG pXyN0vsW3T54XABpeaQokmkaw//pOV4KBqFr3291aqJcUMtPMslqWH8Pv7kLtxpVNiP5/zcc20Nu9 voFAAEy+6d7H/r1E2F3OJIw07ex5yOE5WVpkgNQxqEAmLFWVb/d5+z/hqJeZ/Zh9T0ZERTUWAh2kM +O680GfrK4o3cVIePl0zVW0HkfqMt6aM7MG0DAtMz8wf75V4p2qB5KBzGNfo3axp2bDhNpgAPPwDI KVFjLeutaLGcTWrRD05A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYggl-0000000AqC4-1g0p; Wed, 02 Dec 2026 09:31:47 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYggj-0000000AqBY-1RsG for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 09:31:45 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 1E8FE453C1; Wed, 2 Dec 2026 09:31:45 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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