Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by YuanZhe Liu
Fri, 27 Nov 2026 07:23
[PATCH v4] net: ethtool: do not call get_regs() for zero-length dumps
Author: YuanZhe Liu
Date: Fri, 27 Nov 2026 07:23
Date: Fri, 27 Nov 2026 07:23
61 lines
11373 bytes
11373 bytes
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. The check comes after get_regs_len() so that drivers
which cannot provide a dump still return their error to userspace:
ethtool(8) sends a zero-length request when ETHTOOL_GDRVINFO reported
no regdump_len, which is what happens when get_regs_len() fails.
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(). Since a zero-length dump
returns no data, the driver also cannot fill in regs.version; callers
that need the version have to request the dump.
The problem was found while testing the ethtool register dump path of
an MCS7830 adapter.
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>
---
v4: drop Fixes: and the stable Cc; there is no report behind this
(Andrew Lunn). Move the zero-length check after the get_regs_len()
result check so drivers which fail get_regs_len() keep reporting the
error to ethtool -d, and document that a zero-length dump returns
neither data nor the version.
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) (Andrew Lunn).
v2: handle this in the ethtool core instead of the mcs7830 driver.
https://lore.kernel.org/r/20261126015239.6038-1-25031212351@stu.xidian.edu.cn/
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..4839ef141b21 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1783,6 +1783,10 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
if (reglen <= 0)
return reglen;
+ /* A zero-length dump has nothing to fill in. */
+ if (!regs.len)
+ return 0;
+
if (regs.len > reglen)
regs.len = reglen;
--
2.34.1
Re: [PATCH v4] net: ethtool: do not call get_regs() for zero-length dumps
Author: Andrew Lunn
Date: Sat, 28 Nov 2026 16:05
Date: Sat, 28 Nov 2026 16:05
33 lines
9811 bytes
9811 bytes
On Fri, Nov 27, 2026 at 03:23:48PM +0800, YuanZhe Liu wrote:
> 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. The check comes after get_regs_len() so that drivers
> which cannot provide a dump still return their error to userspace:
> ethtool(8) sends a zero-length request when ETHTOOL_GDRVINFO reported
> no regdump_len, which is what happens when get_regs_len() fails.
>
> 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(). Since a zero-length dump
> returns no data, the driver also cannot fill in regs.version; callers
> that need the version have to request the dump.
>
> The problem was found while testing the ethtool register dump path of
> an MCS7830 adapter.
>
> 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>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
Re: [PATCH v4] net: ethtool: do not call get_regs() for zero-length dumps
Author: patchwork-bot+netdevbpf
Date: Wed, 02 Dec 2026 04:20
Date: Wed, 02 Dec 2026 04:20
24 lines
8714 bytes
8714 bytes
Hello:
This patch was applied to netdev/net.git (main)
by Willem de Bruijn <willemb@google.com>:
On Fri, 27 Nov 2026 15:23:48 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [v4] net: ethtool: do not call get_regs() for zero-length dumps
https://git.kernel.org/netdev/net/c/0d39bf812678
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads