mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] net: ethtool: do not call get_regs() for zero-length dumps
@ 2026-11-26  8:27 YuanZhe Liu
  2026-11-27  8:30 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-11-26  8:27 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 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@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>
---
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@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..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	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] net: ethtool: do not call get_regs() for zero-length dumps
  2026-11-26  8:27 [PATCH v3] net: ethtool: do not call get_regs() for zero-length dumps YuanZhe Liu
@ 2026-11-27  8:30 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27  8:30 UTC (permalink / raw)
  To: 25031212351
  Cc: andrew, kuba, davem, edumazet, pabeni, netdev, linux-kernel,
	stable, horms, byu, wencheng

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch adds an early `if (!regs.len) return 0;` in
  ethtool_get_regs() (net/ethtool/ioctl.c:1782-1784).

--

net: ethtool: do not call get_regs() for zero-length dumps

This patch adds an early return in ethtool_get_regs() when the
user-supplied regs.len is zero, so the driver's get_regs() callback is
never called for zero-length dumps. The commit message says this does
not remove a way to query the dump size, because the size comes from
ETHTOOL_GDRVINFO.regdump_len.

> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index 80b7930b3fe0d..e8af861ee5de3 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;

[Severity: Medium]
The early return sits before ops->get_regs_len() and its error check.
It also comes before the copy_to_user() of the struct ethtool_regs
header. For a request with len == 0, this seems to change
ETHTOOL_GREGS in a few ways userspace can see.

First, is a negative errno from get_regs_len() now reported as success?
ethtool_get_drvinfo() only fills in regdump_len when the driver
returns a positive length:

net/ethtool/ioctl.c:ethtool_get_drvinfo() {
    ...
	if (ops->get_regs_len) {
		int ret = ops->get_regs_len(dev);

		if (ret > 0)
			rsp->info.regdump_len = ret;
	}
    ...
}

So when get_regs_len() fails, ethtool(8) sends GREGS with
len = regdump_len = 0. One example is bnxt_get_regs_len(), which does
this on a VF:

	if (!BNXT_PF(bp))
		return -EOPNOTSUPP;

Before this patch, "ethtool -d" on a bnxt VF failed with "Operation not
supported". With the early return, the ioctl succeeds and ethtool(8)
prints an empty dump. dsa_conduit_get_regs_len() passes on negative
errors from the conduit in the same way.

Second, the header is no longer written back for len == 0. Several
get_regs() implementations set regs->version, and some also overwrite
regs->len with the full dump size. lan743x_get_regs() is one:

	regs->version = LAN743X_ETH_REG_VERSION;
	regs->len = regs_len;

emac_get_regs(), axienet_ethtools_get_regs() and
dsa_conduit_get_regs() do something similar. mcs7830_get_regs(), the
driver named in the changelog, sets regs->version.

On those devices, a GREGS call with len == 0 used to return the
version and the full length in the header, because the data
copy_to_user() moved 0 bytes. Does that conflict with this part of
the commit message?

    This does not remove a way to query the dump size: the
    uAPI tells users to obtain it from ETHTOOL_GDRVINFO.regdump_len,

The struct ethtool_regs kernel-doc in include/uapi/linux/ethtool.h
also describes @version as a driver-supplied output, with no
exception for len == 0. The new comment says there is "nothing to fill
in", but the header still has fields to fill.

Could the zero-length check go after the get_regs_len() call and its
"reglen <= 0" check, so errors still reach userspace? Copying the
header back to userspace, or documenting the new behaviour in the uAPI
header, would cover the version and len cases. Since this is tagged for
stable, the commit message could also mention the change in behaviour.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126082748.2798-1-25031212351%40stu.xidian.edu.cn

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

end of thread, other threads:[~2026-11-27  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  8:27 [PATCH v3] net: ethtool: do not call get_regs() for zero-length dumps YuanZhe Liu
2026-11-27  8:30 ` netdev-bot+sashiko

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

all inboxes | Powered by JetHome®