From: sashiko-bot@kernel.org
To: "Petr Wozniak" <petr.wozniak@gmail.com>
Cc: neil.armstrong@linaro.org, vkoul@kernel.org,
linux-phy@lists.infradead.org, olteanv@gmail.com
Subject: Re: [PATCH net-next v3 1/2] net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy
Date: Wed, 24 Jun 2026 08:05:50 +0000 [thread overview]
Message-ID: <20260624080551.0F3C81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623080538.7646-2-petr.wozniak@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The delayed works (`sfp->poll` and `sfp->timeout`) can execute after their dependent GPIO descriptors and IRQs are released, leading to Use-After-Free.
--
commit 318c6861220a57086d547ce894cf1c029a4d3639
Author: Petr Wozniak <petr.wozniak@gmail.com>
net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy
sfp_i2c_mdiobus_create() allocates the I2C MDIO bus with mdio_i2c_alloc(),
a plain (non-devm) allocation, and registers it. sfp_i2c_mdiobus_destroy()
only unregisters the bus and clears sfp->i2c_mii without calling
mdiobus_free(). As the only reference to the bus is then cleared, the
struct mii_bus is leaked.
> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 03bfd8640db96..c4d274ab651e3 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -963,6 +963,7 @@ static int sfp_i2c_mdiobus_create(struct sfp *sfp)
> static void sfp_i2c_mdiobus_destroy(struct sfp *sfp)
> {
> mdiobus_unregister(sfp->i2c_mii);
> + mdiobus_free(sfp->i2c_mii);
> sfp->i2c_mii = NULL;
> }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the teardown
path I noticed a potential use-after-free during device unbind or module
removal.
In sfp_probe(), sfp_cleanup() is registered before allocating the GPIO
descriptors:
drivers/net/phy/sfp.c:sfp_probe() {
...
err = devm_add_action_or_reset(sfp->dev, sfp_cleanup, sfp);
if (err < 0)
return err;
...
for (i = 0; i < GPIO_MAX; i++)
if (sff->gpios & BIT(i)) {
sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev,
gpio_names[i], gpio_flags[i]);
...
}
During unbind, devres runs cleanup actions in reverse LIFO order, meaning
the GPIO descriptors are freed first.
sfp_remove() doesn't cancel sfp->poll. If sfp->need_poll is true, the poll
worker could fire and access the freed GPIO descriptors before sfp_cleanup()
finally cancels it:
drivers/net/phy/sfp.c:sfp_cleanup() {
...
cancel_delayed_work_sync(&sfp->poll);
cancel_delayed_work_sync(&sfp->timeout);
...
}
Could this lead to a panic when unbinding the device or removing the module?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260623080538.7646-1-petr.wozniak@gmail.com?part=1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-06-24 8:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 8:05 [PATCH net-next v3 0/2] net: phy: sfp/mdio-i2c: defer RollBall probe + fix mii_bus leak Petr Wozniak
2026-06-23 8:05 ` [PATCH net-next v3 1/2] net: phy: sfp: free mii_bus in sfp_i2c_mdiobus_destroy Petr Wozniak
2026-06-23 16:23 ` Maxime Chevallier
2026-06-24 8:05 ` sashiko-bot [this message]
2026-06-23 8:05 ` [PATCH net-next v3 2/2] net: phy: mdio-i2c: defer RollBall bridge probe to PHY discovery Petr Wozniak
2026-06-23 16:28 ` Maxime Chevallier
2026-06-24 8:05 ` sashiko-bot
2026-06-23 16:34 ` [PATCH net-next v3 0/2] net: phy: sfp/mdio-i2c: defer RollBall probe + fix mii_bus leak Maxime Chevallier
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=20260624080551.0F3C81F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=petr.wozniak@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox