Skip to contentSkip to conversation

wifi: mt76: Replace strlcpy with strscpy

PATCH Applied Azeem Shaikh 3 participants 9 messages Jul 3, 2023 – Aug 2, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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

---
 drivers/net/wireless/mediatek/mt76/mt7615/mt7615_trace.h | 2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_trace.h       | 2 +-
 drivers/net/wireless/mediatek/mt76/mt7921/mt7921_trace.h | 2 +-
 drivers/net/wireless/mediatek/mt76/trace.h               | 2 +-
 drivers/net/wireless/mediatek/mt76/usb_trace.h           | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mt7615_trace.h +1 -1
index d3eb49d83b98..9be5a58a4e6d 100644
@@ -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
drivers/net/wireless/mediatek/mt76/mt76x02_trace.h +1 -1
index 6a98092e996b..11d119cd0f6f 100644
@@ -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
drivers/net/wireless/mediatek/mt76/mt7921/mt7921_trace.h +1 -1
index 9bc4db67f352..887d5cfddd01 100644
@@ -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
drivers/net/wireless/mediatek/mt76/trace.h +1 -1
index c3d0ef8e2890..109a07f9733a 100644
@@ -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
drivers/net/wireless/mediatek/mt76/usb_trace.h +1 -1
index f5ab3215af80..7b261ddb2ac6 100644
@@ -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
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Azeem Shaikh

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().

Quoted 7 lines

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

Looks good -- thing is using return values from the macros.

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 12 lines · Kees Cook
Quoted 10 lines · Azeem Shaikh

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.

Quoted 6 lines
Quoted 4 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Looks good -- thing is using return values from the macros.

Just to confirm, you mean *not* using return values from the macros?

#3 lore raw
Quoted 13 lines · Azeem Shaikh
Quoted 12 lines · Kees Cook
Quoted 10 lines · Azeem Shaikh

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.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Looks good -- thing is using return values from the macros.

Just to confirm, you mean *not* using return values from the macros?

I thought I'd replied to this, but I see it didn't happen: yes, I meant "not using return values". Sorry for the confusion!

Signature · 1 line
Kees Cook
Applied
#4 lore raw
In reply to Azeem Shaikh
Quoted 8 lines · Azeem Shaikh

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().

[...]

Applied, thanks!

[1/1] wifi: mt76: Replace strlcpy with strscpy

      https://git.kernel.org/kees/c/535c78cbc0c4

Best regards,

Signature · 1 line
Kees Cook
#5 lore raw
Quoted 8 lines · Kees Cook
Quoted 7 lines · Azeem Shaikh

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().

Quoted 6 lines
Quoted 1 line

[...]

Applied, thanks!

[1/1] wifi: mt76: Replace strlcpy with strscpy

      https://git.kernel.org/kees/c/535c78cbc0c4

Why did you take this? mt76 is in active development so risk of conflicts is high.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#6 lore raw
Quoted 12 lines · Kalle Valo
Quoted 10 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh

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().

[...]

Quoted 7 lines
Quoted 4 lines

Applied, thanks!

[1/1] wifi: mt76: Replace strlcpy with strscpy

      https://git.kernel.org/kees/c/535c78cbc0c4

Why did you take this? mt76 is in active development so risk of conflicts is high.

There didn't seem to be any further activity for 3 weeks, and it was a relatively mechanical change. I can drop it from my tree. What's needed for it to be picked up through wireless?

-Kees

Signature · 1 line
Kees Cook
#7 lore raw
Quoted 15 lines · Kees Cook
Quoted 14 lines · Kalle Valo
Quoted 12 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh

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().

[...]

Applied, thanks!

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

[1/1] wifi: mt76: Replace strlcpy with strscpy

      https://git.kernel.org/kees/c/535c78cbc0c4

Why did you take this? mt76 is in active development so risk of conflicts is high.

There didn't seem to be any further activity for 3 weeks, and it was a relatively mechanical change.

That's because the wireless trees were on a summer break:

https://lore.kernel.org/all/[email protected]/

Quoted 1 line

I can drop it from my tree.

Yes, please drop this. And in the future don't take any wireless patches unless acked by Johannes or me, I want to minimize the risk of conflicts between the trees. If a patch is missed for whatever reason please let me know, do not take it to your tree.

Quoted 1 line

What's needed for it to be picked up through wireless?

I don't know why Felix didn't take this patch but now I assigned it to me on patchwork:

https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

It should be in wireless-next this week.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#8 lore raw

Re: wifi: mt76: Replace strlcpy() with strscpy()

In reply to Azeem Shaikh
Quoted 7 lines · Azeem Shaikh

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().

Quoted 8 lines

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

Patch applied to wireless-next.git, thanks.

d6b484b5cb2a wifi: mt76: Replace strlcpy() with strscpy()

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches