Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2513932imm; Mon, 28 May 2018 09:30:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoBrOpjtCcfwtxx0tEhujW2ch3GUFLdyh1L/F6IxI19AqkZNOnyo7cf3FlOoIFEfzbkGQwa X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr14186019plt.126.1527525048834; Mon, 28 May 2018 09:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527525048; cv=none; d=google.com; s=arc-20160816; b=DGjusu1iItCnmbsAQ8whgDlfV2zLHQb+RfwA78GGxiOZLUkRVdo+cCvI/47ent/H7i /yajVVxFaNBL5S5pUc9QBl/eRh4ENd5DncYKFr28KXQCaOFciS3iWVFSwxrIRf1+wUdo cRTxdxnlggLwIZMam3zi5/OecoEBWSY7qPndy8RJ5SdaXQow/Smu63+KVT12fbhKfry7 A7R+sar6Bgte4zfLf6IvDDA9dPM1F2YhmZo2yxsODYILtqhhsC4VN5E7/5Ltbv4AtVAk e896CJohwoCp5XjHNiqdNPEdQ0aKkRD0Ac1IFpqDVU99EqvZUhJY/uhb4ijb6L6ZeoIE Mb6Q== 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=YcmWzImL5vFAcmyKtN17dZ33K4nkIBrsHqLH3aFuMmg=; b=PltsGrMC2l1fzZnMIeRwKklLzienFZFSlZZUZFK86OBAq4vE7GZLkUwocUa9aD/lTv h8KQad/Z1f5lwBLXLlbYx4vGUDmzuAo9Yvim4+S4DvWz+IyH0W/uPthYVRpUFp1CpTDo I+IEilsWXF5DOvz495rLbCjDw6YKydyeTqy6EtNDAzLGyc2bnmycaeG8Eop584V0mpYg wGcG4pNhKlBmtQdmxJInvg/XWqXNbpjnxGY1kM3k1rJFCvSTJtDJyQx6R8nmuilFFVSC DJ+OtDVUtDqsgrQmw8NGCRzYoHt4r7ur9AD7hdw7G1V6YE4+lE/Z5vmhDpQC0Qoahowp /Ldg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yOcEV9Q7; 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 u6-v6si30347194plm.99.2018.05.28.09.30.34; Mon, 28 May 2018 09:30:48 -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=yOcEV9Q7; 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 S1425432AbeE1QaK (ORCPT + 99 others); Mon, 28 May 2018 12:30:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:57936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935748AbeE1KJs (ORCPT ); Mon, 28 May 2018 06:09:48 -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 D07642086D; Mon, 28 May 2018 10:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502188; bh=QMRsGr6UQsi6O8nfMKXOuqgxnlLAKJBQjxmq1XbGUug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yOcEV9Q77gIZKQGMEkZSIKeUrulw2xepPBWn12b+0BfIoKijBUNf3G9vw3gtHZhzr EWlmizwaakd93z64q46uRsibziDhMsMZENo+tjWrL4NkvOEy6R8gKdXgwhaXfTjwEg NkBVKLcWfh6GRbFliXyn2Nrv+63Vm77hchVK5kbA= 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 3.18 094/185] net: Fix vlan untag for bridge and vlan_dev with reorder_hdr off Date: Mon, 28 May 2018 12:02:15 +0200 Message-Id: <20180528100058.908715810@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@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 3.18-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 @@ -29,6 +29,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 @@ -4129,13 +4129,16 @@ EXPORT_SYMBOL_GPL(skb_gso_transport_segl 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; }