icmp: prevent possible NULL dereferences from icmp_build_probe()
authorEric Dumazet <edumazet@google.com>
Sat, 20 Apr 2024 07:01:16 +0000 (07:01 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 May 2024 14:24:44 +0000 (16:24 +0200)
commit23b7ee4a8d559bf38eac7ce5bb2f6ebf76f9c401
tree4b07daee4aa154810dafb3da050ddc585a4f0bcc
parent8bdd3cf01490b325a2b9976b5a943e669a708385
icmp: prevent possible NULL dereferences from icmp_build_probe()

[ Upstream commit c58e88d49097bd12dfcfef4f075b43f5d5830941 ]

First problem is a double call to __in_dev_get_rcu(), because
the second one could return NULL.

if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)

Second problem is a read from dev->ip6_ptr with no NULL check:

if (!list_empty(&rcu_dereference(dev->ip6_ptr)->addr_list))

Use the correct RCU API to fix these.

v2: add missing include <net/addrconf.h>

Fixes: d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Andreas Roeseler <andreas.a.roeseler@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/icmp.c