From patchwork Wed May 15 12:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Prakash Shukla X-Patchwork-Id: 1935567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0220 header.b=BeQRqKyY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VfXJS1WlTz1ymw for ; Wed, 15 May 2024 22:16:24 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 54B0E81EB3; Wed, 15 May 2024 12:16:15 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id lK3aHFrCRAdz; Wed, 15 May 2024 12:16:14 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 4C07F81E50 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0220 header.b=BeQRqKyY Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4C07F81E50; Wed, 15 May 2024 12:16:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 34D0CC0077; Wed, 15 May 2024 12:16:14 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1D0F0C0037 for ; Wed, 15 May 2024 12:16:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0D0A860611 for ; Wed, 15 May 2024 12:16:13 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id p_XJa-U4XpUz for ; Wed, 15 May 2024 12:16:10 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=67.231.156.173; helo=mx0b-0016f401.pphosted.com; envelope-from=prvs=28654af7c1=amitprakashs@marvell.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 0F03F605BE Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=marvell.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 0F03F605BE Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0220 header.b=BeQRqKyY Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by smtp3.osuosl.org (Postfix) with ESMTPS id 0F03F605BE for ; Wed, 15 May 2024 12:16:09 +0000 (UTC) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44F9SDnY014306 for ; Wed, 15 May 2024 05:16:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=pfpt0220; bh=WrdHoNDU ccDiOFpMXiWWNY3RtVa7H6+htoA4FVuYv+0=; b=BeQRqKyY6l75xMOylCkupAya PgSfKN7JBn8sW8coBIjnEZIMDRxE9N/1IwEjc0ZPklqAWQPebvXYXNv1k8ZNzY+A +mG5ZLlrBCG+0dQLFzy/vHnEQxBuhTT6Z6iiApi5vZs8lyecRb28zkD/NwfOYV/7 j/BtgyxDGqrZ+Ky/VRlQj+DGnw3kSeuiTaKPhRLl4BSHRpw+HLdCiCWmFZAVRSma mUlWBptUFpoU1wHZRKMEgz5tO2ZEDplFdrLSstWU1FHkqyj4OFBEEMQiTvCAxVKQ hq9Mk8r5tixF8B7lNcHwKXknUBiT+Gh5LJm6+0I7iw4R48ykEVODZht66pW9qA== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3y3udndr68-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 May 2024 05:16:07 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 15 May 2024 05:15:51 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 15 May 2024 05:15:51 -0700 Received: from cavium-OptiPlex-5090-BM14.. (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id DB0913F704B; Wed, 15 May 2024 05:15:49 -0700 (PDT) From: Amit Prakash Shukla To: Date: Wed, 15 May 2024 17:45:46 +0530 Message-ID: <20240515121546.390821-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 5NDktaKSurzzF5W8eTgF_5sZWiMAulvA X-Proofpoint-GUID: 5NDktaKSurzzF5W8eTgF_5sZWiMAulvA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-15_06,2024-05-15_01,2023-05-22_02 Cc: hkalra@marvell.com, jerinj@marvell.com Subject: [ovs-dev] [PATCH v4] lib: Assert for incorrect packet. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 --- 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);