All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Birger Koblitz" <mail@birger-koblitz.de>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH net-next v19 02/13] phylib: Add support for PHYs with broken forced mode
Date: Sun, 11 Oct 2026 04:54:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-167014@kernel.org> (raw)
In-Reply-To: <20261010-ax88179a-v19-2-7475173cfb56@birger-koblitz.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] phy: C45 MDIO writes falsely trigger C22 register handlers corrupting state
- [High] phylib: NULL pointer deref due to TOCTOU race on phydev->drv
--

commit f3ec63e34d550025dac6b66482995851d8d99969
Author: Birger Koblitz <mail@birger-koblitz.de>

phylib: Add support for PHYs with broken forced mode

This commit adds support for PHYs which only support auto-negotiated speed
modes. This prevents a kernel warning and stack-trace within the
phy_state_machine when PHYs return -EOPNOTSUPP from config_aneg() because
they do not support forced modes.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c

[ ... ]

> @@ -354,6 +354,9 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
>  			switch (devad) {
>  			case MII_BMCR:
>  				if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
> +					if (phydev->drv &&
> +					    (phydev->drv->flags & PHY_BROKEN_FORCED))
> +						return -EOPNOTSUPP;

[Severity: High]
Can this unlocked check on phydev->drv lead to a NULL pointer dereference?

If a concurrent sysfs unbind calls phy_remove() and sets phydev->drv = NULL
without holding rtnl_lock or phydev->lock, the compiler might fetch
phydev->drv to verify it is non-NULL, and then fetch it again to read flags.
This double-fetch could result in a NULL pointer dereference if the pointer
is cleared between the two operations.

Also, for C45 accesses in phy_mii_ioctl(), devad holds the MMD address but
is matched against C22 register definitions like MII_BMCR (which is 0). 

Does adding this early return mean a C45 write to MMD 0 (with zeroed reset
and anenable bits) will now incorrectly hit this C22 handler and fail with
-EOPNOTSUPP?

[ ... ]

> @@ -1190,6 +1193,10 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
>  	      duplex != DUPLEX_FULL)))
>  		return -EINVAL;
>  
> +	if (autoneg == AUTONEG_DISABLE && phydev->drv &&
> +	    (phydev->drv->flags & PHY_BROKEN_FORCED))
> +		return -EOPNOTSUPP;

[Severity: High]
Does this present the same time-of-check to time-of-use race as above?

A sysfs unbind could set phydev->drv to NULL between the NULL check and the
flags dereference, since ethtool operations and unbind operations do not
share a common lock here.

> +
>  	mutex_lock(&phydev->lock);
>  	phydev->autoneg = autoneg;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261010-ax88179a-v19-0-7475173cfb56@birger-koblitz.de?part=2

  reply	other threads:[~2026-10-11  4:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10  4:54 [PATCH net-next v19 00/13] ax88179_178a: Add support for AX88179A-based chips Birger Koblitz
2026-10-10  4:54 ` [PATCH net-next v19 01/13] phylink: Add phylink_mac_interrupt Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-11  5:32     ` Birger Koblitz
2026-10-10  4:54 ` [PATCH net-next v19 02/13] phylib: Add support for PHYs with broken forced mode Birger Koblitz
2026-10-11  4:54   ` sashiko-bot [this message]
2026-10-10  4:54 ` [PATCH net-next v19 03/13] ax88179_178a: Split driver into library and device specific code Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 04/13] ax88179_178a: Add HW support for AX179A-based chips Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 05/13] ax88179_178a: Add EEE configuration support for AX88179A MACs Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 07/13] ax88179_178a: Add VLAN offload support for AX88179A Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 08/13] ax88179_178a: Add AX179A/AX279 multicast configuration Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279 Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 10/13] ax88179_178a: Add ethtool get_drvinfo Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 11/13] ax88179_178a: Update driver name and information Birger Koblitz
2026-10-11  4:54   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access Birger Koblitz
2026-10-11  4:55   ` sashiko-bot
2026-10-10  4:54 ` [PATCH net-next v19 13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279 Birger Koblitz
2026-10-11  4:55   ` sashiko-bot
2026-10-10  6:20 ` [PATCH v19 0/13] ax88179_178a: Add support for AX88179A-based chips Jianhui Xu
2026-10-10  7:42   ` Birger Koblitz

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=sashiko-outbox-167014@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --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.