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=1796475561; b=gCdZLvvLBhxwB3QuNWrQneTQ0YejvOwvFPOqXE+WrgXLohVVBQGWJch9unT9pjVLhqvP rXd5JZyMH4B/nlWNQlY5PNhpDrHLKoU4E41nm/9sIbmu/kWX1g47o6k/WR8ucFjhDN00m nssGQuML7mxWHU1HLu1c7Cuaj+5CwGUnQScD2mc9aR7892sVBzu8Y281A5YvQf3rSwtz6 olJ9ElT1LE6KR8CakhBRcIVT6/yCDOyqGLf2DMHbKnL79vbYlSjJGHTZ1F5xdUyEkHOUB b0/9J9eOqKaxOwMEXTcqgN1NB/EDbTO2H4B0Krj6sUkhum0O1Om+38BDW8WvJ4lyCLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796475561; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=6tMETTtcbU1X6awiUPxXKb9aDbwACsFIZWR+uYnYF3U=; b=cXw+qIFfDSzpLZW5Y43ZaR5wMLYxPRM23Ie8dai2b5Sox+0GqIlnSZZkJ5mE4sALh51K uHCV3Wtg41aZbUuHs1Pn2tsxm+jhPmARH3Y2NapTudgajsmyeuckYDyszkQBIq3FdlYJ7 RYFG6aCzPlqmu2ya6TGJmjXW9J27do/8ONNe/fZ82TvqbPAv/OzBxGPnA57+SLHr948Ox LLlxmeDOIbxrEvU+mUYflti7u4HjQL5om8KSHkEaVTxR1Bzg1Cp8cHJR8gsxDq2rVpy5Y p4eFZWR6xZaCJVaeHO0twdreUTSd0ykQtqRt3RnHJnXGzQ3nH7lHItQeI+jYnJB6fCQ== 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=eJrgbm2+; 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 7AEB6606A322 for ; Sat, 5 Dec 2026 12:59:21 +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=eJrgbm2+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 118C91F00A07; Sat, 5 Dec 2026 12:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796475561; bh=6tMETTtcbU1X6awiUPxXKb9aDbwACsFIZWR+uYnYF3U=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eJrgbm2+AQVTv7XodvxxI2Ob+Ujc4cGvZQr7H2xOrUoJOFigW4OuDP+uI5No0XaFg MIHi4sSgF4pU18UnxXfjknRYKqiElZVeFNjY595lPgSy7l8lvXzEEiGMBIE/cBFjEE cIxopZi8T7Xfg+edvSYUvEacQ5RDVdRd4p5dujHIGGgqDX21vJ3A0+34bBjN9ZknZZ dD74ifjHk5N6Qp5hSEuIItH4mgCL0BlUpebmXo2VAdehh3T+WZsNOoBueTfOiRxYrC 1noonm2C1vuJFtCq/ZYYgum54XASukJgBq7UlDUDluUVlNWOig46uMG7C+1zSHXB2n 2OGGXNybMKMWg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] pinctrl: qcom: lpass-lpi: Don't touch reserved pins Reply-To: sashiko-reviews@lists.linux.dev To: "Andrey Derkach" Cc: linux-gpio@vger.kernel.org In-Reply-To: <20261205123913.1063058-1-gabin278@gmail.com> References: <20261205123913.1063058-1-gabin278@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 12:59:20 +0000 X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 [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/q= com/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 *pctl= dev, unsigned int function, > return 0; > } > =20 > +static int lpi_gpio_request(struct pinctrl_dev *pctldev, unsigned int of= fset) > +{ > + struct lpi_pinctrl *pctrl =3D pinctrl_dev_get_drvdata(pctldev); > + > + return gpiochip_line_is_valid(&pctrl->chip, offset) ? 0 : -EINVAL; > +} > + > static const struct pinmux_ops lpi_gpio_pinmux_ops =3D { > + .request =3D lpi_gpio_request, > .get_functions_count =3D lpi_gpio_get_functions_count, > .get_function_name =3D lpi_gpio_get_function_name, > .get_function_groups =3D 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 *pctlde= v, > int pull; > int ret; > =20 > + /* Reserved pins may be protected, reading them can hang the bus */ > + if (!gpiochip_line_is_valid(&state->chip, pin)) > + return -EINVAL; > + > ret =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205123913.1063= 058-1-gabin278@gmail.com?part=3D1