Skip to content

Commit 2be9958

Browse files
gasbytesdanielinux
authored andcommitted
validate ip->len covers at least the ip and icmp headers
1 parent 1dc667c commit 2be9958

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/unit/unit.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16700,6 +16700,32 @@ START_TEST(test_regression_udp_inflated_udp_len)
1670016700
}
1670116701
END_TEST
1670216702

16703+
START_TEST(test_regression_icmp_ip_len_below_header)
16704+
{
16705+
struct wolfIP s;
16706+
struct wolfIP_icmp_packet icmp;
16707+
uint32_t frame_len;
16708+
16709+
wolfIP_init(&s);
16710+
mock_link_init(&s);
16711+
s.dhcp_state = DHCP_OFF;
16712+
wolfIP_filter_set_callback(NULL, NULL);
16713+
last_frame_sent_size = 0;
16714+
16715+
memset(&icmp, 0, sizeof(icmp));
16716+
icmp.ip.src = ee32(0x0A000002U);
16717+
icmp.ip.dst = ee32(0x0A000001U);
16718+
icmp.ip.ttl = 64;
16719+
icmp.ip.len = 0;
16720+
icmp.type = ICMP_ECHO_REQUEST;
16721+
frame_len = (uint32_t)(ETH_HEADER_LEN + IP_HEADER_LEN + ICMP_HEADER_LEN);
16722+
16723+
icmp_input(&s, TEST_PRIMARY_IF, (struct wolfIP_ip_packet *)&icmp, frame_len);
16724+
ck_assert_uint_eq(last_frame_sent_size, 0);
16725+
}
16726+
END_TEST
16727+
16728+
1670316729
/* ----------------------------------------------------------------------- */
1670416730

1670516731
Suite *wolf_suite(void)
@@ -17265,6 +17291,7 @@ Suite *wolf_suite(void)
1726517291
tcase_add_test(tc_utils, test_eth_output_add_header_invalid_if);
1726617292
tcase_add_test(tc_utils, test_ip_output_add_header);
1726717293
tcase_add_test(tc_utils, test_ip_output_add_header_icmp);
17294+
tcase_add_test(tc_utils, test_regression_icmp_ip_len_below_header);
1726817295

1726917296
tcase_add_test(tc_wolfssl, test_wolfssl_io_ctx_registers_callbacks);
1727017297
tcase_add_test(tc_wolfssl, test_wolfssl_io_setio_success);

src/wolfip.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,6 +4524,9 @@ static void icmp_input(struct wolfIP *s, unsigned int if_idx, struct wolfIP_ip_p
45244524
/* validate minimum ICMP packet length */
45254525
if (len < sizeof(struct wolfIP_icmp_packet))
45264526
return;
4527+
/* validate ip->len covers at least the IP and ICMP headers */
4528+
if (ee16(ip->len) < IP_HEADER_LEN + ICMP_HEADER_LEN)
4529+
return;
45274530
/* validate ip->len doesn't exceed actual received data */
45284531
if (len < (uint32_t)(ETH_HEADER_LEN + ee16(ip->len)))
45294532
return;

0 commit comments

Comments
 (0)