* [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
2026-11-27 2:41 ` netdev-bot+sashiko
0 siblings, 2 replies; 6+ 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(®s, 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] 6+ messages in thread
* Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
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-27 2:41 ` netdev-bot+sashiko
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2026-11-26 2:58 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, stable, Simon Horman, Bin Yu, Cheng Wen
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(®s, 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
2026-11-26 2:58 ` Andrew Lunn
@ 2026-11-26 8:21 ` YuanZhe Liu
2026-11-26 14:11 ` Andrew Lunn
0 siblings, 1 reply; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-26 8:21 UTC (permalink / raw)
To: Andrew Lunn
Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, stable, Simon Horman, Bin Yu, Cheng Wen
On Thu, Nov 26, 2026 at 03:58:03AM +0100, Andrew Lunn wrote:
> 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.
Agreed, v3 describes the ethtool side instead of the USB stack.
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> Who does this bother?
The zero-length request itself is harmless, but it now trips the
direction check in the USB core and, in setups with panic_on_warn, turns
a privileged ETHTOOL_GREGS call into a kernel panic. That is the same
class of issue as the plusb fix (CVE-2023-52742), which also carried a
Fixes tag and a stable Cc, so I kept both.
> 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.
I checked. ETHTOOL_GREGS has no zero-length size query: the uAPI tells
users to get the dump size from ETHTOOL_GDRVINFO.regdump_len, ethtool(8)
does exactly that, and ethtool_get_regs() only clamps a too-large
regs.len down to get_regs_len(); with regs.len == 0 it does not fill in
a size. So the early return does not remove a size query; it only stops
asking the driver for a dump that cannot return any data.
v3 to follow separately.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
2026-11-26 8:21 ` YuanZhe Liu
@ 2026-11-26 14:11 ` Andrew Lunn
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2026-11-26 14:11 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
netdev, linux-kernel, stable, Simon Horman, Bin Yu, Cheng Wen
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> >
> > Who does this bother?
>
> The zero-length request itself is harmless, but it now trips the
> direction check in the USB core and, in setups with panic_on_warn, turns
> a privileged ETHTOOL_GREGS call into a kernel panic. That is the same
> class of issue as the plusb fix (CVE-2023-52742), which also carried a
> Fixes tag and a stable Cc, so I kept both.
Maybe. But how long has it been like this? Nobody has reported it, so
nobody is bothered by it.
Linus has been pushing back on the number of Fixes: which get
submitted. So we have to push back.
> > 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.
>
> I checked. ETHTOOL_GREGS has no zero-length size query: the uAPI tells
> users to get the dump size from ETHTOOL_GDRVINFO.regdump_len, ethtool(8)
> does exactly that, and ethtool_get_regs() only clamps a too-large
> regs.len down to get_regs_len(); with regs.len == 0 it does not fill in
> a size. So the early return does not remove a size query; it only stops
> asking the driver for a dump that cannot return any data.
Thanks for checking.
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
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-27 2:41 ` netdev-bot+sashiko
2026-11-27 7:24 ` YuanZhe Liu
1 sibling, 1 reply; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 2:41 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 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] In ethtool_get_regs() (net/ethtool/ioctl.c), the new `if
(!regs.len) return 0;` check runs before `ops->get_regs_len()` and its…
- [Low] In ethtool_get_regs() (net/ethtool/ioctl.c), ETHTOOL_GREGS with
regs.len == 0 now returns success without calling ops->get_regs() and…
--
net: ethtool: do not call get_regs() for zero-length dumps
This patch adds an early return to ethtool_get_regs() when the
user-supplied regs.len is zero, so the driver's get_regs() is no longer
called for a zero-length dump. The goal is to stop drivers such as mcs7830
from issuing zero-length USB control transfers on the receive pipe. Those
transfers trip a WARN in usb_submit_urb().
> 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(®s, 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]
Can this early return hide errors from get_regs_len()?
The new check runs before ops->get_regs_len(). So when regs.len is 0, a
negative return such as -EOPNOTSUPP is never passed back. The ioctl
reports success and copies nothing back.
A GREGS request with len == 0 is what a normal ethtool -d sends when
get_regs_len() fails. That happens because ethtool_get_drvinfo() only sets
regdump_len for positive values:
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;
}
...
}
Userspace then sees regdump_len == 0 and sends ETHTOOL_GREGS with
regs.len == 0.
There are two in-tree examples. DSA user ports always install
dsa_user_get_regs(), so the !ops->get_regs check does not catch them, but:
net/dsa/user.c:dsa_user_get_regs_len() {
...
if (ds->ops->get_regs_len)
return ds->ops->get_regs_len(ds, dp->index);
return -EOPNOTSUPP;
}
And hns3:
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c:hns3_get_regs_len() {
...
if (!h->ae_algo->ops->get_regs_len)
return -EOPNOTSUPP;
return h->ae_algo->ops->get_regs_len(h);
}
Before this patch, ethtool -d on these devices printed an error such as
"Cannot get register dump: Operation not supported". With this patch,
ethtool -d appears to succeed with an empty dump.
In the standard ethtool flow, this seems to undo the error reporting that
commit f9fc54d313fa ("ethtool: check the return value of get_regs_len")
added for hns3. The commit message does not mention this.
Would moving the zero-length check after the "if (reglen <= 0) return
reglen;" check keep the error codes? It would still avoid calling
get_regs() with len == 0.
[Severity: Low]
For drivers whose get_regs_len() returns a positive value, does this
change what a len == 0 query returns in regs.version?
Before this patch, such a request skipped the clamp and set reglen to 0.
It then called ops->get_regs() and copied the ethtool_regs header back.
For example, mcs7830 fills in the version:
drivers/net/usb/mcs7830.c:mcs7830_get_regs() {
...
regs->version = mcs7830_get_rev(dev);
mcs7830_get_reg(dev, 0, regs->len, data);
}
Now the ioctl returns success without calling get_regs() and without
copying the header back. regs.version keeps whatever userspace passed in.
The uAPI kernel-doc for struct ethtool_regs in
include/uapi/linux/ethtool.h still describes @version as driver-specific
output.
Stock ethtool sends len = regdump_len, so it is not affected. This only
affects callers that send len == 0 to read the version alone.
The commit message says:
A zero-length dump cannot return any data, so there is nothing for the
driver to do.
and:
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").
That covers the case where get_regs_len() returns 0. It does not cover
the reglen > 0 case that this patch changes.
Should the commit message or the uAPI documentation describe this change?
Alternatively, should a len == 0 request fail instead of reporting success
with the header left unfilled?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126015239.6038-1-25031212351%40stu.xidian.edu.cn
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
2026-11-27 2:41 ` netdev-bot+sashiko
@ 2026-11-27 7:24 ` YuanZhe Liu
0 siblings, 0 replies; 6+ messages in thread
From: YuanZhe Liu @ 2026-11-27 7:24 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: Andrew Lunn, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, netdev, linux-kernel, Simon Horman, Bin Yu,
Cheng Wen
On Fri, Nov 27, 2026 at 02:41:47AM +0000, netdev-bot+sashiko@kernel.org wrote:
> [Medium] Can this early return hide errors from get_regs_len()?
>
> [Low] For drivers whose get_regs_len() returns a positive value, does
> this change what a len == 0 query returns in regs.version?
Both points are valid.
The Medium one is a real regression. ethtool -d sends a zero-length
request exactly when ETHTOOL_GDRVINFO reported no regdump_len, which is
what happens when get_regs_len() fails, so the early return would hide
-EOPNOTSUPP from DSA user ports and hns3. I moved the zero-length check
after the get_regs_len() result check; only drivers which report a
positive length skip the callback now.
For the Low one, a zero-length dump returns no data and, with the
callback skipped, it no longer fills in regs.version. I documented that
in the commit message: the uAPI points users at ETHTOOL_GDRVINFO for the
size, and ethtool(8) always sends regdump_len for drivers that report
one, so there is no version-only query to preserve.
v4 posted separately:
https://lore.kernel.org/r/20261127072348.5277-1-25031212351@stu.xidian.edu.cn/
pw-bot: cr
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-27 7:24 UTC | newest]
Thread overview: 6+ 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
2026-11-27 2:41 ` netdev-bot+sashiko
2026-11-27 7:24 ` YuanZhe Liu
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®