Netdev List
 help / color / mirror / Atom feed
* [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
@ 2026-11-26  1:52 YuanZhe Liu
  2026-11-26  2:58 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: YuanZhe Liu @ 2026-11-26  1:52 UTC (permalink / raw)
  To: Andrew Lunn, Jakub Kicinski, David S. Miller, Eric Dumazet,
	Paolo Abeni
  Cc: netdev, linux-kernel, stable, Simon Horman, Bin Yu, Cheng Wen

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

With panic_on_warn enabled this warning becomes a denial of service.

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.

Zero-length register dumps used to be issued so that drivers which only
report a revision ID could fill regs->version.  Those drivers return
zero from get_regs_len(), and the core has returned early for them
since commit f9fc54d313fa ("ethtool: check the return value of
get_regs_len").

The problem was found while testing the ethtool register dump path of
an MCS7830 adapter.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
v2: handle this in the ethtool core instead of the mcs7830 driver: a
    zero-length dump is a no-op, so do not call into the driver at all
    (Andrew Lunn).
v1: https://lore.kernel.org/r/20261125071649.7052-1-25031212351@stu.xidian.edu.cn/

 net/ethtool/ioctl.c | 4 ++++
 1 file changed, 4 insertions(+)

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;
+
 	reglen = ops->get_regs_len(dev);
 	if (reglen <= 0)
 		return reglen;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-26 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  1:52 [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps YuanZhe Liu
2026-11-26  2:58 ` Andrew Lunn
2026-11-26  8:21   ` YuanZhe Liu
2026-11-26 14:11     ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox