mt76: replace strlcpy with strscpy
authorMieczyslaw Nalewaj <[email protected]>
Tue, 27 May 2025 06:19:29 +0000 (08:19 +0200)
committerHauke Mehrtens <[email protected]>
Thu, 19 Jun 2025 20:03:30 +0000 (22:03 +0200)
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 <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/18927
Signed-off-by: Hauke Mehrtens <[email protected]>
package/kernel/mt76/patches/002-wifi-mt76-replace-strlcpy-with-strscpy.patch [new file with mode: 0644]

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 (file)
index 0000000..176f6de
--- /dev/null
@@ -0,0 +1,73 @@
+From d6b484b5cb2a7d509b36a220911509ddd8b777c4 Mon Sep 17 00:00:00 2001\r
+From: Azeem Shaikh <[email protected]>\r
+Date: Mon, 3 Jul 2023 18:12:56 +0000\r
+Subject: wifi: mt76: Replace strlcpy() with strscpy()\r
+\r
+strlcpy() reads the entire source buffer first.\r
+This read may exceed the destination size limit.\r
+This is both inefficient and can lead to linear read\r
+overflows if a source string is not NUL-terminated [1].\r
+In an effort to remove strlcpy() completely [2], replace\r
+strlcpy() here with strscpy().\r
+\r
+Direct replacement is safe here since DEV_ASSIGN is only used by\r
+TRACE macros and the return values are ignored.\r
+\r
+[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy\r
+[2] https://github.com/KSPP/linux/issues/89\r
+\r
+Signed-off-by: Azeem Shaikh <[email protected]>\r
+Reviewed-by: Kees Cook <[email protected]>\r
+Signed-off-by: Kalle Valo <[email protected]>\r
+Link: https://lore.kernel.org/r/[email protected]\r
+---\r
+ mt7615/mt7615_trace.h | 2 +-\r
+ mt76x02_trace.h       | 2 +-\r
+ trace.h               | 2 +-\r
+ usb_trace.h           | 2 +-\r
+ 4 files changed, 4 insertions(+), 4 deletions(-)\r
+\r
+--- 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