diff mbox series

[ovs-dev] lib: Fix segfault for tunnel packet.

Message ID 20240503092225.7516-1-amitprakashs@marvell.com
State Superseded
Headers show
Series [ovs-dev] lib: Fix segfault for tunnel packet. | expand

Checks

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

Commit Message

Amit Prakash Shukla May 3, 2024, 9:22 a.m. UTC
Add NULL check to UDP, TCP and SCTP checksum functions. This patch
also adds changes to populate inner_l3_ofs and inner_l4_ofs for the
tunneled packets received from ports other than vport which are
required by the protocol specific checksum function to parse the
headers.

Signed-off-by: Amit Prakash Shukla <amitprakashs@marvell.com>
---
 lib/netdev.c  |  7 +++++++
 lib/packets.c | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/netdev.c b/lib/netdev.c
index f2d921ed6..19bd87ef7 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1032,6 +1032,13 @@  netdev_push_header(const struct netdev *netdev,
                                  netdev_get_name(netdev));
                     continue;
                 }
+                if (packet->l3_ofs != UINT16_MAX) {
+                    packet->inner_l3_ofs = packet->l3_ofs + data->header_len;
+                }
+                if (packet->l4_ofs != UINT16_MAX) {
+                    packet->inner_l4_ofs = packet->l4_ofs + data->header_len;
+                }
+
                 dp_packet_ol_send_prepare(packet, 0);
             }
             netdev->netdev_class->push_header(netdev, packet, data);
diff --git a/lib/packets.c b/lib/packets.c
index 5803d26f4..988c0e41f 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -2011,6 +2011,10 @@  packet_tcp_complete_csum(struct dp_packet *p, bool inner)
         tcp_sz = dp_packet_l4_size(p);
     }
 
+    if (!tcp || !ip_hdr) {
+        return;
+    }
+
     if (!inner && dp_packet_hwol_is_outer_ipv6(p)) {
         is_v4 = false;
     } else if (!inner && dp_packet_hwol_is_outer_ipv4(p)) {
@@ -2058,7 +2062,7 @@  packet_udp_complete_csum(struct dp_packet *p, bool inner)
     }
 
     /* Skip csum calculation if the udp_csum is zero. */
-    if (!udp->udp_csum) {
+    if (!udp || !ip_hdr || !udp->udp_csum) {
         return;
     }
 
@@ -2109,6 +2113,10 @@  packet_sctp_complete_csum(struct dp_packet *p, bool inner)
         tp_len = dp_packet_l4_size(p);
     }
 
+    if (!sh) {
+        return;
+    }
+
     put_16aligned_be32(&sh->sctp_csum, 0);
     csum = crc32c((void *) sh, tp_len);
     put_16aligned_be32(&sh->sctp_csum, csum);