Skip to content

Commit

Permalink
ipv4: fib_rules: Fix possible infinite loop in fib_empty_table
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
YueHaibing authored and David S. Miller committed Dec 30, 2018
1 parent 178fe94 commit 58075ff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions net/ipv4/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 58075ff

Please sign in to comment.