Skip to content

Commit ad27d0e

Browse files
committed
net: ipv6: Check the size of the ICMPv6 echo-req packet
The minimum size is 8 bytes, drop packet if shorter. Fixes #10970 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent de65924 commit ad27d0e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

subsys/net/ip/icmpv6.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static enum net_verdict handle_echo_request(struct net_pkt *orig)
295295
struct net_pkt *pkt;
296296
struct net_buf *frag;
297297
struct net_if *iface;
298-
u16_t payload_len;
298+
s16_t payload_len;
299299
int ret;
300300

301301
NET_DBG("Received Echo Request from %s to %s",
@@ -304,13 +304,18 @@ static enum net_verdict handle_echo_request(struct net_pkt *orig)
304304

305305
iface = net_pkt_iface(orig);
306306

307+
payload_len = ntohs(NET_IPV6_HDR(orig)->len) -
308+
net_pkt_ipv6_ext_len(orig) - NET_ICMPH_LEN;
309+
if (payload_len < NET_ICMPV6_UNUSED_LEN) {
310+
/* No identifier or sequence number present */
311+
goto drop_no_pkt;
312+
}
313+
307314
pkt = net_pkt_get_reserve_tx(0, PKT_WAIT_TIME);
308315
if (!pkt) {
309316
goto drop_no_pkt;
310317
}
311318

312-
payload_len = ntohs(NET_IPV6_HDR(orig)->len) - sizeof(NET_ICMPH_LEN) -
313-
NET_ICMPV6_UNUSED_LEN;
314319
frag = net_pkt_copy_all(orig, 0, PKT_WAIT_TIME);
315320
if (!frag) {
316321
goto drop;

0 commit comments

Comments
 (0)