Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2324364imm; Mon, 28 May 2018 06:05:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLT5LmBTYPO/WIsVFmHDQzimmkT8z4wdxxse6RxYKCkwYbYpA/0bjXcB1wYd9MJkjM1SD+N X-Received: by 2002:a65:4c4d:: with SMTP id l13-v6mr1816998pgr.211.1527512735779; Mon, 28 May 2018 06:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527512735; cv=none; d=google.com; s=arc-20160816; b=IXl31J35Z8GmfB7fne0Tk1QjNEF2tlHH4Tx4Y3tlx/ca70bZeHA1MWPXe6llKaOhPO 7Zzvzn8JeZPOiNnjharGQyY/7VdmS7XKzGs8JCCbOivymZnVZmT1L/WvoWGgqit/jlqK zZxvE+RYqTK+PjZITRM+wZFWvOW61zSIF57QEmuBNel0yhBpu5ZRhdAMwwH9y67SM/rQ tknnqBR2MIpE+xLtf4Ay3E2S3poL5XABIcuEo2Knluszty+S8Ly/G+ibKuC899psHsFx z8qot8hBnqQDkumSn5Ksgn/YgfGvftg+asI/+FtS0BITOvwOet9tKOb0FyzuB4VzvJI5 Il0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=lwNDosvX1NLyyeZyDwIMXMfgB6k0jn/QL4lKm9Coc4w=; b=IvLZsugtxp1tKB1p009DoGip4V8LREGju0jpsEXtnEltY96piGXdYSmsiKVvNMtJQX zUpP/jAcOX60O3KvEn4am3b1j0cudVHMdUnVXQowyggS/hrQ8Aetvv107KynRNmEZ1g/ az6LFomBgJzF6uAQenBfWyGRssNtwqeMFs75RAQgnslZr1YjEhto37auE64WCtSZ7CBX nH4ltCMjcFBeprTVFWN3ngEaPW3dRddqk3s5f1dGfArEpo+pR8CCTNmR0ftkkHswXH+U r7dD/nA322kLqOWbFiPFdAaB/Y4ZI5XZdnCJKLntfpVgRP1zaPa1g2JLp+ZTVET3EKru rh9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SxQpg68O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10-v6si16895677pgs.598.2018.05.28.06.05.03; Mon, 28 May 2018 06:05:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SxQpg68O; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165135AbeE1NER (ORCPT + 99 others); Mon, 28 May 2018 09:04:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:42138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164043AbeE1Kwx (ORCPT ); Mon, 28 May 2018 06:52:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01A69204EE; Mon, 28 May 2018 10:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504772; bh=kjUoCX3GzV/jUR/bwLTtROez8C0Kd1ywPsBNNaVdbQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SxQpg68On2aCmnzC0Esh57CwG/G6K82rQWsEMY8Y+Q1b52KVaXXh1JhOs5Zvz4Jde ARy6P+urytSqcUUL6Kzbqh60Sh4Jy9IYDK4pAr261VxMrge+24YQ5uNm2iZChx1c8T G3sUyQHvHFnd1EWecN/zGOvJHMXWTG3Ev98Bx7sY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Toshiaki Makita , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 259/496] vlan: Fix out of order vlan headers with reorder header off Date: Mon, 28 May 2018 12:00:44 +0200 Message-Id: <20180528100330.785067771@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Toshiaki Makita [ Upstream commit cbe7128c4b92e2004984f477fd38dfa81662f02e ] With reorder header off, received packets are untagged in skb_vlan_untag() called from within __netif_receive_skb_core(), and later the tag will be inserted back in vlan_do_receive(). This caused out of order vlan headers when we create a vlan device on top of another vlan device, because vlan_do_receive() inserts a tag as the outermost vlan tag. E.g. the outer tag is first removed in skb_vlan_untag() and inserted back in vlan_do_receive(), then the inner tag is next removed and inserted back as the outermost tag. This patch fixes the behaviour by inserting the inner tag at the right position. Signed-off-by: Toshiaki Makita Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/if_vlan.h | 66 ++++++++++++++++++++++++++++++++++++++++-------- net/8021q/vlan_core.c | 4 +- 2 files changed, 57 insertions(+), 13 deletions(-) --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -300,30 +300,34 @@ static inline bool vlan_hw_offload_capab } /** - * __vlan_insert_tag - regular VLAN tag inserting + * __vlan_insert_inner_tag - inner VLAN tag inserting * @skb: skbuff to tag * @vlan_proto: VLAN encapsulation protocol * @vlan_tci: VLAN TCI to insert + * @mac_len: MAC header length including outer vlan headers * - * Inserts the VLAN tag into @skb as part of the payload + * Inserts the VLAN tag into @skb as part of the payload at offset mac_len * Returns error if skb_cow_head failes. * * Does not change skb->protocol so this function can be used during receive. */ -static inline int __vlan_insert_tag(struct sk_buff *skb, - __be16 vlan_proto, u16 vlan_tci) +static inline int __vlan_insert_inner_tag(struct sk_buff *skb, + __be16 vlan_proto, u16 vlan_tci, + unsigned int mac_len) { struct vlan_ethhdr *veth; if (skb_cow_head(skb, VLAN_HLEN) < 0) return -ENOMEM; - veth = skb_push(skb, VLAN_HLEN); + skb_push(skb, VLAN_HLEN); - /* Move the mac addresses to the beginning of the new header. */ - memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN); + /* Move the mac header sans proto to the beginning of the new header. */ + memmove(skb->data, skb->data + VLAN_HLEN, mac_len - ETH_TLEN); skb->mac_header -= VLAN_HLEN; + veth = (struct vlan_ethhdr *)(skb->data + mac_len - ETH_HLEN); + /* first, the ethernet type */ veth->h_vlan_proto = vlan_proto; @@ -334,12 +338,30 @@ static inline int __vlan_insert_tag(stru } /** - * vlan_insert_tag - regular VLAN tag inserting + * __vlan_insert_tag - regular VLAN tag inserting * @skb: skbuff to tag * @vlan_proto: VLAN encapsulation protocol * @vlan_tci: VLAN TCI to insert * * Inserts the VLAN tag into @skb as part of the payload + * Returns error if skb_cow_head failes. + * + * Does not change skb->protocol so this function can be used during receive. + */ +static inline int __vlan_insert_tag(struct sk_buff *skb, + __be16 vlan_proto, u16 vlan_tci) +{ + return __vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, ETH_HLEN); +} + +/** + * vlan_insert_inner_tag - inner VLAN tag inserting + * @skb: skbuff to tag + * @vlan_proto: VLAN encapsulation protocol + * @vlan_tci: VLAN TCI to insert + * @mac_len: MAC header length including outer vlan headers + * + * Inserts the VLAN tag into @skb as part of the payload at offset mac_len * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. * * Following the skb_unshare() example, in case of error, the calling function @@ -347,12 +369,14 @@ static inline int __vlan_insert_tag(stru * * Does not change skb->protocol so this function can be used during receive. */ -static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, - __be16 vlan_proto, u16 vlan_tci) +static inline struct sk_buff *vlan_insert_inner_tag(struct sk_buff *skb, + __be16 vlan_proto, + u16 vlan_tci, + unsigned int mac_len) { int err; - err = __vlan_insert_tag(skb, vlan_proto, vlan_tci); + err = __vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, mac_len); if (err) { dev_kfree_skb_any(skb); return NULL; @@ -361,6 +385,26 @@ static inline struct sk_buff *vlan_inser } /** + * vlan_insert_tag - regular VLAN tag inserting + * @skb: skbuff to tag + * @vlan_proto: VLAN encapsulation protocol + * @vlan_tci: VLAN TCI to insert + * + * Inserts the VLAN tag into @skb as part of the payload + * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. + * + * Following the skb_unshare() example, in case of error, the calling function + * doesn't have to worry about freeing the original skb. + * + * Does not change skb->protocol so this function can be used during receive. + */ +static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, + __be16 vlan_proto, u16 vlan_tci) +{ + return vlan_insert_inner_tag(skb, vlan_proto, vlan_tci, ETH_HLEN); +} + +/** * vlan_insert_tag_set_proto - regular VLAN tag inserting * @skb: skbuff to tag * @vlan_proto: VLAN encapsulation protocol --- a/net/8021q/vlan_core.c +++ b/net/8021q/vlan_core.c @@ -48,8 +48,8 @@ bool vlan_do_receive(struct sk_buff **sk * original position later */ skb_push(skb, offset); - skb = *skbp = vlan_insert_tag(skb, skb->vlan_proto, - skb->vlan_tci); + skb = *skbp = vlan_insert_inner_tag(skb, skb->vlan_proto, + skb->vlan_tci, skb->mac_len); if (!skb) return false; skb_pull(skb, offset + VLAN_HLEN);