From: sashiko-bot@kernel.org
To: "Jason Xing" <kerneljasonxing@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net] xsk: fill in header offsets for TX checksum offload
Date: Wed, 25 Nov 2026 08:35:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-232914@kernel.org> (raw)
In-Reply-To: <20261124083520.45547-1-kerneljasonxing@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] xsk: missing skb_reset_mac_header() in xsk_skb_sw_csum()
- [Medium] xsk: xsk_skb_sw_csum() overwrites skb->protocol on VLAN
frames
- [Medium] xsk: insufficient header and protocol validation in
xsk_skb_sw_csum()
--
commit 751e231dd95b04f38f8084599c2e73e9184ffdfe
Author: Jason Xing <kerneljasonxing@gmail.com>
xsk: fill in header offsets for TX checksum offload
This commit parses the Ethernet header and VLAN tag stack in
xsk_skb_sw_csum() to populate skb->protocol, the network header offset,
and the transport header offset for CHECKSUM_PARTIAL frames.
> 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), ð_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: Medium]
Should skb->protocol keep the outer eth->h_proto on VLAN frames instead of
being overwritten with the inner L3 protocol returned by
__vlan_get_protocol()?
AF_XDP TX frames carry VLAN tags in-band in skb->data with
skb_vlan_tag_present(skb) false. When skb->protocol is set to the inner
EtherType, skb_vlan_tagged() and skb_vlan_tagged_multi() return false in
validate_xmit_skb(), which skips the dev->vlan_features intersection in
__netif_skb_features(), bypasses multi-VLAN checksum offload masking in
vlan_features_check(), and breaks driver TX checks such as
ice_tx_prepare_vlan_flags() that test eth_type_vlan(skb->protocol) for
in-band VLAN tags.
> +
> + if (unlikely(skb_checksum_start_offset(skb) < nhoff))
> + return -EINVAL;
[Severity: Medium]
Should this check reject skb_checksum_start_offset(skb) <= nhoff and
verify that the L3 and L4 headers fit within the skb?
Allowing skb_checksum_start_offset(skb) == nhoff sets the network and
transport headers to the same offset (skb_network_header_len(skb) == 0),
which passes ice_features_check() and causes ice_tx_csum() to read the
same offset as both the IP and L4 headers. In addition, because
xsk_skb_metadata() only bounds-checks csum_start + csum_offset + 2 against
desc->len, a short frame with valid csum_start and csum_offset allows
drivers such as ice_tx_csum() and mana_checksum_info() to dereference IP
and TCP header fields past skb->tail. Finally, on IFF_TX_SKB_NO_LINEAR
devices such as virtio_net where xsk_build_skb_zerocopy() leaves
skb_headlen(skb) == 0, setting skb->protocol to an EtherType rejected by
can_checksum_protocol() (such as ETH_P_FCOE) causes harmonize_features()
to strip NETIF_F_CSUM_MASK without linearizing the skb, triggering the
offset >= skb_headlen(skb) WARN_ONCE in skb_checksum_help().
> +
> + skb->protocol = proto;
> + skb_set_network_header(skb, nhoff);
> + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
[Severity: High]
Does xsk_skb_sw_csum() also need to call skb_reset_mac_header(skb)?
Because __xsk_generic_xmit() transmits directly via __dev_direct_xmit(),
nothing resets skb->mac_header from its initial ~0U (0xffff) sentinel.
When a CHECKSUM_PARTIAL frame reaches drivers that compute offsets or read
headers relative to skb->mac_header, such as ice_tx_csum() (which computes
(skb->csum_start - skb->mac_header) / 2 for NETIF_F_HW_CSUM),
fbnic_tx_offloads() (via skb_mac_header_len()), or ice_xmit_frame_ring()
(which dereferences skb_mac_header(skb)), the driver programs a bogus
checksum start offset or reads out of bounds at skb->head + 0xffff.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124083520.45547-1-kerneljasonxing@gmail.com?part=1
next prev parent reply other threads:[~2026-11-25 8:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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:35 ` sashiko-bot [this message]
2026-11-25 8:39 ` netdev-bot+sashiko
2026-11-26 11:01 ` Jason Xing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-232914@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox