Skip to content

Commit 6c62873

Browse files
committed
net: ipv6: Verify ICMPv6 checksum before accepting packet
Make sure that ICMPv6 checksum is correct before continuing processing the packet. Fixes #10971 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent b0ebe0d commit 6c62873

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

subsys/net/ip/ipv6.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static inline enum net_verdict process_icmpv6_pkt(struct net_pkt *pkt,
150150
struct net_ipv6_hdr *ipv6)
151151
{
152152
struct net_icmp_hdr icmp_hdr;
153+
u16_t chksum;
153154
int ret;
154155

155156
ret = net_icmpv6_get_hdr(pkt, &icmp_hdr);
@@ -158,6 +159,16 @@ static inline enum net_verdict process_icmpv6_pkt(struct net_pkt *pkt,
158159
return NET_DROP;
159160
}
160161

162+
chksum = icmp_hdr.chksum;
163+
net_icmpv6_set_chksum(pkt);
164+
(void)net_icmpv6_get_hdr(pkt, &icmp_hdr);
165+
166+
if (chksum != icmp_hdr.chksum) {
167+
NET_DBG("ICMPv6 invalid checksum (0x%04x instead of 0x%04x)",
168+
ntohs(chksum), ntohs(icmp_hdr.chksum));
169+
return NET_DROP;
170+
}
171+
161172
NET_DBG("ICMPv6 %s received type %d code %d",
162173
net_icmpv6_type2str(icmp_hdr.type), icmp_hdr.type,
163174
icmp_hdr.code);

0 commit comments

Comments
 (0)