All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Carlo Szelinsky" <github@szelinsky.de>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next v8 3/7] net: pse-pd: unwind allocations when controller registration fails
Date: Mon, 05 Oct 2026 16:43:05 +0000	[thread overview]
Message-ID: <20261005164306.0BDF21F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261004164219.1161294-4-github@szelinsky.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: pse-pd: TOCTOU race and NULL pointer dereference via unguarded pcdev->pi[i].pw_d assignment
--

commit 8c5741051355bc530c2efc50d6e4e9ebe8e283f3
Author: Carlo Szelinsky <github@szelinsky.de>

net: pse-pd: unwind allocations when controller registration fails

This commit unwinds allocations when pse_controller_register() fails. It
updates the error paths to properly free the notification kfifo, flush
the power domains, and clear the power domain pointers to NULL to avoid
dangling references.

> diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
> --- a/drivers/net/pse-pd/pse_core.c
> +++ b/drivers/net/pse-pd/pse_core.c
> @@ -937,11 +937,21 @@ static void pse_flush_pw_ds(struct pse_controller_dev *pcdev)
>  			continue;
>  
>  		pw_d = xa_load(&pse_pw_d_map, pcdev->pi[i].pw_d->id);
> -		if (!pw_d)
> +		if (!pw_d) {
> +			pcdev->pi[i].pw_d = NULL;
>  			continue;
> +		}
>  
>  		kref_put_mutex(&pw_d->refcnt, __pse_pw_d_release,
>  			       &pse_pw_d_mutex);
> +		/* The pw_d is devm memory of whichever controller created
> +		 * it, so it can go away as soon as that probe unwinds.
> +		 * Nothing may be left pointing at it: pse_pi_is_enabled()
> +		 * reaches pi[].pw_d from the regulator "state" attribute,
> +		 * which stays readable until the PI regulators are
> +		 * unregistered after us.
> +		 */
> +		pcdev->pi[i].pw_d = NULL;

[Severity: High]
Does setting pcdev->pi[i].pw_d to NULL here without holding pcdev->lock
introduce a race condition with concurrent sysfs accesses?

Since the PI regulators are registered via devm_pse_pi_regulator_register()
and accessible via sysfs before pse_flush_pw_ds() is called in the error
path, a concurrent read of the regulator attributes could invoke regulator
operations like pse_pi_is_enabled(). These operations take pcdev->lock and
can call into pse_pi_allocate_pw_budget().

In pse_pi_allocate_pw_budget(), pi->pw_d is evaluated twice without READ_ONCE:

    if (!pi->pw_d)
        return 0;

    /* PSE_BUDGET_EVAL_STRAT_STATIC */
    if (pi->pw_d->budget_eval_strategy == PSE_BUDGET_EVAL_STRAT_STATIC)

If pcdev->pi[i].pw_d is set to NULL concurrently between the null check and
the dereference, could this cause a TOCTOU NULL pointer dereference?

>  	}
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261004164219.1161294-1-github@szelinsky.de?part=3

  reply	other threads:[~2026-10-05 16:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 16:42 [PATCH net-next v8 0/7] net: pse-pd: decouple controller lookup from MDIO probe Carlo Szelinsky
2026-10-04 16:42 ` [PATCH net-next v8 1/7] net: pse-pd: add notifier chain for controller lifecycle events Carlo Szelinsky
2026-10-13  9:39   ` Kory Maincent
2026-10-04 16:42 ` [PATCH net-next v8 2/7] net: pse-pd: fire lifecycle events on controller register/unregister Carlo Szelinsky
2026-10-05 17:33   ` netdev-bot+sashiko
2026-10-13  9:39   ` Kory Maincent
2026-10-04 16:42 ` [PATCH net-next v8 3/7] net: pse-pd: unwind allocations when controller registration fails Carlo Szelinsky
2026-10-05 16:43   ` sashiko-bot [this message]
2026-10-05 17:33   ` netdev-bot+sashiko
2026-10-13  9:39   ` Kory Maincent
2026-10-04 16:42 ` [PATCH net-next v8 4/7] net: pse-pd: si3474: use dev_err_probe() for controller registration Carlo Szelinsky
2026-10-04 16:42 ` [PATCH net-next v8 5/7] net: pse-pd: check the PI vpwr supply before registering the controller Carlo Szelinsky
2026-10-05 17:33   ` netdev-bot+sashiko
2026-10-04 16:42 ` [PATCH net-next v8 6/7] of: property: do not let "pses" block a consumer's probe Carlo Szelinsky
2026-10-05 17:33   ` netdev-bot+sashiko
2026-10-04 16:42 ` [PATCH net-next v8 7/7] net: phy: own phydev->psec via PSE notifier and remove fwnode_mdio hook Carlo Szelinsky
2026-10-05 17:33   ` netdev-bot+sashiko
2026-10-13  7:40 ` [PATCH net-next v8 0/7] net: pse-pd: decouple controller lookup from MDIO probe Paolo Abeni
2026-10-13  8:39   ` Kory Maincent
2026-10-13  9:09     ` Carlo Szelinsky

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=20261005164306.0BDF21F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=github@szelinsky.de \
    --cc=robh@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.