[PATCH v2025.09.y 36/58] net: eth: avoid overlapping memcpy in eth_set_ethaddr

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Mar 13 06:25:20 PDT 2026


eth_param_set_ethaddr() calls eth_set_ethaddr(edev, edev->ethaddr),
which results in memcpy(edev->ethaddr, ethaddr, ETH_ALEN) where source
and destination are the same buffer. This is undefined behavior with
memcpy.

Skip the memcpy when ethaddr already points to edev->ethaddr.

(cherry picked from commit 8d6fe4dff4e352a2226b9cf97e28b5204597c038)

Fixes: b9170a1bde ("net: eth: Remove ethaddr_param")
Reported-by: GCC 14.2 -fanalyzer
Co-authored-by: Claude Opus 4.6 <noreply at anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Link: https://lore.barebox.org/20260216084253.3547270-3-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 net/eth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/eth.c b/net/eth.c
index 857bd2ee70dd..1cc95944ccbd 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -41,7 +41,8 @@ int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr)
 	if (ret)
 		return ret;
 
-	memcpy(edev->ethaddr, ethaddr, ETH_ALEN);
+	if (ethaddr != edev->ethaddr)
+		memcpy(edev->ethaddr, ethaddr, ETH_ALEN);
 
 	return 0;
 }
-- 
2.47.3




More information about the barebox mailing list