Netdev List
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: netdev-bot+sashiko@kernel.org
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
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	[thread overview]
Message-ID: <awAL-CjBSGfOfYUS@ashevche-desk.local> (raw)
In-Reply-To: <179513296378.3136.18205287276015126683@kernel.org>

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



      reply	other threads:[~2026-11-20  8:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:00 [PATCH v5 0/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr Liu Chao
2026-11-17  9:00 ` [PATCH v5 1/2] lib/net_utils: allow mac_pton() to take a custom delimiter Liu Chao
2026-11-17  9:00 ` [PATCH v5 2/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr Liu Chao
2026-11-20  0:02   ` netdev-bot+sashiko
2026-11-20  8:59     ` Andy Shevchenko [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=awAL-CjBSGfOfYUS@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=dbrownell@users.sourceforge.net \
    --cc=edumazet@kernel.org \
    --cc=fangxy@xiaopeng.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=horms@kernel.org \
    --cc=khtsai@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=liuc63@xiaopeng.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    /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