ipv4: Fix NULL deference in fnhe_remove_oldest()
Subsystems (3)
PATCH 1/1 ipv4: Fix NULL deference in fnhe_remove_oldest()
Coverity complains that linux-next commit 67d6d681e15b5 ("ipv4: make exception cache less predictible") neglected to check for NULL before dereferencing 'oldest'. It appears to be possible to fall through the for loop without ever setting 'oldest'.
--- net/ipv4/route.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/ipv4/route.c +5 -3
@@ -603,9 +603,11 @@ static void fnhe_remove_oldest(struct fnhe_hash_bucket *hash) oldest_p = fnhe_p; } } -fnhe_flush_routes (oldest); - *oldest_p = oldest->fnhe_next; -kfree_rcu (oldest, rcu); +if (oldest) { +fnhe_flush_routes (oldest); + *oldest_p = oldest->fnhe_next; +kfree_rcu (oldest, rcu); + } }static u32 fnhe_hashfun (__be32 daddr)
Signature · 1 line
2.33.0
Quoted 5 lines · Tim Gardner
Coverity complains that linux-next commit
67d6d681e15b5("ipv4: make exception cache less predictible") neglected to check for NULL before dereferencing 'oldest'. It appears to be possible to fall through the for loop without ever setting 'oldest'.
Coverity is wrong.
fnhe_remove_oldest() is only called when there are at least 6 items
in the list.
There is no way oldest could be NULL, or that oldest_p could contain garbage.
Quoted 35 lines
Cc Eric Dumazet <[email protected]>Cc "David S. Miller" <[email protected]>Cc Hideaki YOSHIFUJI <[email protected]>Cc David Ahern <[email protected]>Cc Jakub Kicinski <[email protected]>Signed-off-by Tim Gardner <[email protected]>--- net/ipv4/route.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)net/ipv4/route.c +5
-4@@ -603,9 +603,11 @@ static void fnhe_remove_oldest(struct fnhe_hash_bucket *hash) oldest_p = fnhe_p; } } -fnhe_flush_routes (oldest); - *oldest_p = oldest->fnhe_next; -kfree_rcu (oldest, rcu); +if (oldest) { +fnhe_flush_routes (oldest); + *oldest_p = oldest->fnhe_next; +kfree_rcu (oldest, rcu); + } }static u32 fnhe_hashfun (__be32 daddr) --2.33.0
Quoted 7 lines · Eric Dumazet
Quoted 5 lines · Tim Gardner
Coverity complains that linux-next commit
67d6d681e15b5("ipv4: make exception cache less predictible") neglected to check for NULL before dereferencing 'oldest'. It appears to be possible to fall through the for loop without ever setting 'oldest'.
Quoted 7 lines
Coverity is wrong.
fnhe_remove_oldest()is only called when there are at least 6 items
in the list.There is no way oldest could be NULL, or that
oldest_pcould contain garbage.
+1