Re: [RFC PATCH net-next 05/10] net: hibmcge: Implement some .ndo functions
From: Andrew Lunn
Date: Thu Aug 01 2024 - 08:37:06 EST
On Thu, Aug 01, 2024 at 08:33:38PM +0800, Jijie Shao wrote:
>
> on 2024/8/1 20:18, Andrew Lunn wrote:
> > On Thu, Aug 01, 2024 at 05:13:33PM +0800, Jijie Shao wrote:
> > > on 2024/8/1 8:51, Andrew Lunn wrote:
> > > > > +static int hbg_net_set_mac_address(struct net_device *dev, void *addr)
> > > > > +{
> > > > > + struct hbg_priv *priv = netdev_priv(dev);
> > > > > + u8 *mac_addr;
> > > > > +
> > > > > + mac_addr = ((struct sockaddr *)addr)->sa_data;
> > > > > + if (ether_addr_equal(dev->dev_addr, mac_addr))
> > > > > + return 0;
> > > > > +
> > > > > + if (!is_valid_ether_addr(mac_addr))
> > > > > + return -EADDRNOTAVAIL;
> > > > How does the core pass you an invalid MAC address?
> > > According to my test,
> > > in the 6.4 rc4 kernel version, invalid mac address is allowed to be configured.
> > > An error is reported only when ifconfig ethx up.
> > Ah, interesting.
> >
> > I see a test in __dev_open(), which is what you are saying here. But i
> > would also expect a test in rtnetlink, or maybe dev_set_mac_address().
> > We don't want every driver having to repeat this test in their
> > .ndo_set_mac_address, when it could be done once in the core.
> >
> > Andrew
>
> Hi:
> I did the following test on my device:
>
> insmod hibmcge.ko
> hibmcge: no symbol version for module_layout
> hibmcge: loading out-of-tree module taints kernel.
> hibmcge: module verification failed: signature and/or required key missing - tainting kernel
> hibmcge 0000:83:00.1: enabling device (0140 -> 0142)
> Generic PHY mii-0000:83:00.1:02: attached PHY driver (mii_bus:phy_addr=mii-0000:83:00.1:02, irq=POLL)
> hibmcge 0000:83:00.1 enp131s0f1: renamed from eth0
> IPv6: ADDRCONF(NETDEV_CHANGE): enp131s0f1: link becomes ready
> hibmcge 0000:83:00.1: link up!
>
> ifconfig enp131s0f1 hw ether FF:FF:FF:FF:FF:FF
>
> ip a
> 6: enp131s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
> link/ether ff:ff:ff:ff:ff:ff brd ff:ff:ff:ff:ff:ff permaddr 08:02:00:00:08:08
> ifconfig enp131s0f1 up
> ifconfig enp131s0f1 down up
> SIOCSIFFLAGS: Cannot assign requested address
> hibmcge 0000:83:00.1: link down!
>
> uname -a
> Linux localhost.localdomain 6.4.0+ #1 SMP Fri Mar 15 14:44:20 CST 2024 aarch64 aarch64 aarch64 GNU/Linux
>
>
>
> So I'm not sure what's wrong. I also implemented ndo_validate_addr by eth_validate_addr.
I agree. I don't see a test. Please could you include a patch to
dev_set_mac_address() to validate the address there before calling
into the driver. It might also be worth a search to see if anybody
else has tried this before, and failed. There might be a good reason
you cannot validate it.
Andrew