Skip to content

Commit 45f29b4

Browse files
CIQ Kernel Automationbmastbergen
authored andcommitted
icmp: prevent possible NULL dereferences from icmp_build_probe()
jira VULN-43056 cve CVE-2024-35857 commit-author Eric Dumazet <edumazet@google.com> commit c58e88d 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 <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> (cherry picked from commit c58e88d) Signed-off-by: CIQ Kernel Automation <ciq_kernel_automation@ciq.com>
1 parent 82c3239 commit 45f29b4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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
@@ -1027,6 +1028,8 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
10271028
struct icmp_ext_hdr *ext_hdr, _ext_hdr;
10281029
struct icmp_ext_echo_iio *iio, _iio;
10291030
struct net *net = dev_net(skb->dev);
1031+
struct inet6_dev *in6_dev;
1032+
struct in_device *in_dev;
10301033
struct net_device *dev;
10311034
char buff[IFNAMSIZ];
10321035
u16 ident_len;
@@ -1110,10 +1113,15 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
11101113
/* Fill bits in reply message */
11111114
if (dev->flags & IFF_UP)
11121115
status |= ICMP_EXT_ECHOREPLY_ACTIVE;
1113-
if (__in_dev_get_rcu(dev) && __in_dev_get_rcu(dev)->ifa_list)
1116+
1117+
in_dev = __in_dev_get_rcu(dev);
1118+
if (in_dev && rcu_access_pointer(in_dev->ifa_list))
11141119
status |= ICMP_EXT_ECHOREPLY_IPV4;
1115-
if (!list_empty(&rcu_dereference(dev->ip6_ptr)->addr_list))
1120+
1121+
in6_dev = __in6_dev_get(dev);
1122+
if (in6_dev && !list_empty(&in6_dev->addr_list))
11161123
status |= ICMP_EXT_ECHOREPLY_IPV6;
1124+
11171125
dev_put(dev);
11181126
icmphdr->un.echo.sequence |= htons(status);
11191127
return true;

0 commit comments

Comments
 (0)