From: Carlo Szelinsky <github@szelinsky.de>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
Kory Maincent <kory.maincent@bootlin.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Carlo Szelinsky <github@szelinsky.de>
Subject: [PATCH net v2 1/2] net: pse-pd: stop async event sources before freeing PI data in unregister
Date: Sat, 11 Jul 2026 14:16:10 +0200 [thread overview]
Message-ID: <20260711121611.1639086-2-github@szelinsky.de> (raw)
In-Reply-To: <20260711121611.1639086-1-github@szelinsky.de>
pse_controller_unregister() frees resources that its own asynchronous
event sources are still using:
* The PI array (pcdev->pi) is freed by pse_release_pis() while the
threaded IRQ handler pse_isr() can still be running. pse_isr() walks
pcdev->pi[] (via pse_set_config_isr() and
regulator_notifier_call_chain() on pcdev->pi[i].rdev), so an interrupt
arriving before disable_irq() dereferences freed memory.
* pse_flush_pw_ds() runs before disable_irq() and drops the power domain
references, which can free pw_d->supply via __pse_pw_d_release().
A concurrent interrupt reaches that supply through
_pse_pi_disable() -> pse_pw_d_retry_power_delivery() ->
regulator_request_power_budget(pw_d->supply), another use-after-free.
* cancel_work_sync(&pcdev->ntf_work) runs after pse_release_pis(), but
the notification worker reaches pcdev->pi too: pse_send_ntf_worker()
-> pse_control_put() -> __pse_control_release() dereferences
psec->pcdev->pi[psec->id].admin_state_enabled. Draining the worker
after the PI array is freed is therefore also a use-after-free.
Reorder teardown so every asynchronous accessor is stopped first:
disable the IRQ, drain the notification worker, and only then flush the
power domains and release the PI array.
Fixes: ffef61d6d273 ("net: pse-pd: Add support for budget evaluation strategies")
Signed-off-by: Carlo Szelinsky <github@szelinsky.de>
---
drivers/net/pse-pd/pse_core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
index a5e6d7b26b9f..6045b6c399c2 100644
--- a/drivers/net/pse-pd/pse_core.c
+++ b/drivers/net/pse-pd/pse_core.c
@@ -1114,11 +1114,15 @@ EXPORT_SYMBOL_GPL(pse_controller_register);
*/
void pse_controller_unregister(struct pse_controller_dev *pcdev)
{
- pse_flush_pw_ds(pcdev);
- pse_release_pis(pcdev);
+ /* Stop the IRQ and notification worker before freeing what they
+ * reach: both touch pcdev->pi, and the IRQ also uses pw_d->supply
+ * that pse_flush_pw_ds() drops.
+ */
if (pcdev->irq)
disable_irq(pcdev->irq);
cancel_work_sync(&pcdev->ntf_work);
+ pse_flush_pw_ds(pcdev);
+ pse_release_pis(pcdev);
kfifo_free(&pcdev->ntf_fifo);
mutex_lock(&pse_list_mutex);
list_del(&pcdev->list);
--
2.43.0
next prev parent reply other threads:[~2026-07-11 12:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 12:16 [PATCH net v2 0/2] net: pse-pd: fix use-after-free of PI array on controller unregister Carlo Szelinsky
2026-07-11 12:16 ` Carlo Szelinsky [this message]
2026-07-11 12:16 ` [PATCH net v2 2/2] net: pse-pd: guard regulator ops against freed PI data during unregister 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=20260711121611.1639086-2-github@szelinsky.de \
--to=github@szelinsky.de \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
/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.