[openwrt/openwrt] mt76: replace strlcpy with strscpy

LEDE Commits lede-commits at lists.infradead.org
Thu Jun 19 13:04:46 PDT 2025


hauke pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/225622e0f9fb4cba6da747499a68f5ee34842573

commit 225622e0f9fb4cba6da747499a68f5ee34842573
Author: Mieczyslaw Nalewaj <namiltd at yahoo.com>
AuthorDate: Tue May 27 08:19:29 2025 +0200

    mt76: replace strlcpy with strscpy
    
    Change deprecated function strlcpy to strscpy
    for compatibility with kernel 6.12.
    
    strlcpy() reads the entire source buffer first.
    This read may exceed the destination size limit.
    This is both inefficient and can lead to linear read
    overflows if a source string is not NUL-terminated [1].
    In an effort to remove strlcpy() completely [2], replace
    strlcpy() here with strscpy().
    
    Direct replacement is safe here since DEV_ASSIGN is only used by
    TRACE macros and the return values are ignored.
    
    [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
    [2] https://github.com/KSPP/linux/issues/89
    
    Signed-off-by: Mieczyslaw Nalewaj <namiltd at yahoo.com>
    Link: https://github.com/openwrt/openwrt/pull/18927
    Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
---
 ...02-wifi-mt76-replace-strlcpy-with-strscpy.patch | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/package/kernel/mt76/patches/002-wifi-mt76-replace-strlcpy-with-strscpy.patch b/package/kernel/mt76/patches/002-wifi-mt76-replace-strlcpy-with-strscpy.patch
new file mode 100644
index 0000000000..176f6de5a0
--- /dev/null
+++ b/package/kernel/mt76/patches/002-wifi-mt76-replace-strlcpy-with-strscpy.patch
@@ -0,0 +1,73 @@
+From d6b484b5cb2a7d509b36a220911509ddd8b777c4 Mon Sep 17 00:00:00 2001
+From: Azeem Shaikh <azeemshaikh38 at gmail.com>
+Date: Mon, 3 Jul 2023 18:12:56 +0000
+Subject: wifi: mt76: Replace strlcpy() with strscpy()
+
+strlcpy() reads the entire source buffer first.
+This read may exceed the destination size limit.
+This is both inefficient and can lead to linear read
+overflows if a source string is not NUL-terminated [1].
+In an effort to remove strlcpy() completely [2], replace
+strlcpy() here with strscpy().
+
+Direct replacement is safe here since DEV_ASSIGN is only used by
+TRACE macros and the return values are ignored.
+
+[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
+[2] https://github.com/KSPP/linux/issues/89
+
+Signed-off-by: Azeem Shaikh <azeemshaikh38 at gmail.com>
+Reviewed-by: Kees Cook <keescook at chromium.org>
+Signed-off-by: Kalle Valo <kvalo at kernel.org>
+Link: https://lore.kernel.org/r/20230703181256.3712079-1-azeemshaikh38@gmail.com
+---
+ mt7615/mt7615_trace.h | 2 +-
+ mt76x02_trace.h       | 2 +-
+ trace.h               | 2 +-
+ usb_trace.h           | 2 +-
+ 4 files changed, 4 insertions(+), 4 deletions(-)
+
+--- a/mt7615/mt7615_trace.h
++++ b/mt7615/mt7615_trace.h
+@@ -14,7 +14,7 @@
+ 
+ #define MAXNAME		32
+ #define DEV_ENTRY	__array(char, wiphy_name, 32)
+-#define DEV_ASSIGN	strlcpy(__entry->wiphy_name,	\
++#define DEV_ASSIGN	strscpy(__entry->wiphy_name,	\
+ 				wiphy_name(mt76_hw(dev)->wiphy), MAXNAME)
+ #define DEV_PR_FMT	"%s"
+ #define DEV_PR_ARG	__entry->wiphy_name
+--- a/mt76x02_trace.h
++++ b/mt76x02_trace.h
+@@ -14,7 +14,7 @@
+ 
+ #define MAXNAME		32
+ #define DEV_ENTRY	__array(char, wiphy_name, 32)
+-#define DEV_ASSIGN	strlcpy(__entry->wiphy_name,	\
++#define DEV_ASSIGN	strscpy(__entry->wiphy_name,	\
+ 				wiphy_name(mt76_hw(dev)->wiphy), MAXNAME)
+ #define DEV_PR_FMT	"%s"
+ #define DEV_PR_ARG	__entry->wiphy_name
+--- a/trace.h
++++ b/trace.h
+@@ -14,7 +14,7 @@
+ 
+ #define MAXNAME		32
+ #define DEV_ENTRY	__array(char, wiphy_name, 32)
+-#define DEVICE_ASSIGN	strlcpy(__entry->wiphy_name,	\
++#define DEVICE_ASSIGN	strscpy(__entry->wiphy_name,	\
+ 				wiphy_name(dev->hw->wiphy), MAXNAME)
+ #define DEV_PR_FMT	"%s"
+ #define DEV_PR_ARG	__entry->wiphy_name
+--- a/usb_trace.h
++++ b/usb_trace.h
+@@ -14,7 +14,7 @@
+ 
+ #define MAXNAME		32
+ #define DEV_ENTRY	__array(char, wiphy_name, 32)
+-#define DEV_ASSIGN	strlcpy(__entry->wiphy_name,	\
++#define DEV_ASSIGN	strscpy(__entry->wiphy_name,	\
+ 				wiphy_name(dev->hw->wiphy), MAXNAME)
+ #define DEV_PR_FMT	"%s "
+ #define DEV_PR_ARG	__entry->wiphy_name




More information about the lede-commits mailing list