* [PATCH v5 0/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
@ 2026-11-17 9:00 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
0 siblings, 2 replies; 4+ messages in thread
From: Liu Chao @ 2026-11-17 9:00 UTC (permalink / raw)
To: Greg Kroah-Hartman, Andrew Morton
Cc: Andy Shevchenko, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, khtsai, fangxy, Randy Dunlap,
dbrownell, linux-usb, linux-kernel, netdev
Rework of
[PATCH v4] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
https://lore.kernel.org/all/20261106030605.576584-1-liuc63@xiaopeng.com/
following Andy's review of v4: 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 v4:
- no driver code change; the C diff of both patches is byte identical
to v4, only documentation and the commit messages changed
- 1/2: reword the parse_mac_pton() kernel-doc: @s must be at least
MAC_ADDR_STR_LEN characters long, and only the first
MAC_ADDR_STR_LEN characters are checked, the rest ignored
- 2/2: describe the configfs behaviour change accurately: a rejected
address makes the store fail with -EINVAL and keep its previous
value, while only the legacy module parameters fall back to a random
address
- 2/2: name all five functions that reach the parser (ECM, EEM, NCM,
RNDIS, subset) and document the accepted formats in their configfs
ABI files
- 2/2: restore a Fixes: tag pointing at 1da177e4c3f4
("Linux-2.6.12-rc2"), the start of the official git era, keeping the
commit that really introduced the loop named in prose
- 2/2: say "checks the minimum length" where v4 said "checks the
length"
Changes since v3:
- no code change at all, 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
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
- 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
- select GENERIC_NET_UTILS for USB_U_ETHER
One user visible effect remains: the Cisco notation "aabb.ccdd.eeff" and
irregular groupings such as "123456:789abc" are no longer parsed. The
legacy module parameters then fall back to a random address and log a
warning, while a configfs store fails with -EINVAL and keeps the previous
value. 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
.../ABI/testing/configfs-usb-gadget-ecm | 7 ++++++-
.../ABI/testing/configfs-usb-gadget-eem | 7 +++++++
.../ABI/testing/configfs-usb-gadget-ncm | 6 ++++++
.../ABI/testing/configfs-usb-gadget-rndis | 7 +++++++
.../ABI/testing/configfs-usb-gadget-subset | 7 +++++++
drivers/usb/gadget/Kconfig | 1 +
drivers/usb/gadget/function/u_ether.c | 18 ++++++++----------
include/linux/hex.h | 7 ++++++-
lib/net_utils.c | 19 ++++++++++++++++---
9 files changed, 64 insertions(+), 15 deletions(-)
base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
--
2.50.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v5 1/2] lib/net_utils: allow mac_pton() to take a custom delimiter
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 ` 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
1 sibling, 0 replies; 4+ messages in thread
From: Liu Chao @ 2026-11-17 9:00 UTC (permalink / raw)
To: Greg Kroah-Hartman, Andrew Morton
Cc: Andy Shevchenko, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, khtsai, fangxy, Randy Dunlap,
dbrownell, linux-usb, linux-kernel, netdev
mac_pton() hardcodes ':' as the only accepted separator, which pushes
callers that need a different notation to open-code their own parser.
Split the body out into parse_mac_pton() taking the set of accepted
delimiters as a string, and turn mac_pton() into a static inline wrapper
passing ":" so that every existing caller keeps its current behaviour.
The strnlen() guard still runs before any delimiter is inspected, so
strchr() is never handed a NUL character.
No functional change intended.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
v5: reword the parse_mac_pton() kernel-doc to say @s must be at least
MAC_ADDR_STR_LEN characters long and that only the first
MAC_ADDR_STR_LEN characters are checked, the rest ignored. No code
change.
v4: no change.
v3: pick up Andy's Reviewed-by, no code change.
v2: new patch, split out of the u_ether fix at Andy's suggestion.
Link: https://lore.kernel.org/all/20261106030605.576584-2-liuc63@xiaopeng.com/
include/linux/hex.h | 7 ++++++-
lib/net_utils.c | 19 ++++++++++++++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/include/linux/hex.h b/include/linux/hex.h
index 2618382e5b0c..408825478cda 100644
--- a/include/linux/hex.h
+++ b/include/linux/hex.h
@@ -30,6 +30,11 @@ extern int hex_to_bin(unsigned char ch);
extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
extern char *bin2hex(char *dst, const void *src, size_t count);
-bool mac_pton(const char *s, u8 *mac);
+bool parse_mac_pton(const char *s, u8 *mac, const char *delim);
+
+static inline bool mac_pton(const char *s, u8 *mac)
+{
+ return parse_mac_pton(s, mac, ":");
+}
#endif
diff --git a/lib/net_utils.c b/lib/net_utils.c
index 215cda672fee..fd76b9ab3f24 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -5,7 +5,20 @@
#include <linux/export.h>
#include <linux/hex.h>
-bool mac_pton(const char *s, u8 *mac)
+/**
+ * parse_mac_pton - convert a MAC address string using a custom delimiter
+ * @s: string to be parsed
+ * @mac: buffer to store the result, left untouched if @s is malformed
+ * @delim: characters accepted as a separator between the byte pairs
+ *
+ * @s must be at least MAC_ADDR_STR_LEN characters long and use a character
+ * from @delim at every separator position, e.g. "aa.bb:cc.dd:ee.ff" with
+ * ".:". Only the first MAC_ADDR_STR_LEN characters are checked; anything
+ * after them is ignored.
+ *
+ * Return: true on success, false if @s is malformed.
+ */
+bool parse_mac_pton(const char *s, u8 *mac, const char *delim)
{
int i;
@@ -16,7 +29,7 @@ bool mac_pton(const char *s, u8 *mac)
for (i = 0; i < ETH_ALEN; i++) {
if (!isxdigit(s[i * 3]) || !isxdigit(s[i * 3 + 1]))
return false;
- if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
+ if (i != ETH_ALEN - 1 && !strchr(delim, s[i * 3 + 2]))
return false;
}
for (i = 0; i < ETH_ALEN; i++) {
@@ -24,4 +37,4 @@ bool mac_pton(const char *s, u8 *mac)
}
return true;
}
-EXPORT_SYMBOL(mac_pton);
+EXPORT_SYMBOL(parse_mac_pton);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v5 2/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
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 ` Liu Chao
2026-11-20 0:02 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Liu Chao @ 2026-11-17 9:00 UTC (permalink / raw)
To: Greg Kroah-Hartman, Andrew Morton
Cc: Andy Shevchenko, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, khtsai, fangxy, Randy Dunlap,
dbrownell, linux-usb, linux-kernel, netdev
get_ether_addr() walks the MAC address string with a fixed six iteration
loop, calling hex_to_bin() twice per iteration, and never checks for the
terminating NUL. A short string therefore makes it read past the end of
the buffer. The dev_addr and host_addr module parameters of the legacy
gadget drivers are copied into their own kmalloc'ed buffer by
param_set_charp(), so the overrun crosses a slab boundary and KASAN
reports it at insmod time:
# insmod g_ether.ko dev_addr=ab
BUG: KASAN: slab-out-of-bounds in get_ether_addr+0x1ec/0x230
Read of size 1 at addr ffff888009f91f53 by task insmod/70
...
get_ether_addr+0x1ec/0x230
gether_set_dev_addr+0x6b/0x180
eth_bind+0xfd/0x3b0 [g_ether]
composite_bind+0x1bb/0x7b0
gadget_bind_driver+0x229/0xb00
...
Allocated by task 70:
__kmalloc_noprof+0x1d1/0x4a0
param_set_charp+0x4a/0x220
parse_args+0x267/0x5c0
load_module+0x4f6a/0x6600
...
The buggy address is located 0 bytes to the right of
allocated 19-byte region [ffff888009f91f40, ffff888009f91f53)
Besides reading past the end of the string, the loop ignores what
hex_to_bin() returns: it yields -1 for a character that is not a hex
digit, and that value is shifted and OR'ed into dev_addr unchecked, so a
malformed address can be accepted as a valid one and the interface comes
up with an address that nobody asked for:
# insmod g_ether.ko dev_addr=aazz:cc:dd:ee:ff
# cat /sys/class/net/usb0/address
aa:ff:cc:dd:ee:ff
The configfs dev_addr and host_addr attributes of the ECM, EEM, NCM,
RNDIS and subset functions reach the same parser through
gether_set_dev_addr() and gether_set_host_addr(). Their store handler
passes the whole configfs buffer on, so an overrun there stays inside the
same object and is never reported, but a malformed address is silently
accepted all the same.
Replace the open coded loop with parse_mac_pton() for the delimited
notations and hex2bin() for the raw one, and keep the existing
eth_random_addr() fallback for everything both of them reject.
parse_mac_pton() checks the minimum length and every digit before writing
anything to dev_addr, and hex2bin() stops at the first character that is
not a hex digit, which the NUL terminator is, so neither reads past the
end of the string.
The notations that keep working are the byte pair ones, ':' and '.', in
any mixture, and the separator-less "aabbccddeeff". What stops working
is the Cisco notation "aabb.ccdd.eeff" and irregular groupings such as
"123456:789abc", which the old loop only accepted because it skipped a
delimiter wherever it happened to find one. Supporting them would need
a parser per grouping, so such input is now rejected.
Neither of the two should be missed: they are historical notations that
are rarely met these days, and the commit that introduced the loop never
said that it accepted them. That commit only explains that it resolves
a FIXME by adding module parameters for stable addresses, so skipping a
delimiter wherever one happens to turn up reads as a simplification of
the parser rather than as support for non-standard formats.
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. The
configfs attributes go through gether_set_dev_addr() and
gether_set_host_addr(), which return -EINVAL, so the store fails and the
attribute keeps its previous value: writing "aabb.ccdd.eeff" to dev_addr
used to succeed and now fails. This commit documents the accepted
formats in the configfs ABI files of all five functions.
Select GENERIC_NET_UTILS so that parse_mac_pton() is built in.
The loop is older than the git history. It was introduced by
331a2d82bcaf ("[PATCH] USB: ethernet/rndis gadget address params") from
v2.6.7 in drivers/usb/gadget/ether.c, and commit 2b3d942c4878 ("usb
ethernet gadget: split out network core") copied it into u_ether.c.
331a2d82bcaf predates the git conversion and only resolves in the
historic tree history.git, so the Fixes: tag points at the start of the
official git era, commit 1da177e4c3f4 ("Linux-2.6.12-rc2"), and the
commit that actually introduced the loop is named here in prose.
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
---
v5: no driver code change. Describe the configfs behaviour accurately
(a rejected address fails the store with -EINVAL and keeps the old
value; only the legacy module parameters fall back to a random
address), name all five functions that use the parser, document the
accepted formats in their configfs ABI files, restore a Fixes: tag
for 1da177e4c3f4 ("Linux-2.6.12-rc2") while keeping the real
introducing commit in prose, and say "minimum length" where v4 said
"length".
v4: pick up Andy's Reviewed-by; name 331a2d82bcaf from v2.6.7 as the
commit that introduced the loop and note that it only resolves in
history.git; record that the notations being dropped are historical
and were never documented as supported. No code change.
v3: fall back to hex2bin() so that the separator-less notation keeps
working, as suggested by Andy; drop the Fixes tag, the loop predates
the git history.
v2: rework on top of parse_mac_pton(), add the KASAN report and the
malformed address example, select GENERIC_NET_UTILS, drop Cc: stable
and the Reviewed-by.
Link: https://lore.kernel.org/all/20261106030605.576584-3-liuc63@xiaopeng.com/
.../ABI/testing/configfs-usb-gadget-ecm | 7 ++++++-
.../ABI/testing/configfs-usb-gadget-eem | 7 +++++++
.../ABI/testing/configfs-usb-gadget-ncm | 6 ++++++
.../ABI/testing/configfs-usb-gadget-rndis | 7 +++++++
.../ABI/testing/configfs-usb-gadget-subset | 7 +++++++
drivers/usb/gadget/Kconfig | 1 +
drivers/usb/gadget/function/u_ether.c | 18 ++++++++----------
7 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-ecm b/Documentation/ABI/testing/configfs-usb-gadget-ecm
index 732101ca9d0b..076567aacf16 100644
--- 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.
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-eem b/Documentation/ABI/testing/configfs-usb-gadget-eem
index 178c3d5fb647..fb2be6ac0864 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-eem
+++ b/Documentation/ABI/testing/configfs-usb-gadget-eem
@@ -14,3 +14,10 @@ Description:
dev_addr 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.
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-ncm b/Documentation/ABI/testing/configfs-usb-gadget-ncm
index 6fe723effc78..a98ba929f2c2 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-ncm
+++ b/Documentation/ABI/testing/configfs-usb-gadget-ncm
@@ -13,3 +13,9 @@ Description:
dev_addr - 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.
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis b/Documentation/ABI/testing/configfs-usb-gadget-rndis
index 9416eda7fe93..775b32cae136 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-rndis
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -17,3 +17,10 @@ Description:
subclass USB interface subclass, default is 06 (hex)
protocol USB interface protocol, default is 00 (hex)
========= =============================================
+
+ 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.
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-subset b/Documentation/ABI/testing/configfs-usb-gadget-subset
index 0061b864351f..f67537fe53a0 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget-subset
+++ b/Documentation/ABI/testing/configfs-usb-gadget-subset
@@ -14,3 +14,10 @@ Description:
dev_addr 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.
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 76521555e3c1..b83c42be686b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -158,6 +158,7 @@ config USB_U_SERIAL
config USB_U_ETHER
tristate
+ select GENERIC_NET_UTILS
config USB_U_AUDIO
tristate
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 59d85d6a84a8..deedea8a19fd 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -686,18 +686,16 @@ static int eth_stop(struct net_device *net)
static int get_ether_addr(const char *str, u8 *dev_addr)
{
if (str) {
- unsigned i;
+ bool valid;
- for (i = 0; i < 6; i++) {
- unsigned char num;
+ /* Try the delimited formats first */
+ valid = parse_mac_pton(str, dev_addr, ".:");
+ if (valid && is_valid_ether_addr(dev_addr))
+ return 0;
- if ((*str == '.') || (*str == ':'))
- str++;
- num = hex_to_bin(*str++) << 4;
- num |= hex_to_bin(*str++);
- dev_addr [i] = num;
- }
- if (is_valid_ether_addr(dev_addr))
+ /* Fall back to the raw format */
+ valid = hex2bin(dev_addr, str, ETH_ALEN) == 0;
+ if (valid && is_valid_ether_addr(dev_addr))
return 0;
}
eth_random_addr(dev_addr);
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v5 2/2] usb: gadget: u_ether: fix out-of-bounds read in get_ether_addr
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
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-20 0:02 UTC (permalink / raw)
To: liuc63
Cc: gregkh, akpm, andriy.shevchenko, davem, edumazet, kuba, pabeni,
horms, khtsai, fangxy, rdunlap, dbrownell, linux-usb,
linux-kernel, netdev
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?
Could the commit message be corrected to describe the
gether_set_dev_addr() path that the legacy parameters actually take?
> diff --git a/Documentation/ABI/testing/configfs-usb-gadget-ecm b/Documentation/ABI/testing/configfs-usb-gadget-ecm
> index 732101ca9d0bb..076567aacf162 100644
> --- 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.
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.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117090110.3263592-1-liuc63%40xiaopeng.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 0:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox