From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6CB11A04C7; Mon, 14 Sep 2020 15:09:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7EBC72C36; Mon, 14 Sep 2020 15:09:24 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id B55CF2BAB for ; Mon, 14 Sep 2020 15:09:22 +0200 (CEST) IronPort-SDR: jW+vwmPwvjHte9upx4H4flopDL9hVmU+EEk3SMJFJzLMOv7ToBHZPrgvR/Q8cRgX6NKGTruag6 89s0oATfyqHQ== X-IronPort-AV: E=McAfee;i="6000,8403,9743"; a="160006599" X-IronPort-AV: E=Sophos;i="5.76,426,1592895600"; d="scan'208";a="160006599" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 06:09:17 -0700 IronPort-SDR: KNF8YXoTNojJDLY98p+mkBPdktEL1sMDKHIc7ThJmK1J+0qOKmnDTUBXXuW5Le3k15ow8+wanG yRk2oROllVjQ== X-IronPort-AV: E=Sophos;i="5.76,426,1592895600"; d="scan'208";a="507134913" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.213.247.225]) ([10.213.247.225]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 06:09:16 -0700 To: Andrew Rybchenko , Stephen Hemminger Cc: Olivier Matz , dev@dpdk.org References: <1590589902-31034-1-git-send-email-arybchenko@solarflare.com> <20200528224348.261307f7@hermes.lan> From: Ferruh Yigit Message-ID: Date: Mon, 14 Sep 2020 14:09:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [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" On 6/25/2020 1:27 PM, Andrew Rybchenko wrote: > On 5/29/20 8:43 AM, Stephen Hemminger wrote: >> On Wed, 27 May 2020 15:31:41 +0100 >> Andrew Rybchenko wrote: >> >>> 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 >>> --- >>> 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; >> >> Looks good, but you could also make it handle the fragment case with: >> >> diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h >> index 0ae4e75b6c58..4d0e310a4fac 100644 >> --- a/lib/librte_net/rte_ether.h >> +++ b/lib/librte_net/rte_ether.h >> @@ -350,14 +350,18 @@ static inline int rte_vlan_strip(struct rte_mbuf *m) >> */ >> static inline int rte_vlan_insert(struct rte_mbuf **m) >> { >> - struct rte_ether_hdr *oh, *nh; >> + struct rte_ether_hdr *nh, tmp; >> + const struct rte_ether_hdr *oh; >> struct rte_vlan_hdr *vh; >> >> /* Can't insert header if mbuf is shared */ >> if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) >> return -EINVAL; >> >> - oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *); >> + oh = rte_pktmbuf_read(*m, 0, sizeof(*oh), &tmp); >> + if (unlikely(oh == NULL)) >> + return -EINVAL; >> + >> nh = (struct rte_ether_hdr *) >> rte_pktmbuf_prepend(*m, sizeof(struct rte_vlan_hdr)); >> if (nh == NULL) >> > > It is more complicated since memmove() below should be > rewritten in a similar way as rte_pktmbuf_read(), but > write. I'm not sure it worse the effort. > Reviewed-by: Ferruh Yigit Applied to dpdk-next-net/main, thanks.