🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19706

Re: [PATCH v5 2/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr

#19706
From: Andy Shevchenko
Date: Fri, 20 Nov 2026 08:59
142 lines
15335 bytes
On Fri, Nov 20, 2026 at 12:02:43AM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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] The commit message is wrong about how the legacy module
>   parameters report a rejected address.
> - [Low] The ABI text this patch adds to configfs-usb-
>   gadget-{ecm,eem,ncm,rndis,subset} says host_addr/dev_addr accept only…
> 
> --
> 
> usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
> 
> This replaces the open coded MAC address loop in get_ether_addr() with
> parse_mac_pton() for the delimited notations and hex2bin() for the raw
> twelve digit notation. This fixes an out-of-bounds read on short strings
> and stops non-hex characters from being silently accepted. It also selects
> GENERIC_NET_UTILS and documents the accepted formats in the configfs ABI
> files for the ECM, EEM, NCM, RNDIS and subset functions.
> 
> Link: https://lore.kernel.org/all/20261106030605.576584-3-liuc63@xiaopeng.com/
> 
> > How a rejected address is reported depends on the caller.  The legacy
> > module parameters go through gether_setup_name(), which keeps the random
> > address that get_ether_addr() falls back to and only logs a warning.
> 
> [Severity: Medium]
> Is this description of the legacy path accurate?
> 
> Nothing in the tree seems to call gether_setup_name(). Its only wrapper,
> the inline gether_setup() in u_ether.h, has no callers either.
> 
> The legacy gadgets (legacy/ether.c, cdc2.c, ncm.c, multi.c and g_ffs.c)
> pass the dev_addr= and host_addr= parameters through
> gether_set_dev_addr() and gether_set_host_addr(). The KASAN trace earlier
> in this commit message shows the same path
> (eth_bind()->gether_set_dev_addr()->get_ether_addr()):
> 
> drivers/usb/gadget/legacy/ether.c:eth_bind() {
>     ...
> 	if (!gether_set_host_addr(net, host_addr))
> 		pr_info("using host ethernet address: %s", host_addr);
> 	if (!gether_set_dev_addr(net, dev_addr))
> 		pr_info("using self ethernet address: %s", dev_addr);
>     ...
> }
> 
> gether_set_dev_addr() parses into a local new_addr[] and returns -EINVAL
> when get_ether_addr() fails. The random fallback is thrown away:
> 
> drivers/usb/gadget/function/u_ether.c:gether_set_dev_addr() {
>     ...
> 	if (get_ether_addr(dev_addr, new_addr))
> 		return -EINVAL;
>     ...
> }
> 
> The netdev then keeps the dev_mac/host_mac that
> gether_setup_name_default() picked earlier with eth_random_addr(). Since
> eth_bind() has no else branch, nothing is logged.
> 
> With this patch, "insmod g_ether.ko dev_addr=aabb.ccdd.eeff" no longer
> gives a stable aa:bb:cc:dd:ee:ff. parse_mac_pton() fails the length check
> and hex2bin() fails at the first '.'. Would such a user now get a
> different random MAC on every load, with no message explaining why?

It sounds like a good idea to add a warning on rejected addresses and say that
random is in use.

> Could the commit message be corrected to describe the
> gether_set_dev_addr() path that the legacy parameters actually take?

I think this needs to be followed and commit message needs a correction.

...

> > --- a/Documentation/ABI/testing/configfs-usb-gadget-ecm
> > +++ b/Documentation/ABI/testing/configfs-usb-gadget-ecm
> > @@ -17,4 +17,9 @@ Description:
> >  			      - MAC address of device's end of this
> >  				Ethernet over USB link
> >  
> > -
> > +		host_addr and dev_addr accept a MAC address as six byte
> > +		pairs separated by ':' or '.', in any mixture
> > +		(aa:bb:cc:dd:ee:ff, aa.bb.cc.dd.ee.ff), or as twelve
> > +		hexadecimal digits with no separator (aabbccddeeff).  Any
> > +		other format is rejected: the write fails with EINVAL and
> > +		the attribute keeps its previous value.
> 
> [Severity: Low]
> Does this text match what the new get_ether_addr() accepts?
> 
> parse_mac_pton() only checks a minimum length and the first
> MAC_ADDR_STR_LEN characters:
> 
> lib/net_utils.c:parse_mac_pton() {
>     ...
> 	if (strnlen(s, MAC_ADDR_STR_LEN) < MAC_ADDR_STR_LEN)
> 		return false;
>     ...
> }
> 
> Its own kernel-doc says "anything after them is ignored". So writing
> "aa:bb:cc:dd:ee:ff:00" or "aa:bb:cc:dd:ee:ffXYZ" to dev_addr succeeds and
> sets aa:bb:cc:dd:ee:ff.

Yeah, the text needs an amendment. Something like
"...with no separator (aabbccddeeff) at the beginning of the input."
(see the part "at the beginning of the input" that's added).

> The hex2bin(dev_addr, str, ETH_ALEN) fallback reads exactly 12 characters
> and never looks at str[12]. "aabbccddeeff.zz" and "aabbccddeeff0011" are
> accepted as well.
> 
> The reverse case is also missing from the text. Both paths in
> get_ether_addr() also require is_valid_ether_addr(). A correctly
> formatted multicast or all-zero address such as 01:00:5e:00:00:01 or
> 00:00:00:00:00:00 fails with EINVAL, and the new text doesn't mention
> this.
> 
> Trailing characters do have to be tolerated, because a configfs write
> from echo ends in a newline. Could the text say that anything after the
> address is ignored, and that the address must be unicast and non-zero,
> instead of saying that every other format is rejected?
> 
> The eem, ncm, rndis and subset ABI files get the same text.

All of them need to follow the same pattern, yes.

-- 
With Best Regards,
Andy Shevchenko
Technical Details
Message-ID: <awAL-CjBSGfOfYUS@ashevche-desk.local>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367801-linux-kernel-netdev=dewy.ru
References: <20261117090110.3263592-3-liuc63@xiaopeng.com> <179513296378.3136.18205287276015126683@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367801-linux-kernel-netdev=dewy.ru
From: andriy.shevchenko@intel.com (Andy Shevchenko)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v5 2/2] usb: gadget: u_ether: fix out-of-bounds read in
 get_ether_addr
Date: Fri, 20 Nov 2026 10:59:36 +0200
Organization: Usenet Network
Message-ID: <awAL-CjBSGfOfYUS@ashevche-desk.local>
References: <20261117090110.3263592-3-liuc63@xiaopeng.com>
 <179513296378.3136.18205287276015126683@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3113451"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZJikg8M94f2dn+6ORQq+7VVhyH8= sha256:EQlkXgb/OJ21OryEdTWKrP8angpd7bJFGC0JxraKjmg=
	sha1:yB6An17hE/xsWtg9ChulUSzKRGI= sha256:/cfOSOvc/N60Y0YiZQpreDatr7Ze02KjGK4Xcf6jqU0=
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 BCD5111591A; Fri, 20 Nov 2026 12:00:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.951
X-Spam-Status: No, score=-1.951 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001,
	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 (2048-bit key)
	header.d=intel.com
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 oIfHHvMqSKxI;
	Fri, 20 Nov 2026 12:00:38 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367801-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=intel.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 993A8115918; Fri, 20 Nov 2026 12:00:27 +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 DF7101A51A6; Fri, 20 Nov 2026 09:00:18 +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=1795165189;
	b=R+1ExOcF372/E+LCUEHPfSqVKYpcKNGjT79bfqC7T4kzYLKx8FwUrdGQMVhGHemBrsWU
	 G7MSdiwFU46k+Y9xBOJWyxBaDRaYrkUyxavDB+7sla2mYcwhm4v/xFHlJaaIX+2graPE8
	 O8licjuUcVVTF5aYb5D9xl2VKpckJs1/LK0UPCiIFK2cj4L2fzY7Pk2fSgYv6n3LeWDT0
	 4e4kWwubd/l2IG1jR3M5DK9R1PCDF2r6dIcgRcFeV6lwB6GBixnXSHpGCip1gQSVwO/VV
	 FTPVgwNRdBNFOaKcfkwNwspIKByjPZePp4dhhRDkrUSWTwSAy9ECO7yaiA40pdMADxQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795165189;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV:
	 Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:
	 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:
	 Content-Transfer-Encoding:In-Reply-To:Organization;
	bh=VedXmvSI7G6Xtxoxd3IW0KA5vnVG/Qoj5iEhteVh2F4=;
	b=DgcdAW0snRi6DtR+AD/XOc3Wc5texoV0deobklk8JPX+bLdJvNfpBPlCh2mqG7+r5s/R
	 fJJtoMULVWb84GJZ3Hghx7naTG3ofkBMFsW7/yNM2Ga7lPNMTqX7dNZdbbskp1TS/n8jd
	 rfZomMxCj0cJbd7CsmEsqxBSHfD1qHxdr+TtDxFEnZk46Lf8rmYH7zf8PGCnnK7l9BNJV
	 r+pwxYTKbvDm50etdMfACyFhmSk+iNamlQNURSpRRiUfWPmMbcJZY6wFXFHhFdmTEkSZb
	 BERx8F4nL9rJpHCcM2caTDdLX1yZ1QJiwmDEIDdl2RrUXRCeoc0i7+Yqrfw8O98qGgA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GsWwQTjI;
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	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 2E32260A2624;
	Fri, 20 Nov 2026 08:59:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GsWwQTjI
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795165183;
	b=ywJh2kOpTaIGK4anxxARKzRkpvt7PbHsa99EMAn2Ux1+CmMbH0W/KNZE7Rhs2rF5e+0v
	 NtDbTe402sG4yAaJGCgTRTTu4XpTueuhhChxTH7OX/ml0R7PmgzQlmp7qFGVtMpmhBmY7
	 j7ZPBSSuvsu1s4oBId1EL/rH1Pgo0q3jQdevN5AY/ww2Ql5aZuS7hrJGDQ2a7XHyY2hi8
	 rvhn9SuRlFFgdAcOVsfSrj49UwHR/E5TxybH+WwhZyAck2NhoEs1W0oRu+jG1evEvbWoF
	 SdijK9KnPJ64cvjN3ryQRJ7tySkoJ5WpXNU2jAoeC82LIUweVG+b36IDw36H0kypihg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795165183;
	h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID:
	 X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID:
	 X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc:
	 Subject:Message-ID:References:MIME-Version:Content-Type:
	 Content-Disposition:Content-Transfer-Encoding:In-Reply-To:
	 Organization;
	bh=VedXmvSI7G6Xtxoxd3IW0KA5vnVG/Qoj5iEhteVh2F4=;
	b=M4oy1a4rXgYicMuekHjf3+rK8qdElr+BL7MwjYvHwyjot+o89dtWpG8sGG7iJ4FCNnPz
	 1snpJT/gmxIDQYE6kMuv3C3ZOkrs7LYshhAwxk4ikspXXAt1XMAfmzXQIX3bzwwX3/iFt
	 FsJsnNlpx9o2tHHSsvDo1M9Xd6WGgpD/L1xfQpKAvQ9c9BNIcmNz2Dd1MFG+u0+iYzOOz
	 STNQurKJsRypHwSZvmoLOFHUp+XlMfLkzfL3S03Lct6irRzGJ25MeK39RPJWL3b8tscKg
	 SEcnqVmutC/fwz8ygZlCIf+6OBQJoPdtgAY8NBXyCK1VWb5QnhlSYbCbQSJmYlrIuvg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GsWwQTjI;
	arc=none smtp.remote-ip=198.175.65.20
X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4C00606A32C;
	Fri, 20 Nov 2026 08:59:42 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4C00606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1795165184; x=1826701184;
  h=date:from:to:cc:subject:message-id:references:
   mime-version:content-transfer-encoding:in-reply-to;
  bh=nk+t4fI7zmLmWT/kxiuqyqIDMYUCl9U7mqKAwRYAXEU=;
  b=GsWwQTjINcWyOfGYRC/W778QqQYSKIPtAP7s64ZUXJGMAQPBwhJkLB/q
   ltKvmDG4KDCbMVFp22SbdCqPI5YT+ktG7NlgMqsxIiDA099As1e2f4D+D
   CJFioI1E0MmR4yHdiIkJlov7z3bn4L9aiopjOkQkN263M3ZLKSM1RsRdU
   roLx0ZtlvTMuJv+4TZoSFNECvOtOMhQcE6tG2ZQ23p/NkExcD9Elyk9E9
   pSzJm6EPPeBfiCpe5EAdc6a19xpTJxHjhsxiO3Ae50e0bcUED/nVsODQB
   Y+Q1bgJIicOglhll5V5ZS9WTVDBBGW4sgynt+YCxDNloG3VthIK60OFaG
   g==;
X-CSE-ConnectionGUID: 3dlW4yPfRz+FVa2Ykd8g0Q==
X-CSE-MsgGUID: hTpyKbj5RsalkxRQP5hSow==
X-IronPort-AV: E=McAfee;i="6800,10657,11971"; a="4081601"
X-IronPort-AV: E=Sophos;i="6.27,222,1787036400"; 
   d="scan'208";a="4081601"
X-Received: from fmviesa012.fm.intel.com ([10.60.135.152])
  by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2026 00:59:43 -0800
X-CSE-ConnectionGUID: 8YRu/vs0QIeBu8Whxdd/Iw==
X-CSE-MsgGUID: eYIQxeXtQJuw0HqduVkqRA==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.27,222,1787036400"; 
   d="scan'208";a="12363983"
X-Received: from conormcd-mobl2.ger.corp.intel.com (HELO localhost) ([10.245.245.218])
  by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2026 00:59:39 -0800
X-Cc: liuc63@xiaopeng.com, gregkh@linuxfoundation.org,
	akpm@linux-foundation.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	khtsai@google.com, fangxy@xiaopeng.com, rdunlap@infradead.org,
	dbrownell@users.sourceforge.net, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
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: <179513296378.3136.18205287276015126683@kernel.org>
X-Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6
 krs, Bertel Jungin Aukio 5, 02600 Espoo