Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps

From: Andrew Lunn

Date: Wed Nov 25 2026 - 21:58:19 EST


On Thu, Nov 26, 2026 at 09:52:39AM +0800, YuanZhe Liu wrote:
> ethtool_get_regs() passes the user-supplied regs.len to the driver
> unchanged, including zero. A driver that uses that length for its I/O
> then issues a zero-length transfer. Such a transfer has no data stage
> and the USB core treats it as an OUT transfer, so a driver submitting
> it on the receive pipe trips the direction check:
>
> usb 1-1: BOGUS control dir, pipe 80000380 doesn't match bRequestType c0
> WARNING: drivers/usb/core/urb.c:411 at usb_submit_urb

Your commit message is focusing on USB too much. Very few Ethernet
drivers are USB. Since you are modifying the core, you should make the
commit message generic.

> A zero-length dump cannot return any data, so there is nothing for the
> driver to do. Return success without calling into the driver, the same
> way a zero-length read is a no-op, instead of making every driver check
> regs->len.

> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

Who does this bother?

> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 80b7930b3fe0..e8af861ee5de 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -1779,6 +1779,10 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
> if (copy_from_user(&regs, useraddr, sizeof(regs)))
> return -EFAULT;
>
> + /* A zero-length dump has nothing to fill in. */
> + if (!regs.len)
> + return 0;
> +

Some of the kAPIs consider passing 0 as being special. It is user
space asking the kernel how big a buffer is needed to hold the full
dump. The kernel sets the value in the structure and returns. User
space then allocates a buffer of that size, and makes the request
again.

I don't know if this API actually does this. You need to look at the
logic and decide. But by returning this early, if it did, you have
broken that.

Andrew