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 71AFCA00C5; Fri, 29 May 2020 07:44:38 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AC2DD1DC06; Fri, 29 May 2020 07:44:37 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id AE9B81DC05 for ; Fri, 29 May 2020 07:44:35 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id 131so707504pfv.13 for ; Thu, 28 May 2020 22:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5tUZhViQfyvCdTxp8NlImcRu1kICHIRz/6cdg6wZjeU=; b=SrMqKVXpd6KfDLbQRZyfyvLO7i0t9dhWmOmwDl2Uc5VVt3grR/xfMgTc0c3+R8DLoZ M/RX8bomPj0APTps+a/DNY2QJDQFRNeIgpW113GJJDak8jrMGl8vWmcgfm/Gu03+zLi7 y+FN4qZMSgLM5tTP6/SIQnhZNjoHTNjaPMLq2YsDmJKhqqDk0EPVg4Di8dM+m4m2S+TC xqWSbtMak7tlhg3Vut11RQKYS9Rg7ujelGb8i5rKTsEJHpXDSuIYxGEUMd9FKZQPFePz O5O+/cf1hQ+p6YDTFyWhuxXI2PfpoJ8FOQuwMIgCD47L7C+lMEIJP20bGegX3tCTdH35 8Cng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5tUZhViQfyvCdTxp8NlImcRu1kICHIRz/6cdg6wZjeU=; b=dhvXR8sP9a1hBeD00tIzWZUap1IjT9qndkX1dVCbqEGPgd8HMzRunJh7dJkCfxf91C 5kD5VORln7Eowqb1A574ItXVLZ8wGEkikrAJ4fKXvy5+2sio/oEzsy48OFlBdfQMwvgH DBTWwZTzHc8YIiqWc0a7kkIyN9yr8hw/3z8fFZHdoXNfi23AAW1+s0dld2kYficualhk Sqa7uRfJSUH+ypQYvxNQ0f5b0aMjETlJdMhrJNaRJxADzj6daFnpuZUURdRC14zzzfTm y+xiFWYbghihNXw2wHLRobRC17tg+h3SeWi7Cj0zikKZwjdvQNYqHDJoHLwXtUqddrRL eSHQ== X-Gm-Message-State: AOAM533uW7qw7M1g7d7m6+V8/2tB0LdZAhvjE7v4K6P7LeuHKQl72ZB0 qbHY5e2yDZ85+8VscNV/MEk7hA== X-Google-Smtp-Source: ABdhPJyqF/0KvHlAZiEB39fVoXygDtvvMuogoejoXXUAYStJAAKOSQyJtFXNFbUJTePO4qHaOhLzKA== X-Received: by 2002:a65:6790:: with SMTP id e16mr6926072pgr.145.1590731074274; Thu, 28 May 2020 22:44:34 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id m12sm6411085pjs.41.2020.05.28.22.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2020 22:44:33 -0700 (PDT) Date: Thu, 28 May 2020 22:43:48 -0700 From: Stephen Hemminger To: Andrew Rybchenko Cc: Olivier Matz , Message-ID: <20200528224348.261307f7@hermes.lan> In-Reply-To: <1590589902-31034-1-git-send-email-arybchenko@solarflare.com> References: <1590589902-31034-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 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)