* [PATCH v2 0/2] power: sequencing: fix use-after-free in pwrseq-pcie-m2
@ 2026-11-05 8:28 Bartosz Golaszewski
2026-11-05 8:28 ` [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable() Bartosz Golaszewski
2026-11-05 8:28 ` [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init() Bartosz Golaszewski
0 siblings, 2 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-11-05 8:28 UTC (permalink / raw)
To: Manivannan Sadhasivam, Bartosz Golaszewski
Cc: Manivannan Sadhasivam, linux-pci, linux-pm, linux-kernel,
Bartosz Golaszewski, stable
This fixes a use-after-free bug reported by sashiko and then cleans up
the error path in probe() by switching to using devm_mutex_init() and
dropping the remaining goto labels.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v2:
- Assign ctx->num_vregs before scheduling the devres action
- Link to v1: https://patch.msgid.link/20261104-pwrseq-pcie-m2-uaf-v1-1-0ae1bbea9533@oss.qualcomm.com
---
Bartosz Golaszewski (2):
power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable()
power: sequencing: pcie-m2: use devm_mutex_init()
drivers/power/sequencing/pwrseq-pcie-m2.c | 53 ++++++++++++++-----------------
1 file changed, 24 insertions(+), 29 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261104-pwrseq-pcie-m2-uaf-a10209c3c4d7
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable()
2026-11-05 8:28 [PATCH v2 0/2] power: sequencing: fix use-after-free in pwrseq-pcie-m2 Bartosz Golaszewski
@ 2026-11-05 8:28 ` Bartosz Golaszewski
2026-11-05 8:38 ` sashiko-bot
2026-11-05 8:28 ` [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init() Bartosz Golaszewski
1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-11-05 8:28 UTC (permalink / raw)
To: Manivannan Sadhasivam, Bartosz Golaszewski
Cc: Manivannan Sadhasivam, linux-pci, linux-pm, linux-kernel,
Bartosz Golaszewski, stable
During device teardown or on the probe error path, a concurrent consumer
access triggers a use-after-free in pwrseq_pcie_m2_vregs_enable() or
pwrseq_pcie_m2_vregs_disable() due to a lifetime inversion between
devm-managed device registration and manual resource cleanup.
The driver exposes the power sequencer using devm_pwrseq_device_register(),
meaning the device remains fully registered and accessible on the
pwrseq_bus until the driver core schedules devm_pwrseq_device_unregister()
to run after pwrseq_pcie_m2_remove() returns. However, the driver performs
manual resource teardown within pwrseq_pcie_m2_remove() and the
pwrseq_pcie_m2_probe() error path, prematurely destroying the backing
regulator array.
This creates a narrow vulnerability window where the globally visible power
sequencer is backed by freed memory. If a concurrent consumer invokes
pwrseq_enable() during this window, execution is routed to the sequencer
callback and dereferences the destroyed ctx->regs array, resulting in a
direct use-after-free and a kernel crash.
Schedule a devres action for freeing the memory used for the regulator
array to ensure it runs *after* the pwrseq provider was unregistered.
Cc: stable@vger.kernel.org
Fixes: 3f736aecbdc8 ("power: sequencing: pcie-m2: Create serdev device for WCN7850 bluetooth")
Closes: https://sashiko.dev/#/bug/linux-bd17e5b1-a000-4717-b392-0ff0c2a9c376
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/power/sequencing/pwrseq-pcie-m2.c | 36 +++++++++++++++----------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
index 56c5d51293c10faba6c978265bcd07a6980d2a52..60990760287fdd51c29ccf0e3b97a244669e4837 100644
--- a/drivers/power/sequencing/pwrseq-pcie-m2.c
+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -533,6 +533,14 @@ static int pwrseq_pcie_m2_create_serdev(struct pwrseq_pcie_m2_ctx *ctx)
return ret;
}
+static void pwrseq_pcie_m2_free_regulators(void *data)
+{
+ struct pwrseq_pcie_m2_ctx *ctx = data;
+
+ regulator_bulk_free(ctx->num_vregs, ctx->regs);
+ kfree(ctx->regs);
+}
+
static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -563,19 +571,19 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
ctx->num_vregs = ret;
+ ret = devm_add_action_or_reset(dev, pwrseq_pcie_m2_free_regulators, ctx);
+ if (ret)
+ return ret;
+
ctx->w_disable1_gpio = devm_gpiod_get_optional(dev, "w-disable1", GPIOD_OUT_HIGH);
- if (IS_ERR(ctx->w_disable1_gpio)) {
- ret = dev_err_probe(dev, PTR_ERR(ctx->w_disable1_gpio),
+ if (IS_ERR(ctx->w_disable1_gpio))
+ return dev_err_probe(dev, PTR_ERR(ctx->w_disable1_gpio),
"Failed to get the W_DISABLE_1# GPIO\n");
- goto err_free_regulators;
- }
ctx->w_disable2_gpio = devm_gpiod_get_optional(dev, "w-disable2", GPIOD_OUT_HIGH);
- if (IS_ERR(ctx->w_disable2_gpio)) {
- ret = dev_err_probe(dev, PTR_ERR(ctx->w_disable2_gpio),
+ if (IS_ERR(ctx->w_disable2_gpio))
+ return dev_err_probe(dev, PTR_ERR(ctx->w_disable2_gpio),
"Failed to get the W_DISABLE_2# GPIO\n");
- goto err_free_regulators;
- }
config.parent = dev;
config.owner = THIS_MODULE;
@@ -584,11 +592,9 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
config.targets = ctx->pdata->targets;
ctx->pwrseq = devm_pwrseq_device_register(dev, &config);
- if (IS_ERR(ctx->pwrseq)) {
- ret = dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
+ if (IS_ERR(ctx->pwrseq))
+ return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
"Failed to register the power sequencer\n");
- goto err_free_regulators;
- }
mutex_init(&ctx->list_lock);
INIT_LIST_HEAD(&ctx->pci_devices);
@@ -613,9 +619,6 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
pwrseq_pcie_m2_remove_serdev(ctx, NULL);
err_destroy_mutex:
mutex_destroy(&ctx->list_lock);
-err_free_regulators:
- regulator_bulk_free(ctx->num_vregs, ctx->regs);
- kfree(ctx->regs);
return ret;
}
@@ -627,9 +630,6 @@ static void pwrseq_pcie_m2_remove(struct platform_device *pdev)
bus_unregister_notifier(&pci_bus_type, &ctx->nb);
pwrseq_pcie_m2_remove_serdev(ctx, NULL);
mutex_destroy(&ctx->list_lock);
-
- regulator_bulk_free(ctx->num_vregs, ctx->regs);
- kfree(ctx->regs);
}
static const struct of_device_id pwrseq_pcie_m2_of_match[] = {
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init()
2026-11-05 8:28 [PATCH v2 0/2] power: sequencing: fix use-after-free in pwrseq-pcie-m2 Bartosz Golaszewski
2026-11-05 8:28 ` [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable() Bartosz Golaszewski
@ 2026-11-05 8:28 ` Bartosz Golaszewski
2026-11-05 8:39 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-11-05 8:28 UTC (permalink / raw)
To: Manivannan Sadhasivam, Bartosz Golaszewski
Cc: Manivannan Sadhasivam, linux-pci, linux-pm, linux-kernel,
Bartosz Golaszewski
Shrink the probe() error path and remove() by switching to using the
managed variant of mutex_init()
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
drivers/power/sequencing/pwrseq-pcie-m2.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
index 60990760287fdd51c29ccf0e3b97a244669e4837..4f283af8b0147a3eeb322b777f5e52e7d1c3d753 100644
--- a/drivers/power/sequencing/pwrseq-pcie-m2.c
+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -596,14 +596,17 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
return dev_err_probe(dev, PTR_ERR(ctx->pwrseq),
"Failed to register the power sequencer\n");
- mutex_init(&ctx->list_lock);
+ ret = devm_mutex_init(dev, &ctx->list_lock);
+ if (ret)
+ return ret;
+
INIT_LIST_HEAD(&ctx->pci_devices);
ctx->dev = dev;
/* Create serdev for available PCI devices (if required) */
ret = pwrseq_pcie_m2_create_serdev(ctx);
if (ret)
- goto err_destroy_mutex;
+ return ret;
/*
* Register a notifier for creating protocol devices for
@@ -611,14 +614,7 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
*/
ret = pwrseq_pcie_m2_register_notifier(ctx);
if (ret)
- goto err_remove_serdev;
-
- return 0;
-
-err_remove_serdev:
- pwrseq_pcie_m2_remove_serdev(ctx, NULL);
-err_destroy_mutex:
- mutex_destroy(&ctx->list_lock);
+ pwrseq_pcie_m2_remove_serdev(ctx, NULL);
return ret;
}
@@ -629,7 +625,6 @@ static void pwrseq_pcie_m2_remove(struct platform_device *pdev)
bus_unregister_notifier(&pci_bus_type, &ctx->nb);
pwrseq_pcie_m2_remove_serdev(ctx, NULL);
- mutex_destroy(&ctx->list_lock);
}
static const struct of_device_id pwrseq_pcie_m2_of_match[] = {
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable()
2026-11-05 8:28 ` [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable() Bartosz Golaszewski
@ 2026-11-05 8:38 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-05 8:38 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linux-pci
> During device teardown or on the probe error path, a concurrent consumer
> access triggers a use-after-free in pwrseq_pcie_m2_vregs_enable() or
> pwrseq_pcie_m2_vregs_disable() due to a lifetime inversion between
> devm-managed device registration and manual resource cleanup.
>
> The driver exposes the power sequencer using devm_pwrseq_device_register(),
> meaning the device remains fully registered and accessible on the
> pwrseq_bus until the driver core schedules devm_pwrseq_device_unregister()
> to run after pwrseq_pcie_m2_remove() returns. However, the driver performs
> manual resource teardown within pwrseq_pcie_m2_remove() and the
> pwrseq_pcie_m2_probe() error path, prematurely destroying the backing
> regulator array.
>
> This creates a narrow vulnerability window where the globally visible power
> sequencer is backed by freed memory. If a concurrent consumer invokes
> pwrseq_enable() during this window, execution is routed to the sequencer
> callback and dereferences the destroyed ctx->regs array, resulting in a
> direct use-after-free and a kernel crash.
>
> Schedule a devres action for freeing the memory used for the regulator
> array to ensure it runs *after* the pwrseq provider was unregistered.
>
> Cc: stable@vger.kernel.org
> Fixes: 3f736aecbdc8 ("power: sequencing: pcie-m2: Create serdev device for WCN7850 bluetooth")
> Closes: https://sashiko.dev/#/bug/linux-bd17e5b1-a000-4717-b392-0ff0c2a9c376
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-pwrseq-pcie-m2-uaf-v2-0-3e1dd415af9a@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init()
2026-11-05 8:28 ` [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init() Bartosz Golaszewski
@ 2026-11-05 8:39 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-05 8:39 UTC (permalink / raw)
To: Bartosz Golaszewski; +Cc: linux-pci
> Shrink the probe() error path and remove() by switching to using the
> managed variant of mutex_init()
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-pwrseq-pcie-m2-uaf-v2-0-3e1dd415af9a@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-05 8:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 8:28 [PATCH v2 0/2] power: sequencing: fix use-after-free in pwrseq-pcie-m2 Bartosz Golaszewski
2026-11-05 8:28 ` [PATCH v2 1/2] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable() Bartosz Golaszewski
2026-11-05 8:38 ` sashiko-bot
2026-11-05 8:28 ` [PATCH v2 2/2] power: sequencing: pcie-m2: use devm_mutex_init() Bartosz Golaszewski
2026-11-05 8:39 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox