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

From: Liu Chao

Date: Thu Nov 05 2026 - 22:09:28 EST


Rework of

[PATCH v3] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
https://lore.kernel.org/all/20261105072147.3383565-1-liuc63@xxxxxxxxxxxx/

following Andy's review: 1/2 prepares a parse_mac_pton() helper in
lib/net_utils.c, 2/2 uses it in get_ether_addr().

The two patches belong to different trees: 1/2 touches lib/ and should go
via netdev or -mm, 2/2 is for the USB tree. 2/2 depends on 1/2, so it
can only be applied once 1/2 has reached Linus' tree.

Changes since v3:
- no code change at all, the tree is byte identical to what Andy
reviewed, only the log of 2/2 changed
- 1/2: unchanged
- 2/2: pick up Andy's Reviewed-by
- 2/2: name 331a2d82bcaf ("[PATCH] USB: ethernet/rndis gadget address
params") from v2.6.7 as the commit that introduced the loop, and
record that it only resolves in the history.git tree, which is why
the series carries no Fixes tag
- 2/2: record that the Cisco notation and irregular groupings are
historical and rarely met these days, and that the commit introducing
the loop never documented accepting them

Changes since v2:
- 1/2: pick up Andy's Reviewed-by, no code change
- 2/2: keep the separator-less notation "aabbccddeeff" working by
falling back to hex2bin() when parse_mac_pton() does not match, as
suggested by Andy
- 2/2: drop the Fixes tag, the loop predates the git history
- 2/2: spell out in the log which notations stop being accepted

Changes since v1:
- rework the fix on top of parse_mac_pton() as suggested by Andy
instead of open coding the bounds checks in get_ether_addr()
- add the KASAN report and the malformed address example that v1 was
missing, both collected on a KASAN build by loading g_ether with a
short and with a non-hex dev_addr
- select GENERIC_NET_UTILS for USB_U_ETHER
- drop Cc: stable: 2/2 calls parse_mac_pton(), which 1/2 introduces,
so it cannot be backported to any stable tree on its own

One user visible effect remains: the Cisco notation "aabb.ccdd.eeff" and
irregular groupings such as "123456:789abc" are no longer parsed and now
fall back to a random address. Details are in the log of 2/2.

Liu Chao (2):
lib/net_utils: allow mac_pton() to take a custom delimiter
usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr

drivers/usb/gadget/Kconfig | 1 +
drivers/usb/gadget/function/u_ether.c | 18 ++++++++----------
include/linux/hex.h | 7 ++++++-
lib/net_utils.c | 17 ++++++++++++++---
4 files changed, 29 insertions(+), 14 deletions(-)


base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
--
2.50.1