From: Andrea della Porta <andrea.porta@suse.com>
To: Xiaolei Wang <wangxiaolei01@kaihong.com>
Cc: linusw@kernel.org, florian.fainelli@broadcom.com,
rjui@broadcom.com, sbranden@broadcom.com,
bcm-kernel-feedback-list@broadcom.com, daniel@dragonzap.com,
iivanov@suse.de, andrea.porta@suse.com, phil@raspberrypi.com,
linux-gpio@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Jonathan Bell <jonathan@raspberrypi.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/4] pinctrl: bcm: Fix off-by-one and out-of-bounds access in fsel_get()
Date: Fri, 13 Nov 2026 13:52:34 +0100 [thread overview]
Message-ID: <avcIEnCThuTHeWVv@apocalypse> (raw)
In-Reply-To: <20261113053221.3131068-2-wangxiaolei01@kaihong.com>
Hi Wang,
On 05:32 Fri 13 Nov , Xiaolei Wang wrote:
> The FSEL field is a 1-based function number: 0 means GPIO, 1..n_funcs
> map to funcs[0..n_funcs - 1], and n_funcs + 1 and above are rejected.
> brcmstb_pinctrl_fsel_get() indexes funcs[] with the raw value instead
> of subtracting one, so readbacks are shifted by one slot: value 8
> indexes funcs[8], past the array end, while 0 is reported as funcs[0]
> instead of GPIO. The setter programs the mux correctly, so only the
> debugfs readback is affected.
>
> Map 0 and out-of-range values back to GPIO, warn on the latter, and
> index funcs[] with fsel - 1. Tested on Raspberry Pi 5 with KASAN: the
> "alt8" readback no longer splats, and field 0 reports GPIO.
>
> Fixes: 657cbf9b24ba ("pinctrl: bcm: Add STB family pin controller driver")
> Cc: Jonathan Bell <jonathan@raspberrypi.com>
> Cc: Phil Elwell <phil@raspberrypi.com>
> Cc: stable@vger.kernel.org
> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
> Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
Reviewed-by: Andrea della Porta <andrea.porta@suse.com>
Thanks!
Andrea
> ---
> drivers/pinctrl/bcm/pinctrl-brcmstb.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/bcm/pinctrl-brcmstb.c b/drivers/pinctrl/bcm/pinctrl-brcmstb.c
> index f46b27155c3c..2b942ca7196b 100644
> --- a/drivers/pinctrl/bcm/pinctrl-brcmstb.c
> +++ b/drivers/pinctrl/bcm/pinctrl-brcmstb.c
> @@ -66,7 +66,16 @@ static unsigned int brcmstb_pinctrl_fsel_get(struct brcmstb_pinctrl *pc,
>
> val = readl(pc->base + BIT_TO_REG(bit));
> fsel = (val >> BIT_TO_SHIFT(bit)) & pc->pin_funcs[pin].func_mask;
> - func = pc->pin_funcs[pin].funcs[fsel];
> +
> + if (!fsel)
> + return pc->func_gpio;
> +
> + if (fsel > pc->pin_funcs[pin].n_funcs) {
> + dev_warn(pc->dev, "invalid fsel %d for pin %u\n", fsel, pin);
> + return pc->func_gpio;
> + }
> +
> + func = pc->pin_funcs[pin].funcs[fsel - 1];
>
> if (func >= pc->func_count)
> func = fsel;
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-11-13 12:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 5:32 [PATCH v2 0/4] pinctrl: bcm: Two bounds fixes and a dt_free_map cleanup Xiaolei Wang
2026-11-13 5:32 ` [PATCH v2 1/4] pinctrl: bcm: Fix off-by-one and out-of-bounds access in fsel_get() Xiaolei Wang
2026-11-13 12:52 ` Andrea della Porta [this message]
2026-11-13 5:32 ` [PATCH v2 2/4] pinctrl: bcm: Use pinconf_generic_dt_free_map in bcm2835 Xiaolei Wang
2026-11-13 5:32 ` [PATCH v2 3/4] pinctrl: bcm: Use pinconf_generic_dt_free_map in brcmstb Xiaolei Wang
2026-11-13 5:32 ` [PATCH v2 4/4] pinctrl: bcm: Add missing SGPIO entries to the BCM2712 AON tables Xiaolei Wang
2026-11-13 12:53 ` Andrea della Porta
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=avcIEnCThuTHeWVv@apocalypse \
--to=andrea.porta@suse.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=daniel@dragonzap.com \
--cc=florian.fainelli@broadcom.com \
--cc=iivanov@suse.de \
--cc=jonathan@raspberrypi.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-rpi-kernel@lists.infradead.org \
--cc=phil@raspberrypi.com \
--cc=rjui@broadcom.com \
--cc=sbranden@broadcom.com \
--cc=stable@vger.kernel.org \
--cc=wangxiaolei01@kaihong.com \
/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