diff mbox series

[RFC] wifi: mac80211: Replace strncpy() with strscpy()

Message ID 20250327141108.182585-1-richard120310@gmail.com (mailing list archive)
State Rejected
Delegated to: Johannes Berg
Headers show
Series [RFC] wifi: mac80211: Replace strncpy() with strscpy() | expand

Checks

Context Check Description
wifibot/fixes_present success Fixes tag not required for -next series
wifibot/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
wifibot/tree_selection success Guessed tree name to be wireless-next
wifibot/ynl success Generated files up to date; no warnings/errors; no diff in generated;
wifibot/build_32bit success Errors and warnings before: 0 this patch: 0
wifibot/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
wifibot/build_clang success Errors and warnings before: 0 this patch: 0
wifibot/build_clang_rust success No Rust files in patch. Skipping build
wifibot/build_tools success No tools touched, skip
wifibot/check_selftest success No net selftest shell script
wifibot/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
wifibot/deprecated_api success None detected
wifibot/header_inline success No static functions without inline keyword in header files
wifibot/kdoc success Errors and warnings before: 0 this patch: 0
wifibot/source_inline success Was 0 now: 0
wifibot/verify_fixes success No Fixes tag
wifibot/verify_signedoff success Signed-off-by tag matches author and committer

Commit Message

I Hsin Cheng March 27, 2025, 2:11 p.m. UTC
The name of vif which is "vif_name" should be NULL-terminated to be a
valid string, however "strncpy()" doesn't guarantee that. Replace it
with "strscpy()" to make sure the content within "vif_name" is
NULL-terminated.

Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
 net/mac80211/trace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

I Hsin Cheng March 27, 2025, 2:24 p.m. UTC | #1
On Thu, Mar 27, 2025 at 10:11:08PM +0800, I Hsin Cheng wrote:
> The name of vif which is "vif_name" should be NULL-terminated to be a
> valid string, however "strncpy()" doesn't guarantee that. Replace it
> with "strscpy()" to make sure the content within "vif_name" is
> NULL-terminated.
> 
> Link: https://github.com/KSPP/linux/issues/90
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> ---
>  net/mac80211/trace.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
> index 72fad8ea8bb9..37f5b1c87709 100644
> --- a/net/mac80211/trace.h
> +++ b/net/mac80211/trace.h
> @@ -1725,7 +1725,7 @@ TRACE_EVENT(drv_switch_vif_chanctx,
>  				SWITCH_ENTRY_ASSIGN(vif.vif_type, vif->type);
>  				SWITCH_ENTRY_ASSIGN(vif.p2p, vif->p2p);
>  				SWITCH_ENTRY_ASSIGN(link_id, link_conf->link_id);
> -				strncpy(local_vifs[i].vif.vif_name,
> +				strscpy(local_vifs[i].vif.vif_name,
>  					sdata->name,
>  					sizeof(local_vifs[i].vif.vif_name));
>  				SWITCH_ENTRY_ASSIGN(old_chandef.control_freq,
> -- 
> 2.43.0
>

> The name of vif which is "vif_name" should be NULL-terminated to be a
Or maybe it should be trailing NULL-padding when sources is shorter, if
it's the case we should consider strscpy_pad() or other alternatives.

Let me know if there's any mistakes or tests I can help to validate,
thanks!

Best regards,
I Hsin Cheng
Johannes Berg March 28, 2025, 9:26 a.m. UTC | #2
On Thu, 2025-03-27 at 22:11 +0800, I Hsin Cheng wrote:
> The name of vif which is "vif_name" should be NULL-terminated to be a
> valid string

And why should it be a "valid string"? This is just a buffer here in the
trace code. We don't even (and cannot) suggest how to print this, so I
think the userspace tool that does will just need to be careful, as with
anything else. Don't see any issue here.

johannes
diff mbox series

Patch

diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 72fad8ea8bb9..37f5b1c87709 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -1725,7 +1725,7 @@  TRACE_EVENT(drv_switch_vif_chanctx,
 				SWITCH_ENTRY_ASSIGN(vif.vif_type, vif->type);
 				SWITCH_ENTRY_ASSIGN(vif.p2p, vif->p2p);
 				SWITCH_ENTRY_ASSIGN(link_id, link_conf->link_id);
-				strncpy(local_vifs[i].vif.vif_name,
+				strscpy(local_vifs[i].vif.vif_name,
 					sdata->name,
 					sizeof(local_vifs[i].vif.vif_name));
 				SWITCH_ENTRY_ASSIGN(old_chandef.control_freq,