linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ipv4: fib_rules: Fix possible infinite loop in fib_empty_table
@ 2018-12-29  6:45 YueHaibing
  2018-12-30 20:57 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: YueHaibing @ 2018-12-29  6:45 UTC (permalink / raw)
  To: davem, kuznet, yoshfuji; +Cc: linux-kernel, netdev, YueHaibing

gcc warn this:
net/ipv4/fib_rules.c:203 fib_empty_table() warn:
 always true condition '(id <= 4294967295) => (0-u32max <= u32max)'

'id' is u32, which always not greater than RT_TABLE_MAX
(0xFFFFFFFF), So add a check to break while wrap around.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
v2: clean up exit conditions
---
 net/ipv4/fib_rules.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index f8eb78d..cfec3af 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -198,11 +198,15 @@ static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
 
 static struct fib_table *fib_empty_table(struct net *net)
 {
-	u32 id;
+	u32 id = 1;
 
-	for (id = 1; id <= RT_TABLE_MAX; id++)
+	while (1) {
 		if (!fib_get_table(net, id))
 			return fib_new_table(net, id);
+
+		if (id++ == RT_TABLE_MAX)
+			break;
+	}
 	return NULL;
 }
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ipv4: fib_rules: Fix possible infinite loop in fib_empty_table
  2018-12-29  6:45 [PATCH v2] ipv4: fib_rules: Fix possible infinite loop in fib_empty_table YueHaibing
@ 2018-12-30 20:57 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-12-30 20:57 UTC (permalink / raw)
  To: yuehaibing; +Cc: kuznet, yoshfuji, linux-kernel, netdev

From: YueHaibing <yuehaibing@huawei.com>
Date: Sat, 29 Dec 2018 14:45:23 +0800

> gcc warn this:
> net/ipv4/fib_rules.c:203 fib_empty_table() warn:
>  always true condition '(id <= 4294967295) => (0-u32max <= u32max)'
> 
> 'id' is u32, which always not greater than RT_TABLE_MAX
> (0xFFFFFFFF), So add a check to break while wrap around.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> v2: clean up exit conditions

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-12-30 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-29  6:45 [PATCH v2] ipv4: fib_rules: Fix possible infinite loop in fib_empty_table YueHaibing
2018-12-30 20:57 ` David Miller

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).