Linux USB
 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 v18 02/13] phylib: Add support for PHYs with broken forced mode
Date: Fri, 09 Oct 2026 03:51:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-164798@kernel.org> (raw)
In-Reply-To: <20261008-ax88179a-v18-2-6fa1d4c40422@birger-koblitz.de>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] phy: TOCTOU race allowing NULL pointer dereference in phy_mii_ioctl and phy_ethtool_ksettings_set
- [Medium] net: phy: data race modifying bitfields in phy_mii_ioctl
- [Medium] net: phy: SIOCSMIIREG C45 writes misinterpret MMDs as C22 registers
--

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

phylib: Add support for PHYs with broken forced mode

This adds support for PHYs which only support auto-negotiated speed modes,
preventing a kernel warning and stack-trace when PHYs return -EOPNOTSUPP
from config_aneg() for forced modes.

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index fce9bc7be3304..079c53516f424 100644
> --- 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:

[Severity: Medium]
Does this switch statement evaluate Clause 45 MMDs against Clause 22
register macros?

In phy_mii_ioctl(), devad contains the MMD for C45 writes:

	case SIOCSMIIREG:
		if (mdio_phy_id_is_c45(mii_data->phy_id)) {
			prtad = mdio_phy_id_prtad(mii_data->phy_id);
			devad = mdio_phy_id_devad(mii_data->phy_id);

If a user issues an SIOCSMIIREG ioctl targeting a Clause 45 PHY and
writes to MMD 4 (PHY XS), devad will be 4. Doesn't this hit the
MII_ADVERTISE case below, incorrectly corrupting phydev->advertising?

Additionally, will the newly added logic here improperly intercept C45 writes
to MMD 0?

>  				if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
> +					if (phydev->drv &&
> +					    (phydev->drv->flags & PHY_BROKEN_FORCED))

[Severity: High]
Can the compiler double-fetch phydev->drv here without locks, risking a NULL
pointer dereference?

If an asynchronous driver unbind occurs via sysfs:

echo <phy_id> > /sys/bus/mdio_bus/drivers/<drv>/unbind

This calls phy_remove(), which clears phydev->drv to NULL without acquiring
phydev->lock. Could the second fetch of phydev->drv in the condition above
yield NULL, leading to a kernel panic when dereferencing flags?

> +						return -EOPNOTSUPP;
>  					if (phydev->autoneg == AUTONEG_ENABLE)
>  						change_autoneg = true;
>  					phydev->autoneg = AUTONEG_DISABLE;

[Severity: Medium]
Is it safe to modify phydev->autoneg and phydev->duplex locklessly here?

These fields are part of a bitfield block in struct phy_device:

	unsigned autoneg:1;
	unsigned link:1;
	unsigned autoneg_complete:1;

phy_state_machine() modifies adjacent bitfields (like link and
autoneg_complete) asynchronously while holding phydev->lock. Because they
share the same memory word, could this lockless assignment in phy_mii_ioctl()
cause a read-modify-write race that silently overwrites the state machine's
updates?

[ ... ]
> @@ -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))

[Severity: High]
Similar to the check in phy_mii_ioctl(), can the compiler double-fetch
phydev->drv here before phydev->lock is taken?

If phy_remove() clears phydev->drv concurrently, could the second load yield
NULL and cause a dereference crash?

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-ax88179a-v18-0-6fa1d4c40422@birger-koblitz.de?part=2

  reply	other threads:[~2026-10-09  3:51 UTC|newest]

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

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-164798@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox