Skip to content

Commit c58e88d

Browse files
edumazetdavem330
authored andcommitted
icmp: prevent possible NULL dereferences from icmp_build_probe()
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: d329ea5 ("icmp: add response to RFC 8335 PROBE messages") Signed-off-by: Eric Dumazet <[email protected]> Cc: Andreas Roeseler <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0b8fe5b commit c58e88d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/ipv4/icmp.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include <net/inet_common.h>
9393
#include <net/ip_fib.h>
9494
#include <net/l3mdev.h>
95+
#include <net/addrconf.h>
9596

9697
/*
9798
* Build xmit assembly blocks
@@ -1032,6 +1033,8 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
10321033
struct icmp_ext_hdr *ext_hdr, _ext_hdr;
10331034
struct icmp_ext_echo_iio *iio, _iio;
10341035
struct net *net = dev_net(skb->dev);
1036+
struct inet6_dev *in6_dev;
1037+
struct in_device *in_dev;
10351038
struct net_device *dev;
10361039
char buff[IFNAMSIZ];
10371040
u16 ident_len;
@@ -1115,10 +1118,15 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
11151118
/* Fill bits in reply message */
11161119
if (dev->flags & IFF_UP)
11171120
status |= ICMP_EXT_ECHOREPLY_ACTIVE;
1118-
if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
1121+
1122+
in_dev = __in_dev_get_rcu(dev);
1123+
if (in_dev && rcu_access_pointer(in_dev->ifa_list))
11191124
status |= ICMP_EXT_ECHOREPLY_IPV4;
1120-
if (!list_empty(&rcu_dereference(dev->ip6_ptr)->addr_list))
1125+
1126+
in6_dev = __in6_dev_get(dev);
1127+
if (in6_dev && !list_empty(&in6_dev->addr_list))
11211128
status |= ICMP_EXT_ECHOREPLY_IPV6;
1129+
11221130
dev_put(dev);
11231131
icmphdr->un.echo.sequence |= htons(status);
11241132
return true;

0 commit comments

Comments
 (0)