Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp37490pja; Fri, 22 Nov 2019 03:08:47 -0800 (PST) X-Google-Smtp-Source: APXvYqz66DKyppvEjJe4C+G2CmuLmzAyEPfNay5yG4QHV0IS1R43jLu59S8WJfw8eN3dSrtbl5cb X-Received: by 2002:a17:906:1c59:: with SMTP id l25mr21172993ejg.98.1574420927094; Fri, 22 Nov 2019 03:08:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574420927; cv=none; d=google.com; s=arc-20160816; b=X1FIrqlhvQMKNxXdHJw5xZ+7Yh/sLYqwx8jFQoUb3cP4P8kslf1OmB3yFD9zDAzB0m khopbLDhm3Nkd9/23xfMbUq/RwnuDyLye66zlRPw/b5mCl3a6Oizxnhd7wfbLTc7Flio OgrtIEKtLjjuVcyKQqNJUnR8P5GojGQBzKNFRrsZS9HuT4wQAj/ZTBFBIG6GnOziYSs5 YLP4XTVdemn9SseuNhRq+eAZb6BOMD6z6OlOAiUvcu6F/HYzYZRUwT8p1iU8B7cBB0Oi ULVslcqaDII1NOXBA64W9XBxxDR2vA9Z6TJEzjbcoHRCQWVl2RgRw3N+91HwpjvPv+pn WZxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ChJT6OvHd7iJp/W6iCKQjChJvovVcOTawfPJTIJezO4=; b=GGPXsYec2Ox5v4i2BModqXkEBwFgHS5FT3H+GjAiFyzWFsLX7qgnKQhufQbRGTUkHf pH0CcYjUecz/cu8MtVMwRYt4g9fSZFZSbP5xs4D2kldaM7apUipWG/+lRKq6s9m7Rczq RKwZzjzgVJbuumyoHlmts81mh0ITP5qbN8jvMh2k/DMJEMdeVW45oLIkV8lu10fmtxzr QqyWejyFpw+FCbOPEguETR6KAsie7anaVJRIYYM6WRCaMnxPtfISz+k+YhWeBRTaRyRE yHww9HLVp+ZM5dbQLmfYYXosAfH15RVDM40yZoTAe4YDuIocdfsYQb4Ja4EzQmqZAHCf a8dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H7gObVwq; 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 be23si4211625edb.103.2019.11.22.03.08.23; Fri, 22 Nov 2019 03:08:47 -0800 (PST) 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=H7gObVwq; 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 S1731115AbfKVLEl (ORCPT + 99 others); Fri, 22 Nov 2019 06:04:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:59798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730950AbfKVLEk (ORCPT ); Fri, 22 Nov 2019 06:04:40 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 4455E2084D; Fri, 22 Nov 2019 11:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574420679; bh=Bb7rzqBJjmBbvr7XAuy08cxKHrBROKdq85oHPWcCyEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7gObVwqSsgOKKeIrBDyO1GqhlwIiIMityrRj21csgSU8z+2/3NGCazgWzPWXdELX hd5geR1/3nJ7LybBqZZpZEWhuUltnW/8eWTajW9gGaPr18D1mRRIlshs1g2hzb0MWm 0GO1hdMWC9+zchP8OaVlNzCQ5Pt7PEnY3O9gQb1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jesper Dangaard Brouer , Alexei Starovoitov , Sasha Levin Subject: [PATCH 4.19 189/220] net: fix generic XDP to handle if eth header was mangled Date: Fri, 22 Nov 2019 11:29:14 +0100 Message-Id: <20191122100927.741135903@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100912.732983531@linuxfoundation.org> References: <20191122100912.732983531@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer [ Upstream commit 2972495699320229b55b8e5065a310be5c81485b ] XDP can modify (and resize) the Ethernet header in the packet. There is a bug in generic-XDP, because skb->protocol and skb->pkt_type are setup before reaching (netif_receive_)generic_xdp. This bug was hit when XDP were popping VLAN headers (changing eth->h_proto), as skb->protocol still contains VLAN-indication (ETH_P_8021Q) causing invocation of skb_vlan_untag(skb), which corrupt the packet (basically popping the VLAN again). This patch catch if XDP changed eth header in such a way, that SKB fields needs to be updated. V2: on request from Song Liu, use ETH_HLEN instead of mac_len, in __skb_push() as eth_type_trans() use ETH_HLEN in paired skb_pull_inline(). Fixes: d445516966dc ("net: xdp: support xdp generic on virtual devices") Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- net/core/dev.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 4a2ee1ce6c024..e96c88b1465d7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4296,6 +4296,9 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb, struct netdev_rx_queue *rxqueue; void *orig_data, *orig_data_end; u32 metalen, act = XDP_DROP; + __be16 orig_eth_type; + struct ethhdr *eth; + bool orig_bcast; int hlen, off; u32 mac_len; @@ -4336,6 +4339,9 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb, xdp->data_hard_start = skb->data - skb_headroom(skb); orig_data_end = xdp->data_end; orig_data = xdp->data; + eth = (struct ethhdr *)xdp->data; + orig_bcast = is_multicast_ether_addr_64bits(eth->h_dest); + orig_eth_type = eth->h_proto; rxqueue = netif_get_rxqueue(skb); xdp->rxq = &rxqueue->xdp_rxq; @@ -4359,6 +4365,14 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb, } + /* check if XDP changed eth hdr such SKB needs update */ + eth = (struct ethhdr *)xdp->data; + if ((orig_eth_type != eth->h_proto) || + (orig_bcast != is_multicast_ether_addr_64bits(eth->h_dest))) { + __skb_push(skb, ETH_HLEN); + skb->protocol = eth_type_trans(skb, skb->dev); + } + switch (act) { case XDP_REDIRECT: case XDP_TX: -- 2.20.1