🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22874

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

#22874
From: Andrew Lunn
Date: Thu, 26 Nov 2026 02:58
48 lines
10168 bytes
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(&regs, 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
Technical Details
Message-ID: <366216bc-ccc3-4547-8587-87cdf35f552f@lunn.ch>
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-371840-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-371840-linux-kernel-netdev=dewy.ru
From: andrew@lunn.ch (Andrew Lunn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2] net: ethtool: do not call get_regs() for zero-length
 dumps
Date: Thu, 26 Nov 2026 03:58:03 +0100
Organization: Usenet Network
Message-ID: <366216bc-ccc3-4547-8587-87cdf35f552f@lunn.ch>
References: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="366201"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:hZsEXSSPyNkDNDoUO71YGI2HemA= sha256:/LBuW+jOfGQ081ae9Xn8VQ/lpQM+pdNBXqMCSWqTFt0=
	sha1:LL4rOFrRIODuxun8TGHYW35VCHM= sha256:KgGGT3/EJ3Z+9bcwcD1+DPZAGcKY/1Qx27YZa7myfWk=
Content-Disposition: inline
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 6AFBD125EAC; Thu, 26 Nov 2026 05:58:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=lunn.ch
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 S3BhDnUjdnnk;
	Thu, 26 Nov 2026 05:58:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-371840-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=lunn.ch
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id A83B6125EA3; Thu, 26 Nov 2026 05:58:24 +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 54DAE2EC21; Thu, 26 Nov 2026 02:58:20 +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=1795661900;
	b=tkGdp0eHKWmAFtiiu4CBwIMTc6f6pxpeMjpLGBG2smppk/PlQmO4gSrRSC2bddKAyE3h
	 fEowaLYiGXuQoE6GbV9TxgN0o6f6HrgS0s9CWB+hfJN16AkkxtIDQtGvd7GUFioU7myPN
	 T4kWfWZwiwFmu5ByMe95dQC7mDY6pGH9FLJsSrISgiv+VsUloTs7ba5HwcQSPkxU/55Wq
	 O5FP6G05cJBw0XMwauxMD6TBxpGirMJ3MCUynJFD/v4J+Arft+BnCKqN2TlCMfj/NzFez
	 gZlE1QS6G1UpnSqsTYy8N/gD8WRvPwmq/JUIbgZQl13odzE5cWkBftBmGMV5cKkzcEA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795661900;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:Date:
	 From:To:Cc:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=QOEcDp+7IJMgNzkrkV18FLHjUkTLg5/xxzENnntmIO4=;
	b=LfDy6mh1r+qwaJAkFwAQBYFh8x4ySoh7tT1ZXnNkzjvNZyCFMJ1nchulsisp7iZkTyU6
	 kOsH6MrW4h95ivP9HEFE7TfpZW/Ga2BDfr51CNMAxo8xsrnyNtc9TXyAx+hjzX79PezdU
	 vGLm1PAC7kOOroj8b6H8abM07VlDb3R8JmyCmtP86Y7+NidkP0zB+qN7JWHvoFj0D9XBM
	 vUTh+3HfjaoQan4aNScCmQkyuJ+pD8ey96Y5dDNnGHBcm+AnSgTz1Dz9RVkkIbhgkLLqe
	 5aMZnr52/6o6VlfL9dwKil/bXbNmOiPYeKPHpDSs0LAXM9TRV4LdlTP+hr+3SsTt03w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=ODM4lkrQ;
	dmarc=pass header.from=lunn.ch;
	spf=pass smtp.mailfrom=lunn.ch;
	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 E2C89606A32E;
	Thu, 26 Nov 2026 02:58:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=ODM4lkrQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=156.67.10.101
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795661894;
	b=WS5tCvjHx/3tnAtvwOah4B8MKpuvXd7uQMGxnAiXBMmPF/jksOqKcpfrIVGATtQ8B/Wx
	 3SaaZ5Hr7ucBsJrOy0gmb/mk/pZucBOqatwDB0qWG8vyh0KTXvscZaj6086nFkeW6t1NX
	 7uDDkQgbIarorPrFBlXeKt37rkAUvTlvt3bezU4A2PGbdBrrhAE22hsRPWgYJYejMcRc2
	 jfQ9MtAsB0GeLAwO/F5EaLQ/nC2/ONMKk3UZBpeJyzc8K9JclLdpKF0pQLXTWPmQkoaR7
	 MWSrbHUJY73cGJPaUIEadUqUeBOvFJVWQCclRxUxkflXPSKClbNoWi9zIcCcgzCZwOQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795661894;
	h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject:
	 Message-ID:References:MIME-Version:Content-Type:Content-Disposition:
	 In-Reply-To;
	bh=QOEcDp+7IJMgNzkrkV18FLHjUkTLg5/xxzENnntmIO4=;
	b=csEwBGYOrdGvdgs0GCeIf+/Dxt/wADdPbs/yGPgUZ3iz2CbVWsQCB5wrPSyk+C+BmOPp
	 kdXX9KJsBiCqdcjMOOy4HDXNlD5AnRSxow0XgKsBf0c7XpSip0L7DKnLrzD64Yiglimja
	 BdXkhMp/fup31kn4WMnskFCHgfsZTY6rXjXp5AhOvm+W2fMeEy6NFwhTmUBpTiNj0Yn8a
	 kVbAjmX62WocZijjHhZYFmz1xu2bHNUTw7wufTEqEiBEJ6d+oKZHdrUQ6rBSGxUdkIhlL
	 QFgCwicdqYJWaHzs5MuRFa6hA20ZvI6OQkAUVCdVWsqZFQbF2ULfPpVwDdalZS092eQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=lunn.ch;
	spf=pass smtp.mailfrom=lunn.ch;
	dkim=pass header.d=lunn.ch header.i=@lunn.ch header.a=rsa-sha256 header.s=20171124 header.b=ODM4lkrQ;
	arc=none smtp.remote-ip=156.67.10.101
X-Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93992606A31E;
	Thu, 26 Nov 2026 02:58:13 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93992606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch;
	s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version:
	References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject:
	Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:
	Content-ID:Content-Description:Content-Disposition:In-Reply-To:References;
	bh=QOEcDp+7IJMgNzkrkV18FLHjUkTLg5/xxzENnntmIO4=; b=ODM4lkrQQTpzXvAYlWv/BdS8w6
	tndkhnfEVh4+YNxGBfECQczmlIJC4xUe0jnM06N8XOTTRw7ghYE9tj/DYsMEdxkbW4l06rCNWHrv3
	m/cFV0/FXtz6cW3WpcHaY3YOLIMyQ9JTbGHAeGhldUSMEFAccOttJmE3wh5W3XxeO65M=;
X-Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2)
	(envelope-from <andrew@lunn.ch>)
	id 1xWPgR-001ULd-68; Thu, 26 Nov 2026 03:58:03 +0100
X-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>
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
X-In-Reply-To: <20261126015239.6038-1-25031212351@stu.xidian.edu.cn>