Packet that are not encapsulated but metadata of the packet contains
a offload flag set, will call dp_packet_inner_l4 to get TCP, UDP, SCTP
header pointers. dp_packet_inner_l4 for such packets would return NULL
as the inner offsets by-default are configured as UINT16_MAX. On
derefrencing such pointers, segfault is observed.

Add assert check for packets with incorrect header or incorrect
offload flag set.

Signed-off-by: Amit Prakash Shukla <[email protected]>
---
v2:
- Added Fixes tag and updated commit message.

v3:
- Resolved review comment - added assert.
- Updated patch subject and commit message.

v4:
- Fixed checkpatch warning.

 lib/packets.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/packets.c b/lib/packets.c
index 5803d26f4..ebf516d67 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -2011,6 +2011,9 @@ packet_tcp_complete_csum(struct dp_packet *p, bool inner)
         tcp_sz = dp_packet_l4_size(p);
     }
 
+    ovs_assert(tcp);
+    ovs_assert(ip_hdr);
+
     if (!inner && dp_packet_hwol_is_outer_ipv6(p)) {
         is_v4 = false;
     } else if (!inner && dp_packet_hwol_is_outer_ipv4(p)) {
@@ -2057,6 +2060,9 @@ packet_udp_complete_csum(struct dp_packet *p, bool inner)
         udp_sz = dp_packet_l4_size(p);
     }
 
+    ovs_assert(udp);
+    ovs_assert(ip_hdr);
+
     /* Skip csum calculation if the udp_csum is zero. */
     if (!udp->udp_csum) {
         return;
@@ -2109,6 +2115,8 @@ packet_sctp_complete_csum(struct dp_packet *p, bool inner)
         tp_len = dp_packet_l4_size(p);
     }
 
+    ovs_assert(sh);
+
     put_16aligned_be32(&sh->sctp_csum, 0);
     csum = crc32c((void *) sh, tp_len);
     put_16aligned_be32(&sh->sctp_csum, csum);
-- 
2.34.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to