Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2203751imm; Mon, 28 May 2018 03:53:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoYk+qehMNxPOKc+Wqv4twAfDMbtySVoZplLgFyP3yBJO3LWh3ULp4Nw+2PGmD7nBKN5e2H X-Received: by 2002:a17:902:4081:: with SMTP id c1-v6mr13099891pld.60.1527504816836; Mon, 28 May 2018 03:53:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527504816; cv=none; d=google.com; s=arc-20160816; b=Ykijt4UO6RARS3Zge8RlvDVfAKJcavy+3ZMEdTfJ7CxgoiHPXZNxIWiHIHd32+jexW fvlxUAgkBneuVbw1www/1yBS01GIUlJEOv6QKhR659oynXULdGtDIUbHl+flaqilFcTP lbnt2nKbpTEroVlLsNnYneDd4pLGXlct0fpPjBrB37IUrSwEh8XVIprx6lSCiVXgTF2W b5scAym37ZQcI+JPhWe2dc5JC0qRsf7fQKZ8sXkSY8Q3cFyiNwLtoT9Fjf4qrKuMwg0v Btdv9XLZp7hYdrcjGB/jfbsxgz6Kj8kp6wiqAuIn6GUqpztF/xxgOh7qHVokZukt/Ueu b5yA== 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=mSGImSwSXy1FI3YGmrXP7z3Q5sg4VQVzn/41yjiBLVk=; b=KJVbDG5VmVYT4ukJ3Y4sw8o31GyGBAYcn/h5xj1dCfOCUaFprjlTYbf/BRwH4bhpHZ VqxmpTGGHANTz0V1avgqDnvPUcQkT9ikHzSaW3sh5UkIT8g6VfMo+Etx7GtgYsrgsW4l 7Z7NmTX7QftXtwa2ZLDl5TOK60quuJ5z1JZfD2ZpfMBV17L7nKgDFLyg5RWCniw6M6Tr HTXKDNkJoX27+cJOPcAYKGTADLKmvxpC4TkHWAdGZJLhO8bfuHfobHifTOn3FfaPCxoV YrkK0zweU9fp+a5KLBQ3vNc6YU6LysIul8W7wa7D0ZaJNeQAZ7fOSpO9GxbuvL50VGod 0Vdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P4zjNvC7; 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 r1-v6si5294341pgu.52.2018.05.28.03.53.22; Mon, 28 May 2018 03:53:36 -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=P4zjNvC7; 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 S1164053AbeE1Kwz (ORCPT + 99 others); Mon, 28 May 2018 06:52:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164027AbeE1Kwt (ORCPT ); Mon, 28 May 2018 06:52:49 -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 D8BFD204EE; Mon, 28 May 2018 10:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504769; bh=xkpxmRQD9ZYK14Ht2tYf6YCj3jEL58m3ktjLY7vnctE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4zjNvC7hTDeKRNjcfgtIDDXmJm94c3QFEsaU9iRgoujHeFAARl8lq6iN7rA6H8pZ lOOdh1kCX2ixlkbrTEYqJ8Tk/AUEfCCWRtu8rn9fVTKiRP67j+W7zQhvWCQbJDn3Ux Q/MfLyFtq+c50Tv6zBfxIBxaUzSLZKEYCTBn0e+Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brandon Carpenter , Toshiaki Makita , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 258/496] net: Fix vlan untag for bridge and vlan_dev with reorder_hdr off Date: Mon, 28 May 2018 12:00:43 +0200 Message-Id: <20180528100330.742832210@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 4bbb3e0e8239f9079bf1fe20b3c0cb598714ae61 ] When we have a bridge with vlan_filtering on and a vlan device on top of it, packets would be corrupted in skb_vlan_untag() called from br_dev_xmit(). The problem sits in skb_reorder_vlan_header() used in skb_vlan_untag(), which makes use of skb->mac_len. In this function mac_len is meant for handling rx path with vlan devices with reorder_header disabled, but in tx path mac_len is typically 0 and cannot be used, which is the problem in this case. The current code even does not properly handle rx path (skb_vlan_untag() called from __netif_receive_skb_core()) with reorder_header off actually. In rx path single tag case, it works as follows: - Before skb_reorder_vlan_header() mac_header data v v +-------------------+-------------+------+---- | ETH | VLAN | ETH | | ADDRS | TPID | TCI | TYPE | +-------------------+-------------+------+---- <-------- mac_len ---------> <-------------> to be removed - After skb_reorder_vlan_header() mac_header data v v +-------------------+------+---- | ETH | ETH | | ADDRS | TYPE | +-------------------+------+---- <-------- mac_len ---------> This is ok, but in rx double tag case, it corrupts packets: - Before skb_reorder_vlan_header() mac_header data v v +-------------------+-------------+-------------+------+---- | ETH | VLAN | VLAN | ETH | | ADDRS | TPID | TCI | TPID | TCI | TYPE | +-------------------+-------------+-------------+------+---- <--------------- mac_len ----------------> <-------------> should be removed <---------------------------> actually will be removed - After skb_reorder_vlan_header() mac_header data v v +-------------------+------+---- | ETH | ETH | | ADDRS | TYPE | +-------------------+------+---- <--------------- mac_len ----------------> So, two of vlan tags are both removed while only inner one should be removed and mac_header (and mac_len) is broken. skb_vlan_untag() is meant for removing the vlan header at (skb->data - 2), so use skb->data and skb->mac_header to calculate the right offset. Reported-by: Brandon Carpenter Fixes: a6e18ff11170 ("vlan: Fix untag operations of stacked vlans with REORDER_HEADER off") Signed-off-by: Toshiaki Makita Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/uapi/linux/if_ether.h | 1 + net/core/skbuff.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) --- a/include/uapi/linux/if_ether.h +++ b/include/uapi/linux/if_ether.h @@ -30,6 +30,7 @@ */ #define ETH_ALEN 6 /* Octets in one ethernet addr */ +#define ETH_TLEN 2 /* Octets in ethernet type field */ #define ETH_HLEN 14 /* Total octets in header. */ #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ #define ETH_DATA_LEN 1500 /* Max. octets in payload */ --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4939,13 +4939,16 @@ EXPORT_SYMBOL_GPL(skb_gso_validate_mtu); static struct sk_buff *skb_reorder_vlan_header(struct sk_buff *skb) { + int mac_len; + if (skb_cow(skb, skb_headroom(skb)) < 0) { kfree_skb(skb); return NULL; } - memmove(skb->data - ETH_HLEN, skb->data - skb->mac_len - VLAN_HLEN, - 2 * ETH_ALEN); + mac_len = skb->data - skb_mac_header(skb); + memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb), + mac_len - VLAN_HLEN - ETH_TLEN); skb->mac_header += VLAN_HLEN; return skb; }