diff mbox series

[RFC] net: sched: em_text: Replace strncpy() with strscpy_pad()

Message ID 20250327143733.187438-1-richard120310@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series [RFC] net: sched: em_text: Replace strncpy() with strscpy_pad() | expand

Checks

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

Commit Message

I Hsin Cheng March 27, 2025, 2:37 p.m. UTC
The content within "conf.algo" should be a valid NULL-terminated string,
however "strncpy()" doesn't guarantee that. Use strscpy_pad() to replace
it to make sure "conf.algo" is NULL-terminated. ( trailing NULL-padding
if source buffer is shorter. )

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

Comments

Florian Westphal March 27, 2025, 4:23 p.m. UTC | #1
I Hsin Cheng <richard120310@gmail.com> wrote:
> The content within "conf.algo" should be a valid NULL-terminated string,
> however "strncpy()" doesn't guarantee that. Use strscpy_pad() to replace
> it to make sure "conf.algo" is NULL-terminated. ( trailing NULL-padding
> if source buffer is shorter. )
>
> Link: https://github.com/KSPP/linux/issues/90
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> ---
>  net/sched/em_text.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sched/em_text.c b/net/sched/em_text.c
> index 420c66203b17..c78b82931dc4 100644
> --- a/net/sched/em_text.c
> +++ b/net/sched/em_text.c
> @@ -108,7 +108,7 @@ static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
>  	struct text_match *tm = EM_TEXT_PRIV(m);
>  	struct tcf_em_text conf;
>  
> -	strncpy(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);
> +	strscpy_pad(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);

Please drop the 3rd argument and then resend with a fixes tag:
Fixes: d675c989ed2d ("[PKT_SCHED]: Packet classification based on textsearch (ematch)")

As is, the last byte remains uninitialised.
diff mbox series

Patch

diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index 420c66203b17..c78b82931dc4 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -108,7 +108,7 @@  static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
 	struct text_match *tm = EM_TEXT_PRIV(m);
 	struct tcf_em_text conf;
 
-	strncpy(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);
+	strscpy_pad(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);
 	conf.from_offset = tm->from_offset;
 	conf.to_offset = tm->to_offset;
 	conf.from_layer = tm->from_layer;