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

From: YuanZhe Liu

Date: Thu Nov 26 2026 - 03:28:16 EST


ethtool_get_regs() passes the user-supplied regs.len to the driver
unchanged, including zero. A zero-length dump has nothing to fill in,
but the driver callback still runs and may use that length for its own
I/O. A zero-length transfer cannot move any data, and some transports
report a warning for it, which becomes a denial of service when
panic_on_warn is set.

Return success without calling into the driver when the requested dump
length is zero. This does not remove a way to query the dump size: the
uAPI tells users to obtain it from ETHTOOL_GDRVINFO.regdump_len, and
the core only clamps an oversized regs.len down to get_regs_len();
ethtool(8) uses regdump_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@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
v3: describe the ethtool behaviour instead of the USB stack, and document
that ETHTOOL_GREGS has no zero-length size query (the size comes from
ETHTOOL_GDRVINFO.regdump_len), so the early return does not remove one
(Andrew Lunn).
v2: handle this in the ethtool core instead of the mcs7830 driver.
https://lore.kernel.org/r/20261126015239.6038-1-25031212351@xxxxxxxxxxxxxxxxx/
v1: https://lore.kernel.org/r/20261125071649.7052-1-25031212351@xxxxxxxxxxxxxxxxx/

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