Skip to content

Commit 225622e

Browse files
namiltdhauke
authored andcommitted
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] KSPP/linux#89 Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com> Link: openwrt/openwrt#18927 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
1 parent 23faf4c commit 225622e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
From d6b484b5cb2a7d509b36a220911509ddd8b777c4 Mon Sep 17 00:00:00 2001
2+
From: Azeem Shaikh <azeemshaikh38@gmail.com>
3+
Date: Mon, 3 Jul 2023 18:12:56 +0000
4+
Subject: wifi: mt76: Replace strlcpy() with strscpy()
5+
6+
strlcpy() reads the entire source buffer first.
7+
This read may exceed the destination size limit.
8+
This is both inefficient and can lead to linear read
9+
overflows if a source string is not NUL-terminated [1].
10+
In an effort to remove strlcpy() completely [2], replace
11+
strlcpy() here with strscpy().
12+
13+
Direct replacement is safe here since DEV_ASSIGN is only used by
14+
TRACE macros and the return values are ignored.
15+
16+
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
17+
[2] https://github.com/KSPP/linux/issues/89
18+
19+
Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
20+
Reviewed-by: Kees Cook <keescook@chromium.org>
21+
Signed-off-by: Kalle Valo <kvalo@kernel.org>
22+
Link: https://lore.kernel.org/r/20230703181256.3712079-1-azeemshaikh38@gmail.com
23+
---
24+
mt7615/mt7615_trace.h | 2 +-
25+
mt76x02_trace.h | 2 +-
26+
trace.h | 2 +-
27+
usb_trace.h | 2 +-
28+
4 files changed, 4 insertions(+), 4 deletions(-)
29+
30+
--- a/mt7615/mt7615_trace.h
31+
+++ b/mt7615/mt7615_trace.h
32+
@@ -14,7 +14,7 @@
33+
34+
#define MAXNAME 32
35+
#define DEV_ENTRY __array(char, wiphy_name, 32)
36+
-#define DEV_ASSIGN strlcpy(__entry->wiphy_name, \
37+
+#define DEV_ASSIGN strscpy(__entry->wiphy_name, \
38+
wiphy_name(mt76_hw(dev)->wiphy), MAXNAME)
39+
#define DEV_PR_FMT "%s"
40+
#define DEV_PR_ARG __entry->wiphy_name
41+
--- a/mt76x02_trace.h
42+
+++ b/mt76x02_trace.h
43+
@@ -14,7 +14,7 @@
44+
45+
#define MAXNAME 32
46+
#define DEV_ENTRY __array(char, wiphy_name, 32)
47+
-#define DEV_ASSIGN strlcpy(__entry->wiphy_name, \
48+
+#define DEV_ASSIGN strscpy(__entry->wiphy_name, \
49+
wiphy_name(mt76_hw(dev)->wiphy), MAXNAME)
50+
#define DEV_PR_FMT "%s"
51+
#define DEV_PR_ARG __entry->wiphy_name
52+
--- a/trace.h
53+
+++ b/trace.h
54+
@@ -14,7 +14,7 @@
55+
56+
#define MAXNAME 32
57+
#define DEV_ENTRY __array(char, wiphy_name, 32)
58+
-#define DEVICE_ASSIGN strlcpy(__entry->wiphy_name, \
59+
+#define DEVICE_ASSIGN strscpy(__entry->wiphy_name, \
60+
wiphy_name(dev->hw->wiphy), MAXNAME)
61+
#define DEV_PR_FMT "%s"
62+
#define DEV_PR_ARG __entry->wiphy_name
63+
--- a/usb_trace.h
64+
+++ b/usb_trace.h
65+
@@ -14,7 +14,7 @@
66+
67+
#define MAXNAME 32
68+
#define DEV_ENTRY __array(char, wiphy_name, 32)
69+
-#define DEV_ASSIGN strlcpy(__entry->wiphy_name, \
70+
+#define DEV_ASSIGN strscpy(__entry->wiphy_name, \
71+
wiphy_name(dev->hw->wiphy), MAXNAME)
72+
#define DEV_PR_FMT "%s "
73+
#define DEV_PR_ARG __entry->wiphy_name

0 commit comments

Comments
 (0)