Skip to contentSkip to conversation

net: lan966x: fix kernel oops on ioctl when I/F is down

PATCH Michael Walle 2 participants 2 messages Mar 26, 2022 – Mar 28, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Am 2022-03-26 03:17, schrieb Andrew Lunn:

Quoted 9 lines · Michael Walle
Quoted 2 lines

A SIOCGMIIPHY ioctl will cause a kernel oops when the interface is down. Fix it by checking the state and if it's no running, return an error.

s/no/not/

I don't think it is just SIOCGMIIPHY. phy_has_hwtstamp(dev->phydev) is probably also an issue. The phy is connected in open, and disconnected in stop. So dev->phydev is not valid outside of that time.

phy_has_hwtstamp() handles NULL gracefully. And I guess the MAC timestamp handling is working if there is no phydev. Not sure if the interface has to be up though.

Quoted 3 lines

But i'm also not sure it is guaranteed to be valid while the interface is up. The driver uses phylink, so there could be an SFP attached to a port, in which case, dev->phydev will not be set.

I wonder if we should use phylink_mii_ioctl() here. Maybe as a seperate patch for the net-next if its open again?

Quoted 2 lines

So rather than testing of running, it would be better to test if the phydev is NULL or not.

What about the following:

static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr,
int cmd)

{
	struct lan966x_port *port = netdev_priv(dev);

	if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) {
		switch (cmd) {
		case SIOCSHWTSTAMP:
			return lan966x_ptp_hwtstamp_set(port, ifr);
		case SIOCGHWTSTAMP:
			return lan966x_ptp_hwtstamp_get(port, ifr);
		}
	}

	if (!dev->phydev)
		return -ENODEV;

	return phy_mii_ioctl(dev->phydev, ifr, cmd);
}

-michael

#1 lore raw
Quoted 7 lines
Quoted 2 lines

So rather than testing of running, it would be better to test if the phydev is NULL or not.

What about the following:

static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr,
int cmd)

Quoted 16 lines
{
	struct lan966x_port *port = netdev_priv(dev);

	if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) {
		switch (cmd) {
		case SIOCSHWTSTAMP:
			return lan966x_ptp_hwtstamp_set(port, ifr);
		case SIOCGHWTSTAMP:
			return lan966x_ptp_hwtstamp_get(port, ifr);
		}
	}

	if (!dev->phydev)
		return -ENODEV;

	return phy_mii_ioctl(dev->phydev, ifr, cmd);

Yes, that is good.

Andrew