diff mbox series

[ovs-dev,v3] lib: assert for incorrect packet.

Message ID 20240515115422.390780-1-amitprakashs@marvell.com
State Superseded
Delegated to: Simon Horman
Headers show
Series [ovs-dev,v3] lib: assert for incorrect packet. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Amit Prakash Shukla May 15, 2024, 11:54 a.m. UTC
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 <amitprakashs@marvell.com>
---
v2:
- Added Fixes tag and updated commit message.

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

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

Patch

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);