All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable()
Date: Wed, 04 Nov 2026 16:28:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-197610@kernel.org> (raw)
In-Reply-To: <20261104-pwrseq-pcie-m2-uaf-v1-1-0ae1bbea9533@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] power: sequencing: overwritten ret zeroes num_vregs in pwrseq_pcie_m2_probe()
--

commit 4538b4fe7cf3308c45ac12f332947a46b82e94d0
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable()

This commit replaces manual regulator cleanup in pwrseq_pcie_m2_remove() and
the pwrseq_pcie_m2_probe() error path with a devres action so that the
regulator array is freed only after devm_pwrseq_device_unregister() runs.

> diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
> index 56c5d51293c10..a794e2ad6a9c8 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;
> @@ -561,21 +569,21 @@ static int pwrseq_pcie_m2_probe(struct platform_device *pdev)
>  		return dev_err_probe(dev, ret,
>  				     "Failed to get all regulators\n");
>  
> +	ret = devm_add_action_or_reset(dev, pwrseq_pcie_m2_free_regulators, ctx);
> +	if (ret)
> +		return ret;
> +
>  	ctx->num_vregs = ret;

[Severity: High]
In drivers/power/sequencing/pwrseq-pcie-m2.c, pwrseq_pcie_m2_probe() stores
the number of regulators returned by of_regulator_bulk_get_all() in ret, but
then overwrites ret with the return value of devm_add_action_or_reset()
before setting ctx->num_vregs = ret.

When devm_add_action_or_reset() succeeds, ret is 0, so ctx->num_vregs is
always set to 0. Doesn't this cause pwrseq_pcie_m2_vregs_enable() and
pwrseq_pcie_m2_vregs_disable() to pass 0 to regulator_bulk_enable() and
regulator_bulk_disable(), leaving the M.2 connector regulators unpowered?

Also, because ctx->num_vregs is 0 both during devm_add_action_or_reset() and
afterward, pwrseq_pcie_m2_free_regulators() will call
regulator_bulk_free(0, ctx->regs) and leak the struct regulator references in
ctx->regs before freeing the array. Should ctx->num_vregs = ret be assigned
before calling devm_add_action_or_reset()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-pwrseq-pcie-m2-uaf-v1-1-0ae1bbea9533@oss.qualcomm.com?part=1

      reply	other threads:[~2026-11-04 16:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 16:21 [PATCH] power: sequencing: pcie-m2: fix use-after-free in pwrseq_pcie_m2_vregs_enable() Bartosz Golaszewski
2026-11-04 16:28 ` sashiko-bot [this message]

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=sashiko-outbox-197610@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.