* [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn)
@ 2017-10-13 22:01 Wei Wang
2017-10-13 22:49 ` Martin KaFai Lau
2017-10-16 20:06 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Wei Wang @ 2017-10-13 22:01 UTC (permalink / raw)
To: David Miller, netdev; +Cc: Eric Dumazet, Martin KaFai Lau, Wei Wang
From: Wei Wang <weiwan@google.com>
In fib6_locate(), we need to first make sure fn is not NULL before doing
FIB6_SUBTREE(fn) to avoid crash.
This fixes the following static checker warning:
net/ipv6/ip6_fib.c:1462 fib6_locate()
warn: variable dereferenced before check 'fn' (see line 1459)
net/ipv6/ip6_fib.c
1458 if (src_len) {
1459 struct fib6_node *subtree = FIB6_SUBTREE(fn);
^^^^^^^^^^^^^^^^
We shifted this dereference
1460
1461 WARN_ON(saddr == NULL);
1462 if (fn && subtree)
^^
before the check for NULL.
1463 fn = fib6_locate_1(subtree, saddr, src_len,
1464 offsetof(struct rt6_info, rt6i_src)
Fixes: 66f5d6ce53e6 ("ipv6: replace rwlock with rcu and spinlock in fib6_table")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Wei Wang <weiwan@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
---
net/ipv6/ip6_fib.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index c2ecd5ec638a..548af48212fc 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1456,13 +1456,16 @@ struct fib6_node *fib6_locate(struct fib6_node *root,
#ifdef CONFIG_IPV6_SUBTREES
if (src_len) {
- struct fib6_node *subtree = FIB6_SUBTREE(fn);
-
WARN_ON(saddr == NULL);
- if (fn && subtree)
- fn = fib6_locate_1(subtree, saddr, src_len,
+ if (fn) {
+ struct fib6_node *subtree = FIB6_SUBTREE(fn);
+
+ if (subtree) {
+ fn = fib6_locate_1(subtree, saddr, src_len,
offsetof(struct rt6_info, rt6i_src),
exact_match);
+ }
+ }
}
#endif
--
2.15.0.rc0.271.g36b669edcc-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn)
2017-10-13 22:01 [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn) Wei Wang
@ 2017-10-13 22:49 ` Martin KaFai Lau
2017-10-16 20:06 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2017-10-13 22:49 UTC (permalink / raw)
To: Wei Wang; +Cc: David Miller, netdev, Eric Dumazet
On Fri, Oct 13, 2017 at 10:01:08PM +0000, Wei Wang wrote:
> From: Wei Wang <weiwan@google.com>
>
> In fib6_locate(), we need to first make sure fn is not NULL before doing
> FIB6_SUBTREE(fn) to avoid crash.
Acked-by: Martin KaFai Lau <kafai@fb.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn)
2017-10-13 22:01 [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn) Wei Wang
2017-10-13 22:49 ` Martin KaFai Lau
@ 2017-10-16 20:06 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-10-16 20:06 UTC (permalink / raw)
To: weiwan; +Cc: netdev, edumazet, kafai
From: Wei Wang <weiwan@google.com>
Date: Fri, 13 Oct 2017 15:01:08 -0700
> From: Wei Wang <weiwan@google.com>
>
> In fib6_locate(), we need to first make sure fn is not NULL before doing
> FIB6_SUBTREE(fn) to avoid crash.
>
> This fixes the following static checker warning:
> net/ipv6/ip6_fib.c:1462 fib6_locate()
> warn: variable dereferenced before check 'fn' (see line 1459)
>
> net/ipv6/ip6_fib.c
> 1458 if (src_len) {
> 1459 struct fib6_node *subtree = FIB6_SUBTREE(fn);
> ^^^^^^^^^^^^^^^^
> We shifted this dereference
>
> 1460
> 1461 WARN_ON(saddr == NULL);
> 1462 if (fn && subtree)
> ^^
> before the check for NULL.
>
> 1463 fn = fib6_locate_1(subtree, saddr, src_len,
> 1464 offsetof(struct rt6_info, rt6i_src)
>
> Fixes: 66f5d6ce53e6 ("ipv6: replace rwlock with rcu and spinlock in fib6_table")
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Wei Wang <weiwan@google.com>
> Acked-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-16 20:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-13 22:01 [PATCH net-next] ipv6: check fn before doing FIB6_SUBTREE(fn) Wei Wang
2017-10-13 22:49 ` Martin KaFai Lau
2017-10-16 20:06 ` 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).