All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xuanqiang Luo <xuanqiang.luo@linux.dev>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev@vger.kernel.org, hkallweit1@gmail.com,
	linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org,
	Xuanqiang Luo <luoxuanqiang@kylinos.cn>,
	stable@vger.kernel.org
Subject: Re: [PATCH net v1] net: phy: fix NULL deref in IRQ handler after unbind
Date: Wed, 26 Aug 2026 15:54:47 +0800	[thread overview]
Message-ID: <b75e9ae4-ba79-4c0b-a3c5-da270de0b75b@linux.dev> (raw)
In-Reply-To: <667fb4ef-0822-432f-ad0e-aeb4bf66dccf@lunn.ch>

Hi Andrew,

在 2026/8/25 21:03, Andrew Lunn 写道:

> On Tue, Aug 25, 2026 at 11:34:04AM +0800, Xuanqiang Luo wrote:
>> Hi Andrew,
>>
>> 在 2026/8/24 20:54, Andrew Lunn 写道:
>>
>>>> The IRQ is requested at attach time and released by phy_disconnect(),
>>>> so phy_remove() cannot free it without a later double-free.
>>> So this sounds wrong.
>>>
>>> If you unbind the PHY, you need to also unbind the MAC, since a MAC
>>> without a PHY is useless. When the MAC unloads, it will call
>>> phy_remove() so everything unwinds in the correct order.
>>>
>>>       Andrew
>>>
>>> ---
>>> pw-bot: cr
>>> 	
>> I agree that the MAC should normally be unbound before the PHY.
>>
>> Also, the paragraph about freeing the IRQ in phy_remove() was
>> misleading. It was not relevant to the change being proposed,
>> so I will drop it in v2.
>>
>> Do you mean that unbinding the PHY first through sysfs is not a
>> supported operation?
> To me, unbind is an odd thing to do. What is your use case?

I don't have a real use case for unbinding the PHY while keeping the
MAC bound. I found this during code review and used sysfs unbind to
reproduce the crash.

> When doing development work, i tend to reboot the target. If not, i
> would unload the MAC driver and the PHY driver, to ensure i have a
> clean state.
>
>> The same sequence was used to reproduce the issue fixed by commit
>> c2b727df7caa ("net: phy: Avoid NPD upon phy_detach() when driver is
>> unbound"), which made me think that it should at least not crash:
>>
>> https://lore.kernel.org/all/20200917034310.2360488-2-f.fainelli@gmail.com/
> A crash is not good.
>
> But we also need to look, is the fix the correct architecturally, or
> we are actually making it worse. Drivers have function pairs. A
> function which does setup, and a mirror function which does
> tairdown. A function to bind to a MAC and a mirror which unbinds from
> a MAC. That symmetry makes drivers simple, easy to reason about.

Thanks for clarifying. I agree.

> Does this problem happen if you keep to the symmetry?

No. I checked the normal teardown path, and the problem does not occur
when the symmetric teardown order is followed. This is expected.

> Does your fix to this problem make the symmetry worse?

The normal teardown path is unchanged, but the patch allows the
asymmetric state created by a PHY-first unbind to continue with the IRQ
still installed. From that point of view, the fix is wrong.

> If unbind were to cause the MAC to unload, is the symmetry kept?

Yes. I agree that this is the right direction. I will stop here and
think more carefully about how to enforce the ordering before posting
another version.

Thanks,
Xuanqiang


      reply	other threads:[~2026-08-26  7:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 12:07 [PATCH net v1] net: phy: fix NULL deref in IRQ handler after unbind Xuanqiang Luo
2026-08-24 12:54 ` Andrew Lunn
2026-08-25  3:34   ` Xuanqiang Luo
2026-08-25 13:03     ` Andrew Lunn
2026-08-26  7:54       ` Xuanqiang Luo [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=b75e9ae4-ba79-4c0b-a3c5-da270de0b75b@linux.dev \
    --to=xuanqiang.luo@linux.dev \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luoxuanqiang@kylinos.cn \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.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 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.