Thread (3 messages) 3 messages, 2 authors, 2025-04-05
STALE467d

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

From: I Hsin Cheng <hidden>
Date: 2025-03-27 14:37:39
Also in: linux-kernel-mentees, lkml
Subsystem: networking [general], tc subsystem, the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Jamal Hadi Salim, Jiri Pirko, Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help