Netdev List
 help / color / mirror / Atom feed
* [PATCH net] xsk: fill in header offsets for TX checksum offload
@ 2026-11-24  8:35 Jason Xing
  2026-11-24  8:37 ` netdev-bot+sinfo
  2026-11-25  8:39 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Jason Xing @ 2026-11-24  8:35 UTC (permalink / raw)
  To: magnus.karlsson, maciej.fijalkowski, sdf, 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, which will be handled in the csum offload like
ice_tx_csum(). Drivers like ICE do read network_header/transport_header
fields which actually point to the wrong place, leading to wrong action.

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. Also, initialize skb->protocol
because of some drivers (e.g. mana_start_xmit()) using it.

A frame whose csum_start points into the L2 header disagrees with its
own metadata, so it is rejected and dropped instead of being handed to
the driver with a layout it cannot use.

Only Ethernet framing is parsed while other device types keep existing
behaviour.

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>
---
V1
Previous discussions: https://lore.kernel.org/all/arKm5gCaERk6MaGA@boxer/
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.
---
 net/xdp/xsk.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 52d538160e0a..7c846f02972e 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -11,6 +11,8 @@
 
 #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/sched/mm.h>
@@ -1027,10 +1029,37 @@ 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;
+	__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 -EINVAL;
+
+	proto = eth->h_proto;
+	if (eth_type_vlan(proto)) {
+		proto = __vlan_get_protocol(skb, proto, &nhoff);
+		if (unlikely(!proto))
+			return -EINVAL;
+	}
+
+	if (unlikely(skb_checksum_start_offset(skb) < nhoff))
+		return -EINVAL;
+
+	skb->protocol = 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

* Re: [PATCH net] xsk: fill in header offsets for TX checksum offload
  2026-11-24  8:35 [PATCH net] xsk: fill in header offsets for TX checksum offload Jason Xing
@ 2026-11-24  8:37 ` netdev-bot+sinfo
  2026-11-25  8:39 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-24  8:37 UTC (permalink / raw)
  To: Jason Xing
  Cc: magnus.karlsson, maciej.fijalkowski, sdf, davem, edumazet, kuba,
	pabeni, horms, netdev, bpf, stable

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net] xsk: fill in header offsets for TX checksum offload
  2026-11-24  8:35 [PATCH net] xsk: fill in header offsets for TX checksum offload Jason Xing
  2026-11-24  8:37 ` netdev-bot+sinfo
@ 2026-11-25  8:39 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25  8:39 UTC (permalink / raw)
  To: kerneljasonxing
  Cc: magnus.karlsson, maciej.fijalkowski, sdf, davem, edumazet, kuba,
	pabeni, horms, netdev, bpf, stable

Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] xsk_skb_sw_csum() sets protocol, network_header and
  transport_header but leaves skb->mac_header at the ~0 (0xffff)…
- [Medium] The commit message says ICE (ice_tx_csum) and mana
  (skb->protocol) misbehave on AF_XDP copy-mode checksum requests.
- [Medium] For frames with in-band 802.1Q/802.1AD tags, xsk_skb_sw_csum()
  sets skb->protocol to the innermost ethertype returned by…
- [Low] xsk_skb_sw_csum() adds a rejection that the commit message does
  not mention.
- [Low] The new 'csum_start must not point into the L2 header' rule
  applies in only one configuration: AF_XDP copy mode, without…
- [Low] Before setting skb->protocol to a user-chosen ETH_P_IP/ETH_P_IPV6
  and network_header to nhoff, xsk_skb_sw_csum() only checks…

--

xsk: fill in header offsets for TX checksum offload

This patch makes xsk_skb_sw_csum() parse the Ethernet header and any
in-band VLAN tags of AF_XDP copy-mode frames that request TX checksum
offload. It then sets skb->protocol, the network header and the transport
header. Frames whose csum_start points into the L2 header are rejected
with -EINVAL.

> Drivers like ICE do read network_header/transport_header
> fields which actually point to the wrong place, leading to wrong action.

[ ... ]

> Also, initialize skb->protocol
> because of some drivers (e.g. mana_start_xmit()) using it.

[Severity: Medium]
Could this description be made more accurate? Before this patch, could
ICE or mana ever get a CHECKSUM_PARTIAL skb from this path?

xsk never set skb->protocol, so it stayed 0. On the
__dev_direct_xmit()->validate_xmit_skb()->netif_skb_features() path,
harmonize_features() then cleared the checksum features on any device
without NETIF_F_HW_CSUM:

net/core/dev.c:harmonize_features() {
    ...
	if (skb->ip_summed != CHECKSUM_NONE &&
	    !can_checksum_protocol(features, type)) {
		features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
	}
    ...
}

skb_csum_hwoffload_help() then fell back to skb_checksum_help(), which
computed the checksum correctly in software.

By default ICE only advertises NETIF_F_IP_CSUM, NETIF_F_IPV6_CSUM and
NETIF_F_SCTP_CRC (see ice_set_netdev_features()). On E830 with HW_CSUM
enabled, ice_features_check() still removed the checksum features,
because skb_network_offset() was negative with network_header at 0.

mana only advertises NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM in
mana_probe_port(), so it also always got a software checksum.

So for these devices, doesn't the patch actually turn on hardware TX
checksum offload in AF_XDP copy mode, where the checksum used to be done
in software? The commit message doesn't say this, and the patch is
tagged for stable.

About the transport header: validate_xmit_skb() already sets it from
csum_start before ndo_start_xmit() runs:

net/core/dev.c:validate_xmit_skb() {
    ...
			else
				skb_set_transport_header(skb,
							 skb_checksum_start_offset(skb));
			if (skb_csum_hwoffload_help(skb, features))
    ...
}

So by driver xmit time, only network_header and protocol were wrong. The
new transport header setter still helps ndo_features_check callbacks
such as ice_features_check(), because they run before this point.

> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index ab2e4fa87a4f0..d599fe161857f 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c

[ ... ]

> @@ -1026,10 +1028,37 @@ 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;
> +	__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 -EINVAL;
> +
> +	proto = eth->h_proto;
> +	if (eth_type_vlan(proto)) {
> +		proto = __vlan_get_protocol(skb, proto, &nhoff);
> +		if (unlikely(!proto))
> +			return -EINVAL;

[Severity: Low]
Is this rejection intended for deeply nested tags? __vlan_get_protocol()
also returns 0 when the VLAN_MAX_DEPTH parse limit is hit, i.e. with 8
or more 802.1Q/802.1AD tags:

net/core/skbuff.c:__vlan_get_protocol_offset() {
	unsigned int vlan_depth = skb->mac_len, parse_depth = VLAN_MAX_DEPTH;
    ...
		if (unlikely(!vh || !--parse_depth))
			return (struct vlan_type_depth) { 0 };
    ...
}

When that happens, __xsk_generic_xmit() calls xsk_drop_skb() and the TX
batch fails with EINVAL. This happens even when csum_start is well past
the L2 header. Before the patch these frames were sent, and got a
correct software checksum on non-HW_CSUM devices.

The commit message only talks about rejecting frames whose csum_start
points into the L2 header. Should this case be mentioned too?

Short frames and truncated VLAN headers are rejected too, but there
csum_start does have to point into the L2 header, so the described rule
covers them.

> +	}
> +
> +	if (unlikely(skb_checksum_start_offset(skb) < nhoff))
> +		return -EINVAL;

[Severity: Low]
This check only runs in one configuration: copy mode, without
XDP_UMEM_TX_SW_CSUM, on an ARPHRD_ETHER device.

The same XDP_TXMD_FLAGS_CHECKSUM request is still accepted in these
cases:

  - with tx_sw_csum, because skb_checksum_help() runs first
  - on non-Ethernet devices, because of the early return above
  - in zero-copy mode, where csum_start goes to the driver's
    tmo_request_checksum without any check

Documentation/networking/xsk-tx-metadata.rst just describes csum_start
as the byte offset where checksumming should start. It gives no lower
bound relative to L2 and no error behaviour.

How is user space supposed to know whether such a descriptor will be
sent or fail with EINVAL? Since this change is going to stable, should
the uAPI documentation describe the new constraint?

> +
> +	skb->protocol = proto;

[Severity: Medium]
For frames with in-band VLAN tags, this sets skb->protocol to the
innermost ethertype (e.g. ETH_P_IP), not the outer 802.1Q/802.1AD type.
Doesn't that hide the tags from the core's VLAN-aware feature masking?

include/linux/if_vlan.h:skb_vlan_tagged() {
	if (!skb_vlan_tag_present(skb) &&
	    likely(!eth_type_vlan(skb->protocol)))
		return false;
    ...
}

With the inner protocol here, __netif_skb_features() never intersects
dev->vlan_features. vlan_features_check()->skb_vlan_tagged_multi() also
returns false right away. QinQ frames therefore skip the mask that
limits checksum offload to NETIF_F_HW_CSUM devices.

That mask is used by dflt_features_check() and by drivers like r8169
(rtl8169_features_check() ends with return vlan_features_check(skb,
features)), stmmac, bnxt, bnx2x and mlx4/mlx5.

Before the patch, skb->protocol was 0, so IP_CSUM-only devices got a
software checksum for these frames. Now they get CHECKSUM_PARTIAL
single- and multi-tagged frames that the core normally keeps away from
their hardware. Could that put wrong checksums on the wire?

AF_PACKET does this differently in packet_parse_headers(). It keeps the
outer h_proto in skb->protocol, resets the mac header, and only moves
network_header past the tags:

net/packet/af_packet.c:packet_parse_headers() {
	skb_reset_mac_header(skb);

	if (!skb->protocol && sock->type == SOCK_RAW)
		skb->protocol = dev_parse_header_protocol(skb);
    ...
	if (likely(skb->dev->type == ARPHRD_ETHER) &&
	    eth_type_vlan(skb->protocol) &&
	    vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 0)
		skb_set_network_header(skb, depth);
}

Would setting skb->protocol = eth->h_proto and resetting the mac header
fit better? skb_vlan_tagged_multi() reads skb_vlan_eth_hdr(), which
depends on skb_mac_header().

> +	skb_set_network_header(skb, nhoff);

[Severity: Low]
Should there be a check that an L3 header of type proto fits between
nhoff and csum_start?

The only layout check above is csum_start >= nhoff, and
xsk_skb_metadata() only requires csum_start + csum_offset + 2 <=
desc->len.

Take a 22-byte frame on ICE with h_proto 0x0800, csum_start 14 and
csum_offset 6:

  - ice_features_check() sees network offset 14 and an L3 length of 0,
    and lets the frame through.
  - skb_csum_hwoffload_help() accepts csum_offset 6, which equals
    offsetof(struct udphdr, check).
  - ice_tx_csum() then reads l4_proto = ip.v4->protocol at frame offset
    23. That is past skb->tail, in tailroom that sock_alloc_send_skb()
    does not zero.

That uninitialized byte then picks the L4 type and length written into
the TX descriptor, with an IP length of 0. Before the patch, such frames
got a software checksum.

Would a minimal check help here? For example, require csum_start - nhoff
to be at least sizeof(struct iphdr) or sizeof(struct ipv6hdr), and leave
protocol unset otherwise. That would keep these frames on the old
software checksum path.

> +	skb_set_transport_header(skb, skb_checksum_start_offset(skb));

[Severity: High]
Should the mac header be set here too? skb->mac_header still holds the
~0 sentinel from __finalize_skb_around(), and mac_len is 0. Neither the
xsk TX path nor __dev_direct_xmit() calls skb_reset_mac_header().

With the correct network offset, ice_features_check() now lets these
skbs through for hardware offload. On E830 with NETIF_F_HW_CSUM (GCS)
enabled, ice_tx_csum() computes:

drivers/net/ethernet/intel/ice/ice_txrx.c:ice_tx_csum() {
    ...
		/* Set GCS */
		u16 csum_start = (skb->csum_start - skb->mac_header) / 2;
    ...
}

It then writes this value through FIELD_PREP(ICE_TX_GCS_DESC_START_M,
...), where ICE_TX_GCS_DESC_START_M is GENMASK(7, 0).

For example, take headroom 64 and an IPv4/UDP frame with csum_start 34.
That gives skb->csum_start = 98:

  - (98 - 65535) / 2 = -32718, which is 0x8032 as a u16 and 0x32 after
    the mask.
  - The NIC is then told the checksum starts 100 bytes into the frame
    instead of 34.

Wouldn't that put a corrupted frame on the wire? Before the patch,
ice_features_check() stripped the checksum features and the stack
computed a correct software checksum. That makes this a regression on
the driver the commit message says it fixes.

There is also a related issue that predates this patch.
ice_xmit_frame_ring() reads the mac header for every xsk copy-mode skb
whose priority is not TC_PRIO_CONTROL:

drivers/net/ethernet/intel/ice/ice_txrx.c:ice_xmit_frame_ring() {
    ...
	eth = (struct ethhdr *)skb_mac_header(skb);
    ...
}

With mac_header unset, eth->h_proto is read from skb->head + 0xffff +
12. Resetting the mac header only for CHECKSUM_PARTIAL skbs would not
fully fix that.

Would it help to call skb_reset_mac_header(skb) and set skb->mac_len =
nhoff next to the new header setters? That may be needed for every xsk
generic TX skb on Ethernet devices, not only CHECKSUM_PARTIAL ones.

> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124083520.45547-1-kerneljasonxing%40gmail.com

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

end of thread, other threads:[~2026-11-25  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  8:35 [PATCH net] xsk: fill in header offsets for TX checksum offload Jason Xing
2026-11-24  8:37 ` netdev-bot+sinfo
2026-11-25  8:39 ` netdev-bot+sashiko

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