* [RFC PATCH] net: sched: em_text: Replace strncpy() with strscpy_pad() @ 2025-03-27 14:37 I Hsin Cheng 2025-03-27 16:23 ` Florian Westphal 0 siblings, 1 reply; 3+ messages in thread From: I Hsin Cheng @ 2025-03-27 14:37 UTC (permalink / raw) To: jhs Cc: xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel, skhan, linux-kernel-mentees, I Hsin Cheng 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); conf.from_offset = tm->from_offset; conf.to_offset = tm->to_offset; conf.from_layer = tm->from_layer; -- 2.43.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] net: sched: em_text: Replace strncpy() with strscpy_pad() 2025-03-27 14:37 [RFC PATCH] net: sched: em_text: Replace strncpy() with strscpy_pad() I Hsin Cheng @ 2025-03-27 16:23 ` Florian Westphal 2025-04-05 8:57 ` I Hsin Cheng 0 siblings, 1 reply; 3+ messages in thread From: Florian Westphal @ 2025-03-27 16:23 UTC (permalink / raw) To: I Hsin Cheng Cc: jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel, skhan, linux-kernel-mentees 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. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] net: sched: em_text: Replace strncpy() with strscpy_pad() 2025-03-27 16:23 ` Florian Westphal @ 2025-04-05 8:57 ` I Hsin Cheng 0 siblings, 0 replies; 3+ messages in thread From: I Hsin Cheng @ 2025-04-05 8:57 UTC (permalink / raw) To: Florian Westphal Cc: jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel, skhan, linux-kernel-mentees On Thu, Mar 27, 2025 at 05:23:25PM +0100, Florian Westphal wrote: > 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. Hello Florian, Thanks for your kindly review! Sorry for the late reply, I was on a short school vacation. > Please drop the 3rd argument and then resend with a fixes tag: > Fixes: d675c989ed2d ("[PKT_SCHED]: Packet classification based on textsearch (ematch)") Sure, I'll do that and send v2. > As is, the last byte remains uninitialised. I see, may I ask the reason for the last byte to remain uninit? It's not going to be used so we can save the time to initialize it? And why does dropping 3rd argument can make the last byte uninit? I think "strscpy_pad()" always makes the trailing bytes in destination buffer to be NULL, so it'll always be init, shouldn't we use "strscpy()" instread ? Let me know if I misunderstand it, thanks! Best regards, I Hsin Cheng ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-05 8:58 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-03-27 14:37 [RFC PATCH] net: sched: em_text: Replace strncpy() with strscpy_pad() I Hsin Cheng 2025-03-27 16:23 ` Florian Westphal 2025-04-05 8:57 ` I Hsin Cheng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).