Netdev List
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: FUJITA Tomonori <tomo@flapping.org>
Cc: fujita.tomonori@gmail.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org, hfdevel@gmx.net
Subject: Re: [PATCH net-next v2 1/2] net: tn40xx: avoid early firmware node release
Date: Wed, 18 Nov 2026 17:03:31 +0100	[thread overview]
Message-ID: <av3MU5Edsk7kLY2b@hovoldconsulting.com> (raw)
In-Reply-To: <20261118.195534.1289241641818592530.tomo@flapping.org>

On Wed, Nov 18, 2026 at 07:55:34PM +0900, FUJITA Tomonori wrote:
> On Mon, 16 Nov 2026 10:11:48 +0100
> Johan Hovold <johan@kernel.org> wrote:
> 
> > Note that __mdiobus_register() will essentially only return early
> > without taking the reference during development when the bus structure
> > has not been properly initialised. And currently, not even that would
> > lead to a use-after-free as the child PHY node holds a reference to the
> > parent MDIO node, the child is deregistered before the parent, and
> > software_node_unregister() returns early if the parent node has already
> > been freed.
> 
> [...]
> 
> > --- a/drivers/net/ethernet/tehuti/tn40_mdio.c
> > +++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
> > @@ -157,7 +157,12 @@ void tn40_swnodes_cleanup(struct tn40_priv *priv)
> >  {
> >  	/* cleanup of swnodes is only needed for AQR105-based cards */
> >  	if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
> > -		fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
> > +		/*
> > +		 * drop any reference taken by __mdiobus_register() before
> > +		 * device_remove_software_node() clears the fwnode pointer
> > +		 */
> > +		if (priv->mdio->state != MDIOBUS_ALLOCATED)
> > +			fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
> 
> mdio->state is internal to the MDIO core. I don't think drivers should
> look at it.

Some are, including this driver (if only for an error message).

I agree that they probably should not, but this highlights the existing
problem with the driver further.
 
> Also, 2/2 removes this code. The put is unbalanced when mdio bus
> registration bails out before taking the reference, but it does no
> real harm, as you explain in the commit message.

But that's mostly by chance. The whole thing is quite fragile.
 
> So I think we can drop this patch and fix the problem with 2/2 only.
> The explanation in this commit message could go into the 2/2 commit
> message.

Sure, I'll squash them.

Johan

  reply	other threads:[~2026-11-18 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:11 [PATCH net-next v2 0/2] net: tn40xx: avoid early firmware node release Johan Hovold
2026-11-16  9:11 ` [PATCH net-next v2 1/2] " Johan Hovold
2026-11-18 10:55   ` FUJITA Tomonori
2026-11-18 16:03     ` Johan Hovold [this message]
2026-11-16  9:11 ` [PATCH net-next v2 2/2] net: tn40xx: switch to primary software node Johan Hovold

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=av3MU5Edsk7kLY2b@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=hfdevel@gmx.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tomo@flapping.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