From patchwork Wed May 15 11:54:22 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: 1935563 X-Patchwork-Delegate: horms@verge.net.au 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=jvSaJ62T; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4VfWqF6hdvz1ymf for ; Wed, 15 May 2024 21:54:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id C007C41A31; Wed, 15 May 2024 11:54:31 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ckUfJExUmVPQ; Wed, 15 May 2024 11:54:30 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 9F8E440232 Authentication-Results: smtp2.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=jvSaJ62T Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 9F8E440232; Wed, 15 May 2024 11:54:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7DCC8C0072; Wed, 15 May 2024 11:54:30 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 50BDBC0037 for ; Wed, 15 May 2024 11:54:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 27FAD81355 for ; Wed, 15 May 2024 11:54:29 +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 rr5HVSAEFPfb for ; Wed, 15 May 2024 11:54:28 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=67.231.148.174; helo=mx0b-0016f401.pphosted.com; envelope-from=prvs=28654af7c1=amitprakashs@marvell.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 6F1C181351 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=marvell.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6F1C181351 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=marvell.com header.i=@marvell.com header.a=rsa-sha256 header.s=pfpt0220 header.b=jvSaJ62T Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6F1C181351 for ; Wed, 15 May 2024 11:54:28 +0000 (UTC) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44F5TKNe031832 for ; Wed, 15 May 2024 04:54:27 -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=D2o3WXHA 4rcvmy31BdPw5ep5xp1hP7YtnTs8LahWagU=; b=jvSaJ62TSRUpDlLyJ2wY3+CH EfPtA+8ttYf7dntz91XtbuybJX0650rs70dcaHhZspVHQGD4VtgOkx0tN1oUBVI7 9WJ3KUtuekTgMqqCM6QopybBTkNXomv7Y/L+2vR9dFW1vpX678iMNFb9cA8tB+J1 vVrZURFFSCTuPRPfSTs1YGgODBc6H9vTfeEGvQJ6CtjZ42sXUO/Wpi4Bzq1jmVqd wFUhHS2QyRHvXzFX3VUBow06iV5bXnHVKS90ZTE+7Q8u8BiSpiPz6WYQZ/logwGn 4sPLzDOpfDrQ5iz50EzIJaddmwP0WhHDY16PMhrsDZ4B04pD/jLbx6Wy2+TuAg== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3y4pxtry3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 May 2024 04:54:27 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.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 04:54:26 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 15 May 2024 04:54:26 -0700 Received: from cavium-OptiPlex-5090-BM14.. (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id 1424C3F704B; Wed, 15 May 2024 04:54:24 -0700 (PDT) From: Amit Prakash Shukla To: Date: Wed, 15 May 2024 17:24:22 +0530 Message-ID: <20240515115422.390780-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: enO_Te30_8HCrdlkq3zn99bf6R7YhQ1E X-Proofpoint-GUID: enO_Te30_8HCrdlkq3zn99bf6R7YhQ1E 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 v3] 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. 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);