From patchwork Sat Aug 15 07:29:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 1345416 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=zx2c4.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha1 header.s=mail header.b=jkISz9//; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BTc3Q5vJnz9sTR for ; Sun, 16 Aug 2020 09:29:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728833AbgHOX3x (ORCPT ); Sat, 15 Aug 2020 19:29:53 -0400 Received: from mail.zx2c4.com ([192.95.5.64]:39479 "EHLO mail.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728749AbgHOX3w (ORCPT ); Sat, 15 Aug 2020 19:29:52 -0400 Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 17dbf29d; Sat, 15 Aug 2020 07:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; s=mail; bh=ZIFPDsMaam/KKfRH8s4z6SGuX7w=; b=jkISz9//M14wD6i5jF3L z06/aSM1xT7iqBBx3dLvKjgtn2LPG9fjcA/u9z/jadujcTgp/4wCBqtOXpJ79v5c dlaD9RVc8alTLcJgBrLvuPAq1EHIqG63qXsvSdlVHg6esEXLtXeVoMcaRkenoz1e 0eYdJK/QqYV83Qo61Bqr7cyi0RaXuj0uZIx+z9C1X9kmhsl0Gp1jaFWo9SQ2Mn5G OQj8UDovrYIU4neWq/Auw3t6MY9YbA8hjWkqqGsr1bqLy+SAB8ZQHnonLz2vCVu6 7DXljHGWJETdvpsaqmFK+GeQwGtMqm2irDI7ZxBubzJB4ReprNndQKJgT9B7lNEV yA== Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id b64639ef (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 15 Aug 2020 07:03:58 +0000 (UTC) From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: "Jason A. Donenfeld" , Jesper Dangaard Brouer , "David S . Miller" Subject: [PATCH net] net: xdp: pull ethernet header off packet after computing skb->protocol Date: Sat, 15 Aug 2020 09:29:30 +0200 Message-Id: <20200815072930.4564-1-Jason@zx2c4.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When an XDP program changes the ethernet header protocol field, eth_type_trans is used to recalculate skb->protocol. In order for eth_type_trans to work correctly, the ethernet header must actually be part of the skb data segment, so the code first pushes that onto the head of the skb. However, it subsequently forgets to pull it back off, making the behavior of the passed-on packet inconsistent between the protocol modifying case and the static protocol case. This patch fixes the issue by simply pulling the ethernet header back off of the skb head. Fixes: 297249569932 ("net: fix generic XDP to handle if eth header was mangled") Cc: Jesper Dangaard Brouer Cc: David S. Miller Signed-off-by: Jason A. Donenfeld --- net/core/dev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/dev.c b/net/core/dev.c index 7df6c9617321..151f1651439f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4676,6 +4676,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb, (orig_bcast != is_multicast_ether_addr_64bits(eth->h_dest))) { __skb_push(skb, ETH_HLEN); skb->protocol = eth_type_trans(skb, skb->dev); + __skb_pull(skb, ETH_HLEN); } switch (act) {