2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

datapath-windows: Add validations for IP_HEADER_LEN

Adds validations in OvsGetIp() to make sure the IHL is
within valid bounds. If IHL is invalid, then the packet
is dropped by the callers of this function.

Signed-off-by: Shashank Ram <rams@vmware.com>
Acked-by: Sairam Venugopal <vsairam@vmware.com>
Acked-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Gurucharan Shetty <guru@ovn.org>
This commit is contained in:
Shashank Ram
2017-06-15 15:15:47 -07:00
committed by Gurucharan Shetty
parent 6c6204b678
commit 9d71ade0cf
6 changed files with 24 additions and 3 deletions

View File

@@ -2141,6 +2141,9 @@ OvsExtractLayers(const NET_BUFFER_LIST *packet,
}
}
}
} else {
/* Invalid network header */
return NDIS_STATUS_INVALID_PACKET;
}
} else if (dlType == htons(ETH_TYPE_IPV6)) {
NDIS_STATUS status;
@@ -2360,8 +2363,10 @@ OvsExtractFlow(const NET_BUFFER_LIST *packet,
}
}
} else {
/* Invalid network header */
((UINT64 *)ipKey)[0] = 0;
((UINT64 *)ipKey)[1] = 0;
return NDIS_STATUS_INVALID_PACKET;
}
} else if (flow->l2.dlType == htons(ETH_TYPE_IPV6)) {
NDIS_STATUS status;

View File

@@ -563,6 +563,9 @@ OvsValidateIPChecksum(PNET_BUFFER_LIST curNbl,
if (checksum != hdrChecksum) {
return NDIS_STATUS_FAILURE;
}
} else {
/* Invalid network header */
return NDIS_STATUS_FAILURE;
}
}
return NDIS_STATUS_SUCCESS;

View File

@@ -17,6 +17,8 @@
#ifndef __PACKET_PARSER_H_
#define __PACKET_PARSER_H_ 1
#define MIN_IPV4_HLEN 20
#include "precomp.h"
#include "NetProto.h"
@@ -107,7 +109,12 @@ OvsGetIp(const NET_BUFFER_LIST *packet,
const IPHdr *ip = OvsGetPacketBytes(packet, sizeof *ip, ofs, storage);
if (ip) {
int ipLen = ip->ihl * 4;
if (ipLen >= sizeof *ip && OvsPacketLenNBL(packet) >= ofs + ipLen) {
if (ipLen < MIN_IPV4_HLEN ||
ipLen > MAX_IPV4_HLEN ||
OvsPacketLenNBL(packet) < ofs + ipLen) {
/* IP header is invalid, flag it */
return NULL;
} else {
return ip;
}
}

View File

@@ -1019,7 +1019,7 @@ OvsDecapStt(POVS_SWITCH_CONTEXT switchContext,
innerIpHdr->check = IPChecksum((UINT8 *)innerIpHdr,
innerIpHdr->ihl * 4, 0);
} else {
status = NDIS_STATUS_RESOURCES;
status = NDIS_STATUS_INVALID_PACKET;
goto dropNbl;
}
} else if (layers.isIPv6) {

View File

@@ -465,6 +465,11 @@ OvsExecuteDpIoctl(OvsPacketExecute *execute)
ndisStatus = OvsExtractFlow(pNbl, execute->inPort, &key, &layers,
tempTunKey.tunKey.dst == 0 ? NULL : &tempTunKey.tunKey);
if (ndisStatus != NDIS_STATUS_SUCCESS) {
/* Invalid network header */
goto dropit;
}
ctx = (POVS_BUFFER_CONTEXT)NET_BUFFER_LIST_CONTEXT_DATA_START(pNbl);
ctx->mru = execute->mru;

View File

@@ -489,7 +489,8 @@ OvsSlowPathDecapVxlan(const PNET_BUFFER_LIST packet,
if (nh) {
layers.l4Offset = layers.l3Offset + nh->ihl * 4;
} else {
break;
status = NDIS_STATUS_INVALID_PACKET;
break;
}
/* make sure it's a VXLAN packet */