Skip to content

Commit 4d0cf30

Browse files
committed
Reject short IP lengths in ESP wrap
F/791
1 parent 5e271ef commit 4d0cf30

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/test/unit/unit_esp.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,32 @@ START_TEST(test_wrap_no_matching_sa)
12101210
}
12111211
END_TEST
12121212

1213+
START_TEST(test_wrap_rejects_ip_len_below_header)
1214+
{
1215+
static uint8_t buf[70000];
1216+
struct wolfIP_ip_packet *ip = (struct wolfIP_ip_packet *)buf;
1217+
uint16_t ip_len = (uint16_t)(IP_HEADER_LEN - 1U);
1218+
int ret;
1219+
1220+
memset(buf, 0, sizeof(buf));
1221+
esp_setup();
1222+
1223+
ret = wolfIP_esp_sa_new_hmac(0, (uint8_t *)spi_rt,
1224+
atoip4(T_SRC), atoip4(T_DST),
1225+
ESP_AUTH_SHA256_RFC4868, k_auth16, sizeof(k_auth16),
1226+
ESP_ICVLEN_HMAC_128);
1227+
ck_assert_int_eq(ret, 0);
1228+
1229+
ip->dst = ee32(atoip4(T_DST));
1230+
ip->src = ee32(atoip4(T_SRC));
1231+
ip->proto = WI_IPPROTO_UDP;
1232+
ip->len = ee16(ip_len);
1233+
1234+
ret = esp_transport_wrap(ip, &ip_len);
1235+
ck_assert_int_eq(ret, -1);
1236+
}
1237+
END_TEST
1238+
12131239
static Suite *esp_suite(void)
12141240
{
12151241
Suite *s;
@@ -1283,6 +1309,7 @@ static Suite *esp_suite(void)
12831309
/* No-SA outbound path */
12841310
tc = tcase_create("no_sa");
12851311
tcase_add_test(tc, test_wrap_no_matching_sa);
1312+
tcase_add_test(tc, test_wrap_rejects_ip_len_below_header);
12861313
suite_add_tcase(s, tc);
12871314

12881315
return s;

src/wolfesp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,11 @@ esp_transport_wrap(struct wolfIP_ip_packet *ip, uint16_t * ip_len)
14771477
wolfIP_esp_sa * esp_sa = NULL;
14781478
uint8_t iv_len = 0;
14791479

1480+
if (orig_ip_len < IP_HEADER_LEN) {
1481+
ESP_LOG("error: ip_len below header: %u\n", orig_ip_len);
1482+
return -1;
1483+
}
1484+
14801485
/* todo: priority, proto / port filtering. currently this grabs
14811486
* the first dst match. */
14821487
for (size_t i = 0; i < out_sa_num; ++i) {

0 commit comments

Comments
 (0)