[PATCH 5.10 174/289] net: fix nla_strcmp to handle more then one trailing null character

From
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date
2021-05-17 15:50:44
Also in
lkml
Reply to
Greg Kroah-Hartman, 2021-05-17
From: Maciej Żenczykowski <redacted>

[ Upstream commit 2c16db6c92b0ee4aa61e88366df82169e83c3f7e ]

Android userspace has been using TCA_KIND with a char[IFNAMESIZ]
many-null-terminated buffer containing the string 'bpf'.

This works on 4.19 and ceases to work on 5.10.

I'm not entirely sure what fixes tag to use, but I think the issue
was likely introduced in the below mentioned 5.4 commit.

Reported-by: Nucca Chen <redacted>
Cc: Cong Wang <redacted>
Cc: David Ahern <redacted>
Cc: David S. Miller <davem@davemloft.net>
Cc: Jakub Kicinski <redacted>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <redacted>
Cc: Jiri Pirko <jiri@resnulli.us>
Fixes: 62794fc4fbf5 ("net_sched: add max len check for TCA_KIND")
Change-Id: I66dc281f165a2858fc29a44869a270a2d698a82b
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 lib/nlattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/nlattr.c b/lib/nlattr.c
index 74019c8ebf6b..fe60f9ae9db1 100644
--- a/lib/nlattr.c
+++ b/lib/nlattr.c
@@ -816,7 +816,7 @@ int nla_strcmp(const struct nlattr *nla, const char *str)
 	int attrlen = nla_len(nla);
 	int d;
 
-	if (attrlen > 0 && buf[attrlen - 1] == '\0')
+	while (attrlen > 0 && buf[attrlen - 1] == '\0')
 		attrlen--;
 
 	d = attrlen - len;
-- 
2.30.2


Thread (305 messages) 305 messages, 13 authors, last reply 2021-05-27
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help