Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2329665imm; Thu, 7 Jun 2018 08:53:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJB3Z2CrLoKHE5a07YBLQom7NYECZw8c78tWx5vLR2rs3JUXTqTRJP6Y7HyGfZyKVwgXWoU X-Received: by 2002:a17:902:8a8c:: with SMTP id p12-v6mr2572570plo.94.1528386815928; Thu, 07 Jun 2018 08:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528386815; cv=none; d=google.com; s=arc-20160816; b=BdUIYPNG4GyAUnggNHjGkoo2OeqWarPEmTMZ4ZH5jhsBXjrR1In0bPti3UG9wXS5v7 wRlv4k4BLHndeQpjBwH2dPkxQmBtgDG5taZHnxAxMnCL8DAGuhNV3ArxytLy7D/Ae60K 9U9b+siTZ/wJkY3vQXkVp13lLvoI5RF/q1Fkx3DNdSYwCmE3Xymd6/loxxyo6RytycP7 Bvt5UqKaVzxPQ5yPbsQxX3E3W0jKhdVOp1R2LAJMPStmmsv4ll1lL+yLI2zWy0/vR40D 8KJj5OKJsje5zN4zERAzEimXIpZHrEv9ST0cnSZnA9R0ppuJb+vqqBxNQW+vMP+dzT8y aLaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=IS+pI0NsJiZT08qr2Qth6H+nqbikYlczvQUDXtpYJfw=; b=Wq0cY2ME1a3EI0eITY3THjm2oiDEXOpUAulzqdvQRfEDhInIpInwut+ttDiCU8yG6D 0bOV35bZVNirytlGdZks7zVTmMf3pbQAzkmsdJyncnbGWuArCe8KFens1Rznh1wVNlPj vzLLKfwwPnTTyUGZVsiwUGrKd3USar/h0zp6wRG3o8FRauSusG8yKzptPa9DuBvNvNIz JsES+Y7P0LX8IME51mbJKRBmrtcbSsTHVwg1CafM/Yuy2C8zw5RMM7Gf502vtLN7uHjR pn7/tu1KeoUOM6aYviyT8LX8yM1G1Sk80S0AsfS6OJ8wyk08b12n4JWwANRPakWfelXv k45g== ARC-Authentication-Results: i=1; mx.google.com; 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 k24-v6si28018671pls.330.2018.06.07.08.53.21; Thu, 07 Jun 2018 08:53: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; 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 S934155AbeFGOhs (ORCPT + 99 others); Thu, 7 Jun 2018 10:37:48 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40452 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933532AbeFGOhp (ORCPT ); Thu, 7 Jun 2018 10:37:45 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbP-0005hO-Es; Thu, 07 Jun 2018 15:09:23 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbD-0003GE-6n; Thu, 07 Jun 2018 15:09:11 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Brandon Carpenter" , "Toshiaki Makita" , "David S. Miller" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 366/410] net: Fix vlan untag for bridge and vlan_dev with reorder_hdr off In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Toshiaki Makita commit 4bbb3e0e8239f9079bf1fe20b3c0cb598714ae61 upstream. 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: Ben Hutchings --- 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 @@ -3994,13 +3994,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; }