From patchwork Wed May 27 14:31:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Rybchenko X-Patchwork-Id: 70651 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 752D3A034E; Wed, 27 May 2020 16:32:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6DEB01DA61; Wed, 27 May 2020 16:32:17 +0200 (CEST) Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [148.163.129.52]) by dpdk.org (Postfix) with ESMTP id A12101DA59 for ; Wed, 27 May 2020 16:32:16 +0200 (CEST) Received: from mx1-us1.ppe-hosted.com (unknown [10.7.65.62]) by dispatch1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 61677600DD; Wed, 27 May 2020 14:32:15 +0000 (UTC) Received: from us4-mdac16-41.ut7.mdlocal (unknown [10.7.64.23]) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 5DCF38009E; Wed, 27 May 2020 14:32:15 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from mx1-us1.ppe-hosted.com (unknown [10.7.65.176]) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id A861128007E; Wed, 27 May 2020 14:32:14 +0000 (UTC) Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 35C6668009F; Wed, 27 May 2020 14:32:14 +0000 (UTC) Received: from ukex01.SolarFlarecom.com (10.17.10.4) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 27 May 2020 15:31:54 +0100 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 27 May 2020 15:31:54 +0100 Received: from ukv-loginhost.uk.solarflarecom.com (ukv-loginhost.uk.solarflarecom.com [10.17.10.39]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id 04REVsYC000603; Wed, 27 May 2020 15:31:54 +0100 Received: from ukv-loginhost.uk.solarflarecom.com (localhost [127.0.0.1]) by ukv-loginhost.uk.solarflarecom.com (Postfix) with ESMTP id A2C4216139D; Wed, 27 May 2020 15:31:54 +0100 (BST) From: Andrew Rybchenko To: Olivier Matz CC: Date: Wed, 27 May 2020 15:31:41 +0100 Message-ID: <1590589902-31034-1-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1020-25444.002 X-TM-AS-Result: No-1.616700-8.000000-10 X-TMASE-MatchedRID: JJf+xfeHh409jVuxXDELzeIfK/Jd5eHmwCPeAlWWDwPiKUaoIhea7WLp IIQT+xIm7UA9VmaR8FqBJ4LDL/uDoyHhSBQfglfsA9lly13c/gHYuVu0X/rOkIvFa5XXUMbGL37 uvhV7k5HrQ2m9ImWJnpq9vx1MlcQ0UKJZlzyOIwiUVJ//9Hqtimf6wD367VgtmoYJX+t4td+jxY yRBa/qJcFwgTvxipFajoczmuoPCq2/hDV1Ro5VjWsoLwwJ4220172ChMr4URETaSvK99pC8T8p1 +A15kS+vhFfn9tfVWH/2vmGsiuTRhi/Jc6LWwHTOoDhZEr9yveF15h6/oibNbKsWJ44GuEGPNxa u39/BitFwHZmk+dWMm4j0wYb2y4WlExlQIQeRG0= X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--1.616700-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1020-25444.002 X-MDID: 1590589935-rn-fr2GyzFtz Subject: [dpdk-dev] [PATCH] ether: check the first segment length on SW VLAN insertion X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" SW VLAN insertion relies on Ethernet addresses location in contigous memory (do not split across mbuf segments). There is no any formal requirements on data location and mbuf structure which guarantee it. So, check it explicitly to avoid corrupted packets if the condition is violated. Typically software VLAN insertion is done on Tx prepare stage and application will get indication that the packet is invalid and cannot be transmitted. Signed-off-by: Andrew Rybchenko Reviewed-by: Ferruh Yigit --- lib/librte_net/rte_ether.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 0ae4e75b6c..d7c076bba8 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -357,6 +357,10 @@ static inline int rte_vlan_insert(struct rte_mbuf **m) if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) return -EINVAL; + /* Can't insert header if the first segment is too short */ + if (rte_pktmbuf_data_len(*m) < 2 * RTE_ETHER_ADDR_LEN) + return -EINVAL; + oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *); nh = (struct rte_ether_hdr *) rte_pktmbuf_prepend(*m, sizeof(struct rte_vlan_hdr));