[PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio()

Frank Li Frank.li at oss.nxp.com
Wed Dec 2 09:17:44 PST 2026


On Wed, Dec 02, 2026 at 09:29:56AM +0000, Lee Jones wrote:
> 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 at vger.kernel.org
> Signed-off-by: Lee Jones <lee at kernel.org>
> ---

Reviewed-by: Frank Li <Frank.Li at nxp.com>

>  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
>
>



More information about the linux-arm-kernel mailing list