🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23297

Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps

#23297
From: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 02:41
147 lines
13015 bytes
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(&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]
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
Technical Details
Message-ID: <179574730769.3135.6060942775562840087@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372415-linux-kernel-netdev=dewy.ru
References: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372415-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length dumps
Date: Fri, 27 Nov 2026 02:41:47 +0000
Organization: Usenet Network
Message-ID: <179574730769.3135.6060942775562840087@kernel.org>
References: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="620330"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:svK+IwAPM3QcInkyfzEGYzBuae4= sha256:BeDvlIV7U8RPBgnLb6hhqJXVhBem82N+g93yS8NOBU0=
	sha1:EuCBW0gmXo6kKkyO+VfjdamBjGA= sha256:nMmPfrvi6a3zxBVjMEOveUYzdLVAn0G7QZ0cm7jXJjA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 84CB3125F0D; Fri, 27 Nov 2026 05:42:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id HLj3xW7FhRC7;
	Fri, 27 Nov 2026 05:42:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372415-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9896A125F0A; Fri, 27 Nov 2026 05:41:59 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 4D6982E9C6; Fri, 27 Nov 2026 02:41:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795747315;
	b=YzUnk829EEUtbO+BQaGXuqtsIa4pxfi8c7pY3s4GhxTZtuGNPv0x6mRebYFIA4cv9AMq
	 6FnIWsYP/rJLRuNdLTEMFaBs5grX1YPCKi8fNdC68t5TWY/saCvvEB0gauz3e1yxS1sLC
	 GmJ46MVvdBDer3q/CXXhw08tQ2Fq9NX7SlWS89rmhoiq0JQ8FXx+VZRnJxjOfjtdi1t9N
	 j82F43MAX6/cwFy4wivZNAXWvn/Ze+MJk92xZKcfUMN7Mb/6qyfIyHn8kb1fNoDsQDcI+
	 BwFzYso2qYRxE5xvtPIej8h8QhlJbxqt6POsUc5+pBNlYfozi7TJcjcvzVUNUQabzKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795747315;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=VAR2rz8eXDLkPjCKjfmnvh48//s9d1yIgXhNth07Doc=;
	b=2xblbIQSzU31ac0xXGtjl9Uaj0U1dmAaRd2+IXGg7EQLiUkIq4WA7q4qkn/TE0Q7ti5l
	 Zd609kly53PazPBlzfDLVtSgCEbuXdGvk617i7ePGBwO2JJMIfylynxYWXKp1LjjnMD/H
	 aDc4VIBqKc5WJLz141nsQJynZqf1qJIfWZGULKbearKG5iCIxv62yMbb0vEO06P10jlpz
	 L6AiXR2XBHqS/+OzTCOU74cHsD2KgYaTmiVeNPcSSJTwdVpztwoWYHCxLanJhNOaUyKFQ
	 aHMpeuWAl4iSG9TDgP3D5cG+AjcEv8opfhIg3WRmsYTL5TCTIvCJc7R7PbZ8DSVqiRQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c0fyoVmX;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 19518606A321;
	Fri, 27 Nov 2026 02:41:55 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c0fyoVmX
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795747309;
	b=UmOMK7j1OZg4W1Mz4Xlwyenx2JaSyexQCDceiJeZ0YGzS5HbtSnQHA43NfyeXvCTIF+n
	 PLsALQWTVoBBmIFC/epZkfRIxFz+mTW66uDLtKjIoax/H2AsRoeDio8veCli86nRVea48
	 B23mzSCUsVvgqPjw4p/Sf2TS4SRvrF36ZB9DsHG7K1xDrDmVecPIoDIlLN2YoYI6vkKzM
	 jL0QWMhKg0LvoqdUn5WdCwtMsRUFWOIVgmny4l//sJYovbUuNczsZDS3dafGQYY7G3Iar
	 9nkVbD4v9S3WupXVlCn8RPLyz2PSuegTQdK+UVGLL0gWTRlVw+fVkD7ZI+hTa3Ts+bA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795747309;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=VAR2rz8eXDLkPjCKjfmnvh48//s9d1yIgXhNth07Doc=;
	b=vcdtmrobslrD114mM0wB0/o/sAuj9jA7tpAaluqtQrI/yGyz4ixoQTbCuwxjLqfDSGM7
	 7V8YoGRK2eJGnUOAUlCNg7X4qaZYsfigTGVvHOlaBk9KhHvzOqFPAMdWL3fe6z+f6SMuX
	 vIq4Z9E9fBYKA+NGO01ciNUkqXASzfHB5jeclevGBc/IYyweASMRTgEW8l/Kgu+QEXIq4
	 0QpSJ+u8K2GOAKXu6JXP8lQWixwxr8KHu2Z7Jiwd0u1BQ/Lta+TBeQ7lbMVTHC4yLpDM6
	 kSgLFMJzXv/XjdCQo03Fp9AA7+92Y5796g94jVGYvW/7XAH+uBbC5PglAJCZ/w7utZA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=c0fyoVmX;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A6E606A31E;
	Fri, 27 Nov 2026 02:41:48 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AE131F000C1;
	Fri, 27 Nov 2026 02:41:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795747308;
	bh=VAR2rz8eXDLkPjCKjfmnvh48//s9d1yIgXhNth07Doc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=c0fyoVmXK60ROx38e7J/XKeMSPpRHy+ayOjW/uc+Rzp0silZ0W0jW/ycmbFx9DRSu
	 RpCFRNZ0hKJkVSaqnTJJboOnqQRUrCHa1n3pNkYN/HBUJf2RkeOTOcKuyoIzY4fFJn
	 FXKUN33u8uUXeSiGe8Od+RRHCH58DCWtpP7wWmHy8L7zV1zAHfwqNc1oVrXp0RQMxL
	 xSzkSTCsMZZB7QYZs7DbAczm9y5qUc6iKBJCye2u2l/CW564qmPIFs2wjPEIw4v/Nw
	 YC6cvMosL/kOgoP/f8XTIIBq85UvDT+O6/iN03xh0S87ytisuJJtlsj0btHqh//yuR
	 Ob9aktQN50ipg==
X-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
X-In-Reply-To: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list