diff mbox series

[ovs-dev,v4] lib: Assert for incorrect packet.

Message ID 20240515121546.390821-1-amitprakashs@marvell.com
State Accepted
Headers show
Series [ovs-dev,v4] lib: Assert for incorrect 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 15, 2024, 12:15 p.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.

v4:
- Fixed checkpatch warning.

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

Comments

Ilya Maximets May 17, 2024, 3:46 p.m. UTC | #1
On 5/15/24 14:15, Amit Prakash Shukla wrote:
> 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.
> 
> v4:
> - Fixed checkpatch warning.

Thanks!  I added a note to the commit message that the crash was not
related to OVS logic and applied the change.

Best regards, Ilya Maximets.
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);