QUIC: fix an integer overflow (#1337)

Long standing bug: credits to @lnslbrty for digging into it and to
@aouinizied for the CI improvements
This commit is contained in:
Ivan Nardi
2021-10-11 23:08:10 +02:00
committed by GitHub
parent a8f938f7ac
commit 550e6fe6fc
3 changed files with 17 additions and 12 deletions
+10 -12
View File
@@ -1348,14 +1348,14 @@ static void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
if(prev_offset > offset)
break;
len = offset - prev_offset;
if(tag_offset_start + prev_offset + len > crypto_data_len)
/* Promote to uint64_t to avoid unsigned wrapping */
if((uint64_t)tag_offset_start + prev_offset + len > (uint64_t)crypto_data_len)
break;
#if 0
printf("crypto_data_len %u prev_offset %u offset %u len %d\n",
crypto_data_len, prev_offset, offset, len);
printf("crypto_data_len %u tag_offset_start %u prev_offset %u offset %u len %u\n",
crypto_data_len, tag_offset_start, prev_offset, offset, len);
#endif
if((memcmp(tag, "SNI\0", 4) == 0) &&
(tag_offset_start + prev_offset + len < crypto_data_len)) {
if(memcmp(tag, "SNI\0", 4) == 0) {
sni_len = MIN(len, sizeof(flow->protos.tls_quic_stun.tls_quic.client_requested_server_name) - 1);
memcpy(flow->protos.tls_quic_stun.tls_quic.client_requested_server_name,
&crypto_data[tag_offset_start + prev_offset], sni_len);
@@ -1381,15 +1381,13 @@ static void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
if(memcmp(tag, "UAID", 4) == 0) {
u_int uaid_offset = tag_offset_start + prev_offset;
if((uaid_offset + len) < crypto_data_len) {
NDPI_LOG_DBG2(ndpi_struct, "UA: [%.*s]\n", len, &crypto_data[uaid_offset]);
NDPI_LOG_DBG2(ndpi_struct, "UA: [%.*s]\n", len, &crypto_data[uaid_offset]);
http_process_user_agent(ndpi_struct, flow, &crypto_data[uaid_offset], len); /* http.c */
ua_found = 1;
http_process_user_agent(ndpi_struct, flow, &crypto_data[uaid_offset], len); /* http.c */
ua_found = 1;
if (sni_found)
return;
}
if (sni_found)
return;
}
prev_offset = offset;
Binary file not shown.
@@ -0,0 +1,7 @@
Guessed flow protos: 0
DPI Packets (UDP): 1 (1.00 pkts/flow)
QUIC 1 1280 1
1 UDP 255.255.255.255:8224 -> 255.255.255.32:8224 [proto: 188/QUIC][Encrypted][cat: Web/5][1 pkts/1280 bytes -> 0 pkts/0 bytes][Goodput ratio: 98/0][< 1 sec][Risk: ** Known protocol on non standard port **** SNI TLS extension was missing **][Risk Score: 60][PLAIN TEXT ( )][Plen Bins: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0]