From: Andrew Lunn <andrew@lunn.ch>
To: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Cc: Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Simon Horman <horms@kernel.org>,
Bin Yu <byu@xidian.edu.cn>, Cheng Wen <wencheng@xidian.edu.cn>
Subject: Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
Date: Thu, 26 Nov 2026 03:58:03 +0100 [thread overview]
Message-ID: <366216bc-ccc3-4547-8587-87cdf35f552f@lunn.ch> (raw)
In-Reply-To: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>
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
next prev parent reply other threads:[~2026-11-26 2:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 1:52 YuanZhe Liu
2026-11-26 2:58 ` Andrew Lunn [this message]
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
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=366216bc-ccc3-4547-8587-87cdf35f552f@lunn.ch \
--to=andrew@lunn.ch \
--cc=25031212351@stu.xidian.edu.cn \
--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
all inboxes | Powered by JetHome®