Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] xsk: handle two header issues
@ 2026-11-27 10:53 Jason Xing
  2026-11-27 10:53 ` [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit() Jason Xing
  2026-11-27 10:53 ` [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload Jason Xing
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Xing @ 2026-11-27 10:53 UTC (permalink / raw)
  To: willemb, magnus.karlsson, maciej.fijalkowski, sdf, bjorn, davem,
	edumazet, kuba, pabeni, horms
  Cc: netdev, bpf, Jason Xing

Cover more potential mac_headers cases in __dev_direct_xmit, including
xsk.

Initialize the metadata of headers in xsk.

---
V2
Link: https://lore.kernel.org/all/20261124083520.45547-1-kerneljasonxing@gmail.com/
1. address issues reported by sashiko
2. introduce 0001 patch to prevent the changes from 0002 casuing ICE
unintended buggy behavior because of using mac_header in ICE.

Jason Xing (2):
  net: reset the mac header in __dev_direct_xmit()
  xsk: fill in header offsets for TX checksum offload

 net/core/dev.c |  2 ++
 net/xdp/xsk.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)

-- 
2.43.7


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit()
  2026-11-27 10:53 [PATCH net v2 0/2] xsk: handle two header issues Jason Xing
@ 2026-11-27 10:53 ` Jason Xing
  2026-11-27 10:53 ` [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload Jason Xing
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Xing @ 2026-11-27 10:53 UTC (permalink / raw)
  To: willemb, magnus.karlsson, maciej.fijalkowski, sdf, bjorn, davem,
	edumazet, kuba, pabeni, horms
  Cc: netdev, bpf, Jason Xing, stable, Petr Oros

Compared to __dev_queue_xmit(), __dev_direct_xmit() is the only open
gate for skbs whose mac_header might not be initialized. A few months
ago commit c2707480cfbf ("net/packet: reset the MAC header on the
packet-socket transmit path") solves the case where AF_PACKET skb can
miss resetting mac header if a few conditions in packet_parse_headers()
are not satisified and it will cause out-of-bounds access.

Similarly, Petr reported an issue about AF_XDP path where copy mode
can also trigger the uninitialized mac header problem.

In reply to Petr's patch, Eric suggested to add the reset logic in a
general layer to stop future issues like this happening instead of
dealing with scattered cases one by one[1]. So anchor the mac header in
__dev_direct_xmit() exactly as __dev_queue_xmit() does, before
validate_xmit_skb_list() so that ndo_features_check() and the vlan helpers
see it too.

For callers that already reset the header the operation is idempotent.

[1]: https://lore.kernel.org/all/CANn89i+aacS2PfaMXnimzGgbCLz-JSnqo6QyoS122Gf+kxya3w@mail.gmail.com/

Fixes: 35fcde7f8deb ("xsk: support for Tx")
Cc: stable@vger.kernel.org
Reported-by: Petr Oros <poros@redhat.com>
Closes: https://lore.kernel.org/all/20260817153957.3177627-1-poros@redhat.com/
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
1. this patch will be backported to stable branches to fix the xsk problem
   and will also be merged in net-next. In the -next branch, I'm going to
   follow Eric's thoughts to handle the mac_header 'issues' from the driver
   side, and then finally remove the guarantee (reseting mac header in the
   core stack layer) like this patch and that af_packet case.
2. this patch is also a prep for the second patch in the series.
---
 net/core/dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index 3c58db732761..6ea2fd3506f7 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5149,6 +5149,8 @@ int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
 		     !netif_carrier_ok(dev)))
 		goto drop;
 
+	skb_reset_mac_header(skb);
+
 	skb = validate_xmit_skb_list(skb, dev, &again);
 	if (skb != orig_skb)
 		goto drop;
-- 
2.43.7


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload
  2026-11-27 10:53 [PATCH net v2 0/2] xsk: handle two header issues Jason Xing
  2026-11-27 10:53 ` [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit() Jason Xing
@ 2026-11-27 10:53 ` Jason Xing
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Xing @ 2026-11-27 10:53 UTC (permalink / raw)
  To: willemb, magnus.karlsson, maciej.fijalkowski, sdf, bjorn, davem,
	edumazet, kuba, pabeni, horms
  Cc: netdev, bpf, Jason Xing, stable

An XDP_TXMD_FLAGS_CHECKSUM request is turned into an skb carrying
CHECKSUM_PARTIAL by xsk_skb_metadata() where csum_start/csum_offset/
ip_summed are set.

However skb->protocol stays 0, the offload never actually reaches
the hardware and checksum ends up being computed in software every time
(please see skb_checksum_help() in xsk path):
1. harmonize_features() strips the checksum features on devices.
2. ice_features_check() rejects the frame on NETIF_F_HW_CSUM capable ice.

The frame layout comes from user space, and request.csum_start is
already the offset of the L4 header from the start of the frame, so the
transport header is known exactly.

Only the L2 length has to be found, by parsing the Ethernet header and,
when present, the VLAN tag stack. skb_header_pointer() is used for that,
so it works for frames whose data is not in the linear part of the skb.

skb->protocol is set to the outer ethertype, as the rest of the stack does
for in-band VLAN tags, so skb_vlan_tagged() and vlan_features_check()
keep seeing the tags. can_checksum_protocol() and the drivers get the L3
type through vlan_get_protocol(). The mac header is anchored by
__dev_direct_xmit() in the previous patch.

A frame whose L2 header cannot be parsed, whose L3 type is not IPv4 or
IPv6, or whose csum_start does not leave room for an L3 header cannot be
described to the hardware, so it keeps being checksummed in software
exactly as before.

The patch is based on Maciej suggestion: 1) do not rely on mac header that
probe in AF_PACKET uses, 2) use skb_header_pointer and walk vlan tags to
inspect the accurate location of each field that existing drivers
possibly use.

[1]: https://lore.kernel.org/all/arKm5gCaERk6MaGA@boxer/

Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
Cc: stable@vger.kernel.org
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
 net/xdp/xsk.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 52d538160e0a..8f566996a6dd 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -11,8 +11,12 @@
 
 #define pr_fmt(fmt) "AF_XDP: %s: " fmt, __func__
 
+#include <linux/if_arp.h>
+#include <linux/if_vlan.h>
 #include <linux/if_xdp.h>
 #include <linux/init.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/signal.h>
 #include <linux/sched/task.h>
@@ -1027,9 +1031,48 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
 
 static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool)
 {
-	if (unlikely(pool->tx_sw_csum &&
-		     skb->ip_summed == CHECKSUM_PARTIAL))
+	struct ethhdr eth_buf, *eth;
+	int nhoff = ETH_HLEN;
+	unsigned int l3_min;
+	__be16 proto;
+
+	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL))
+		return 0;
+
+	if (unlikely(pool->tx_sw_csum))
+		return skb_checksum_help(skb);
+
+	if (unlikely(skb->dev->type != ARPHRD_ETHER))
+		return 0;
+
+	eth = skb_header_pointer(skb, 0, sizeof(*eth), &eth_buf);
+	if (unlikely(!eth))
+		return skb_checksum_help(skb);
+
+	proto = eth->h_proto;
+	if (eth_type_vlan(proto)) {
+		proto = __vlan_get_protocol(skb, proto, &nhoff);
+		if (unlikely(!proto))
+			return skb_checksum_help(skb);
+	}
+
+	switch (proto) {
+	case htons(ETH_P_IP):
+		l3_min = sizeof(struct iphdr);
+		break;
+	case htons(ETH_P_IPV6):
+		l3_min = sizeof(struct ipv6hdr);
+		break;
+	default:
 		return skb_checksum_help(skb);
+	}
+
+	if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
+		return skb_checksum_help(skb);
+
+	skb->protocol = eth->h_proto;
+	skb_set_network_header(skb, nhoff);
+	skb_set_transport_header(skb, skb_checksum_start_offset(skb));
 
 	return 0;
 }
-- 
2.43.7


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 10:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 10:53 [PATCH net v2 0/2] xsk: handle two header issues Jason Xing
2026-11-27 10:53 ` [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit() Jason Xing
2026-11-27 10:53 ` [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox