diff mbox series

[v1,1/1] helper: chksum: add few guarding conditions

Message ID 1504083607-26833-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/1] helper: chksum: add few guarding conditions | expand

Commit Message

Github ODP bot Aug. 30, 2017, 9 a.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Add few guarding conditions, otherwise bad packet can hang up ODP code.
Noted by one of the corner case tests for IPsec.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 154 (lumag:fix-checksum-2)
 ** https://github.com/Linaro/odp/pull/154
 ** Patch: https://github.com/Linaro/odp/pull/154.patch
 ** Base sha: 7508c5ac906bb7cb1d339b4c5e924f3a18e504ca
 ** Merge commit sha: 1e5007e87de61c85e055ffd04fd343b472a3dfa7
 **/
 helper/include/odp/helper/ip.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h
index e0d5c3bf..fb7e5ddc 100644
--- a/helper/include/odp/helper/ip.h
+++ b/helper/include/odp/helper/ip.h
@@ -100,10 +100,12 @@  static inline int odph_ipv4_csum(odp_packet_t pkt,
 				 odph_ipv4hdr_t *ip,
 				 odp_u16sum_t *chksum)
 {
-	int nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4;
+	unsigned nleft = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4;
 	uint16_t buf[nleft / 2];
 	int res;
 
+	if (odp_unlikely(nleft < sizeof(*ip)))
+		return -1;
 	ip->chksum = 0;
 	memcpy(buf, ip, sizeof(*ip));
 	res = odp_packet_copy_to_mem(pkt, offset + sizeof(*ip),
@@ -135,7 +137,9 @@  static inline int odph_ipv4_csum_valid(odp_packet_t pkt)
 	if (offset == ODP_PACKET_OFFSET_INVALID)
 		return 0;
 
-	odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
+	res = odp_packet_copy_to_mem(pkt, offset, sizeof(odph_ipv4hdr_t), &ip);
+	if (odp_unlikely(res < 0))
+		return 0;
 
 	chksum = ip.chksum;