From: netdev-bot+sashiko@kernel.org
To: 25031212351@stu.xidian.edu.cn
Cc: andrew@lunn.ch, kuba@kernel.org, davem@davemloft.net,
edumazet@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
horms@kernel.org, byu@xidian.edu.cn, wencheng@xidian.edu.cn
Subject: Re: [PATCH v3] net: ethtool: do not call get_regs() for zero-length dumps
Date: Fri, 27 Nov 2026 08:30:48 +0000 [thread overview]
Message-ID: <179576824874.3135.15886004303093318921@kernel.org> (raw)
In-Reply-To: <20261126082748.2798-1-25031212351@stu.xidian.edu.cn>
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(®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]
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
prev parent reply other threads:[~2026-11-27 8:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179576824874.3135.15886004303093318921@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=25031212351@stu.xidian.edu.cn \
--cc=andrew@lunn.ch \
--cc=byu@xidian.edu.cn \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=wencheng@xidian.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox