* [PATCH] pinctrl: qcom: lpass-lpi: Don't touch reserved pins
@ 2026-12-05 12:39 Andrey Derkach
2026-12-05 12:59 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Derkach @ 2026-12-05 12:39 UTC (permalink / raw)
To: Bjorn Andersson, Bartosz Golaszewski, Linus Walleij
Cc: Richard Acayan, linux-arm-msm, linux-gpio
Since commit a22d2598a563 ("dt-bindings: qcom: lpass-lpi-common: add
reserved GPIOs property") an LPI pin controller can have
gpio-reserved-ranges. On SDM670 phones such as the Pixel 3a these are
the sensor pins, which the firmware protects: reading their registers
hangs the bus and freezes the SoC. gpiolib leaves reserved lines alone,
but the LPI driver still reads them from the GPIO debugfs dump and from
the pinconf-groups debugfs file, and pinmux does not refuse to mux
them.
Do what pinctrl-msm does since commit 691bf5d5a7bf ("pinctrl: qcom:
Don't allow protected pins to be requested") and
commit 27030ff78772 ("pinctrl: qcom: fail to retrieve configuration
from invalid pin groups"): refuse pinmux requests for reserved pins,
fail pinconf reads of them and leave them out of the GPIO debugfs dump.
Tested on the Xiaomi Mi 9 SE (SDM712), which reserves <0 18>, <26 6>:
without this change reading /sys/kernel/debug/gpio freezes the SoC;
with it the dump lists only GPIOs 18-25, and pinconf-groups shows the
reserved groups without configs.
Signed-off-by: Andrey Derkach <gabin278@gmail.com>
---
Writing the pinctrl "pinmux-select" debugfs file calls .set_mux without
.request, so it can still mux a reserved group. pinctrl-msm has the same
gap; this patch leaves it alone.
drivers/pinctrl/qcom/pinctrl-lpass-lpi.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
index f693e5101a7b..de5bab0d28ec 100644
--- a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
+++ b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
@@ -171,7 +171,15 @@ static int lpi_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned int function,
return 0;
}
+static int lpi_gpio_request(struct pinctrl_dev *pctldev, unsigned int offset)
+{
+ struct lpi_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
+
+ return gpiochip_line_is_valid(&pctrl->chip, offset) ? 0 : -EINVAL;
+}
+
static const struct pinmux_ops lpi_gpio_pinmux_ops = {
+ .request = lpi_gpio_request,
.get_functions_count = lpi_gpio_get_functions_count,
.get_function_name = lpi_gpio_get_function_name,
.get_function_groups = lpi_gpio_get_function_groups,
@@ -189,6 +197,10 @@ static int lpi_config_get(struct pinctrl_dev *pctldev,
int pull;
int ret;
+ /* Reserved pins may be protected, reading them can hang the bus */
+ if (!gpiochip_line_is_valid(&state->chip, pin))
+ return -EINVAL;
+
ret = lpi_gpio_read(state, pin, LPI_GPIO_CFG_REG, &ctl_reg);
if (ret)
return ret;
@@ -466,6 +478,9 @@ static void lpi_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
unsigned int i;
for (i = 0; i < chip->ngpio; i++, gpio++) {
+ if (!gpiochip_line_is_valid(chip, i))
+ continue;
+
lpi_gpio_dbg_show_one(s, NULL, chip, i, gpio);
seq_puts(s, "\n");
}
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pinctrl: qcom: lpass-lpi: Don't touch reserved pins
2026-12-05 12:39 [PATCH] pinctrl: qcom: lpass-lpi: Don't touch reserved pins Andrey Derkach
@ 2026-12-05 12:59 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 12:59 UTC (permalink / raw)
To: Andrey Derkach; +Cc: linux-gpio
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] pinctrl: qcom: lpass-lpi: UAF of chip.gpiodev on unbind or
probe failure
- [Medium] pinctrl: qcom: lpass-lpi: probe race before gpiochip
valid_mask init
- [Low] pinctrl: qcom: lpass-lpi: missing Fixes trailer on bug-fix
commit
--
commit ef26c5c45ab94e6f1eff8368010383e7945b02b7
Author: Andrey Derkach <gabin278@gmail.com>
> pinctrl: qcom: lpass-lpi: Don't touch reserved pins
>
> Since commit a22d2598a563 ("dt-bindings: qcom: lpass-lpi-common: add
> reserved GPIOs property") an LPI pin controller can have
> gpio-reserved-ranges. On SDM670 phones such as the Pixel 3a these are
> the sensor pins, which the firmware protects: reading their registers
> hangs the bus and freezes the SoC. gpiolib leaves reserved lines alone,
> but the LPI driver still reads them from the GPIO debugfs dump and from
> the pinconf-groups debugfs file, and pinmux does not refuse to mux
> them.
>
> Do what pinctrl-msm does since commit 691bf5d5a7bf ("pinctrl: qcom:
> Don't allow protected pins to be requested") and
> commit 27030ff78772 ("pinctrl: qcom: fail to retrieve configuration
> from invalid pin groups"): refuse pinmux requests for reserved pins,
> fail pinconf reads of them and leave them out of the GPIO debugfs dump.
>
> Tested on the Xiaomi Mi 9 SE (SDM712), which reserves <0 18>, <26 6>:
> without this change reading /sys/kernel/debug/gpio freezes the SoC;
> with it the dump lists only GPIOs 18-25, and pinconf-groups shows the
> reserved groups without configs.
>
> Signed-off-by: Andrey Derkach <gabin278@gmail.com>
[Severity: Low]
This fixes a bus hang when accessing reserved pins. Should this include:
Fixes: 6e261d1090d6 ("pinctrl: qcom: Add sm8250 lpass lpi pinctrl driver")
> diff --git a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
> index f693e5101a7bc..de5bab0d28ecd 100644
> --- a/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
> +++ b/drivers/pinctrl/qcom/pinctrl-lpass-lpi.c
> @@ -171,7 +171,15 @@ static int lpi_gpio_set_mux(struct pinctrl_dev *pctldev, unsigned int function,
> return 0;
> }
>
> +static int lpi_gpio_request(struct pinctrl_dev *pctldev, unsigned int offset)
> +{
> + struct lpi_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
> +
> + return gpiochip_line_is_valid(&pctrl->chip, offset) ? 0 : -EINVAL;
> +}
> +
> static const struct pinmux_ops lpi_gpio_pinmux_ops = {
> + .request = lpi_gpio_request,
> .get_functions_count = lpi_gpio_get_functions_count,
> .get_function_name = lpi_gpio_get_function_name,
> .get_function_groups = lpi_gpio_get_function_groups,
[Severity: Medium]
Can lpi_gpio_request() allow access to a reserved pin during probe before
pctrl->chip has initialized its valid_mask?
In lpi_pinctrl_probe(), devm_pinctrl_register() and
lpi_build_pin_desc_groups() expose the pin controller and its groups before
devm_gpiochip_add_data() runs:
CPU0 CPU1
lpi_pinctrl_probe()
devm_pinctrl_register()
lpi_build_pin_desc_groups()
pin_request()
lpi_gpio_request()
gpiochip_line_is_valid()
!gc->gpiodev -> true <-- bypass
devm_gpiochip_add_data()
gpiochip_init_valid_mask()
Even after gpiodev is assigned, gpiochip_init_valid_mask() publishes an
all-1s valid_mask via gpiochip_allocate_mask() before
gpiochip_apply_reserved_ranges() clears the reserved bits. A concurrent
pin_request() or debugfs read via lpi_config_get() in this window can read
or write firmware-protected pin registers and hang the bus.
> @@ -189,6 +197,10 @@ static int lpi_config_get(struct pinctrl_dev *pctldev,
> int pull;
> int ret;
>
> + /* Reserved pins may be protected, reading them can hang the bus */
> + if (!gpiochip_line_is_valid(&state->chip, pin))
> + return -EINVAL;
> +
> ret = lpi_gpio_read(state, pin, LPI_GPIO_CFG_REG, &ctl_reg);
> if (ret)
> return ret;
[Severity: Medium]
Can gpiochip_line_is_valid() dereference a freed state->chip.gpiodev on
unbind or probe failure?
Because lpi_pinctrl_probe() calls devm_pinctrl_register() before
devm_gpiochip_add_data(), devres tears them down in reverse order and runs
gpiochip_remove() before pinctrl_unregister(). gpiochip_remove() frees
valid_mask and drops the last reference to gdev without clearing
gc->gpiodev:
CPU0 CPU1
pin_config_group_get()
mutex_lock(&pctldev->mutex)
devres_release_all()
gpiochip_remove()
gpiochip_free_valid_mask()
gpio_device_put(gdev)
kfree(gdev)
pinctrl_unregister()
mutex_lock(&pctldev->mutex)
lpi_config_get()
gpiochip_line_is_valid()
gdev->valid_mask <-- use-after-free
If an open gpiochip fd keeps gdev alive after gpiochip_free_valid_mask()
clears valid_mask to NULL, gpiochip_line_is_valid() instead returns true
and accesses the protected register, hanging the bus. The same lifetime
mismatch applies to lpi_gpio_request(), and to a failing
devm_gpiochip_add_data() that frees gdev without clearing gc->gpiodev while
pctrl->ctrl is still registered.
Storing a driver-owned reserved-pin bitmap parsed before
devm_pinctrl_register() would avoid both this lifetime mismatch and the
probe race above.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205123913.1063058-1-gabin278@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 12:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 12:39 [PATCH] pinctrl: qcom: lpass-lpi: Don't touch reserved pins Andrey Derkach
2026-12-05 12:59 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.