Subject: [PATCH 14/24] net: xdp: pull ethernet header off packet after computing skb->protocol

From: "Jason A. Donenfeld" <[email-masked]>
Date: Sat, 15 Aug 2020 09:29:30 +0200

[ Upstream commit f8414a8d886b613b90d9fdf7cda6feea313b1069 ]

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 <[email-masked]>
Cc: David S. Miller <[email-masked]>
Signed-off-by: Jason A. Donenfeld <[email-masked]>
Signed-off-by: David S. Miller <[email-masked]>
---
 net/core/dev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 7a774ebf64e2..84f507d9d59e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4671,6 +4671,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) {
-- 
2.26.2