Patch "netkit: Fix pkt_type override upon netkit pass verdict" has been added to the 6.8-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    netkit: Fix pkt_type override upon netkit pass verdict

to the 6.8-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     netkit-fix-pkt_type-override-upon-netkit-pass-verdic.patch
and it can be found in the queue-6.8 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8b4ba7e81807092d25ce35abbe0d4a8f75c3896a
Author: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Date:   Fri May 24 18:36:17 2024 +0200

    netkit: Fix pkt_type override upon netkit pass verdict
    
    [ Upstream commit 3998d184267dfcff858aaa84d3de17429253629d ]
    
    When running Cilium connectivity test suite with netkit in L2 mode, we
    found that compared to tcx a few tests were failing which pushed traffic
    into an L7 proxy sitting in host namespace. The problem in particular is
    around the invocation of eth_type_trans() in netkit.
    
    In case of tcx, this is run before the tcx ingress is triggered inside
    host namespace and thus if the BPF program uses the bpf_skb_change_type()
    helper the newly set type is retained. However, in case of netkit, the
    late eth_type_trans() invocation overrides the earlier decision from the
    BPF program which eventually leads to the test failure.
    
    Instead of eth_type_trans(), split out the relevant parts, meaning, reset
    of mac header and call to eth_skb_pkt_type() before the BPF program is run
    in order to have the same behavior as with tcx, and refactor a small helper
    called eth_skb_pull_mac() which is run in case it's passed up the stack
    where the mac header must be pulled. With this all connectivity tests pass.
    
    Fixes: 35dfaad7188c ("netkit, bpf: Add bpf programmable net device")
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Acked-by: Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240524163619.26001-2-daniel@xxxxxxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c
index c24aa9d93f9f6..5cc794a2a789d 100644
--- a/drivers/net/netkit.c
+++ b/drivers/net/netkit.c
@@ -55,6 +55,7 @@ static void netkit_prep_forward(struct sk_buff *skb, bool xnet)
 	skb_scrub_packet(skb, xnet);
 	skb->priority = 0;
 	nf_skip_egress(skb, true);
+	skb_reset_mac_header(skb);
 }
 
 static struct netkit *netkit_priv(const struct net_device *dev)
@@ -78,6 +79,7 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev)
 		     skb_orphan_frags(skb, GFP_ATOMIC)))
 		goto drop;
 	netkit_prep_forward(skb, !net_eq(dev_net(dev), dev_net(peer)));
+	eth_skb_pkt_type(skb, peer);
 	skb->dev = peer;
 	entry = rcu_dereference(nk->active);
 	if (entry)
@@ -85,7 +87,7 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev)
 	switch (ret) {
 	case NETKIT_NEXT:
 	case NETKIT_PASS:
-		skb->protocol = eth_type_trans(skb, skb->dev);
+		eth_skb_pull_mac(skb);
 		skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
 		if (likely(__netif_rx(skb) == NET_RX_SUCCESS)) {
 			dev_sw_netstats_tx_add(dev, 1, len);
diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 297231854ada5..e44913a8200fd 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -632,6 +632,14 @@ static inline void eth_skb_pkt_type(struct sk_buff *skb,
 	}
 }
 
+static inline struct ethhdr *eth_skb_pull_mac(struct sk_buff *skb)
+{
+	struct ethhdr *eth = (struct ethhdr *)skb->data;
+
+	skb_pull_inline(skb, ETH_HLEN);
+	return eth;
+}
+
 /**
  * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
  * @skb: Buffer to pad
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 049c3adeb8504..4e3651101b866 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -161,9 +161,7 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
 	skb->dev = dev;
 	skb_reset_mac_header(skb);
 
-	eth = (struct ethhdr *)skb->data;
-	skb_pull_inline(skb, ETH_HLEN);
-
+	eth = eth_skb_pull_mac(skb);
 	eth_skb_pkt_type(skb, dev);
 
 	/*




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux