Thread View: linux.kernel.netdev
8 messages
8 total messages
Started by Jason Xing
Sun, 29 Nov 2026 11:10
[PATCH net v3 0/2] xsk: handle two header issues
Author: Jason Xing
Date: Sun, 29 Nov 2026 11:10
Date: Sun, 29 Nov 2026 11:10
29 lines
11409 bytes
11409 bytes
Cover more potential mac_headers cases in __dev_direct_xmit, including xsk. Initialize the metadata of headers in xsk. --- V3 Link: https://lore.kernel.org/all/20261127105347.72997-1-kerneljasonxing@gmail.com/ 1. add Bjorn's R-b tag 2. address Bjorn's and Sashiko's issues - return 0 instead of falling back to software csum which could lead to bad exceptions like skb drop. 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 causing 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 | 51 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) -- 2.43.7
[PATCH net v3 1/2] net: reset the mac header in __dev_direct_xmit()
Author: Jason Xing
Date: Sun, 29 Nov 2026 11:10
Date: Sun, 29 Nov 2026 11:10
55 lines
13132 bytes
13132 bytes
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>
Reviewed-by: Björn Töpel <bjorn@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
[PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: Jason Xing
Date: Sun, 29 Nov 2026 11:10
Date: Sun, 29 Nov 2026 11:10
127 lines
14801 bytes
14801 bytes
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:
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 is left
untouched, so validate_xmit_skb() keeps deciding between hardware offload
and software checksum 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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 47 insertions(+), 4 deletions(-)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 52d538160e0a..58f77af6100d 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>
@@ -1025,12 +1029,51 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
return 0;
}
-static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool)
+static int xsk_skb_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), ð_buf);
+ if (unlikely(!eth))
+ return 0;
+
+ proto = eth->h_proto;
+ if (eth_type_vlan(proto)) {
+ proto = __vlan_get_protocol(skb, proto, &nhoff);
+ if (unlikely(!proto))
+ return 0;
+ }
+
+ 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 0;
+ }
+
+ if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
+ return 0;
+
+ skb->protocol = eth->h_proto;
+ skb_set_network_header(skb, nhoff);
+ skb_set_transport_header(skb, skb_checksum_start_offset(skb));
+
return 0;
}
@@ -1281,7 +1324,7 @@ static int __xsk_generic_xmit(struct sock *sk)
continue;
}
- err = xsk_skb_sw_csum(skb, xs->pool);
+ err = xsk_skb_csum(skb, xs->pool);
if (unlikely(err)) {
xsk_drop_skb(skb);
goto out;
--
2.43.7
Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 11:12
Date: Mon, 30 Nov 2026 11:12
167 lines
13711 bytes
13711 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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).
- [Medium] xsk_skb_csum() (net/xdp/xsk.c:1071-1076) assumes that the
user-supplied csum_start is the L4 header right after the outermost L3…
- [Low] The commit message of "xsk: fill in header offsets for TX
checksum offload" relies on its companion commit "net: reset the mac…
--
xsk: fill in header offsets for TX checksum offload
This commit changes xsk_skb_sw_csum() into xsk_skb_csum(). For
CHECKSUM_PARTIAL skbs built from AF_XDP TX metadata, the new function
parses the Ethernet header and any VLAN tags. It then sets skb->protocol,
the network header and the transport header, so that the checksum
request can be offloaded to hardware.
> 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.
[Severity: Low]
This has no runtime effect in this tree, but could the dependency be
named explicitly? "the previous patch" seems to mean "net: reset the mac
header in __dev_direct_xmit()". That commit has a different Fixes tag
(35fcde7f8deb) and is also Cc stable.
Before this patch, skb->protocol stayed 0 for xsk skbs, so
skb_vlan_tagged_multi() returned early:
include/linux/if_vlan.h:skb_vlan_tagged_multi() {
...
if (likely(!eth_type_vlan(protocol)))
return false;
...
veh = skb_vlan_eth_hdr(skb);
...
}
skb->protocol is now set to ETH_P_8021Q/ETH_P_8021AD for in-band VLAN
frames, so this dereferences skb_mac_header(). That is only valid
because the companion patch calls skb_reset_mac_header() in
__dev_direct_xmit() before validate_xmit_skb_list().
Suppose this patch is backported to stable without the companion. Would
a VLAN-tagged copy-mode frame that requests XDP_TXMD_FLAGS_CHECKSUM then
read through an unset mac header?
Could the companion commit be referenced by subject, or could a stable
dependency annotation be added?
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 18cbd50047d80..ea94ba07db813 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
[ ... ]
> @@ -1026,12 +1030,51 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
[ ... ]
> + 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 0;
> + }
> +
> + if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> + return 0;
> +
> + skb->protocol = eth->h_proto;
> + skb_set_network_header(skb, nhoff);
> + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
[Severity: Medium]
Is a lower bound on csum_start enough here? The commit message says
"request.csum_start is already the offset of the L4 header from the
start of the frame, so the transport header is known exactly". However,
nothing ties csum_start to the real L3 header length or to the L4
protocol in the IP header.
Before this patch skb->protocol was 0. On IP_CSUM/IPV6_CSUM-only devices
the sequence was:
can_checksum_protocol() fails
harmonize_features() strips the checksum features
skb_checksum_help() writes the checksum at csum_start + csum_offset
Now an IPv4 frame keeps NETIF_F_IP_CSUM. In this case
skb_csum_hwoffload_help() only looks at csum_offset:
net/core/dev.c:skb_csum_hwoffload_help() {
...
if (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
if (skb_has_ipv6_extension_hdr(skb))
goto sw_checksum;
switch (skb->csum_offset) {
case offsetof(struct tcphdr, check):
case offsetof(struct udphdr, check):
return 0;
...
}
The catch for tunnels without skb->encapsulation only exists for IPv6.
Drivers whose checksum engines pick the L4 type from the IP header then
ignore csum_offset. For example, ice_tx_csum() on E810 (no ICE_F_GCS)
and i40e_tx_enable_csum() both do:
l4_proto = ip.v4->protocol;
and ice programs IPLEN as (l3_len / 4).
Take Eth/IPv4(proto=UDP)/UDP/IPv4/TCP, where user space asks for the
inner TCP checksum with csum_start=62 and csum_offset=16. The check
above passes (62 >= 14 + 20), and ice programs L4T=UDP with IPLEN=48/4.
The NIC would then write a UDP checksum at 62 + 6 = 68, which is inside
the inner TCP sequence number. The real checksum field at 78 keeps the
pseudo-header seed.
There is a separate case. ice_features_check() only rejects odd network
header lengths:
len = skb_network_header_len(skb);
if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
goto out_rm_features;
A length like 70 (VXLAN inner TCP, 84 - 14) is truncated to 68 in the
dword-granular IPLEN field. The hardware L4 start then no longer matches
csum_start.
Could UDP-encapsulated IPv4 frames that used to get a correct software
checksum now leave the NIC with a corrupted checksum?
Would it be safer to leave the skb untouched unless both of these hold?
csum_start - nhoff equals the real L3 header length (IHL * 4 for IPv4,
40 for IPv6)
the L3 next protocol (TCP/UDP) matches csum_offset
Another option might be to set up the headers only for devices with
NETIF_F_HW_CSUM.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129111056.11124-1-kerneljasonxing%40gmail.com
Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: Björn Töpel
Date: Mon, 30 Nov 2026 19:53
Date: Mon, 30 Nov 2026 19:53
125 lines
11951 bytes
11951 bytes
Jason Xing <kerneljasonxing@gmail.com> writes:
> 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:
> 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 is left
> untouched, so validate_xmit_skb() keeps deciding between hardware offload
> and software checksum 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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 47 insertions(+), 4 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 52d538160e0a..58f77af6100d 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>
> @@ -1025,12 +1029,51 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
> return 0;
> }
>
> -static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool)
> +static int xsk_skb_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), ð_buf);
> + if (unlikely(!eth))
> + return 0;
> +
> + proto = eth->h_proto;
> + if (eth_type_vlan(proto)) {
> + proto = __vlan_get_protocol(skb, proto, &nhoff);
> + if (unlikely(!proto))
> + return 0;
> + }
> +
> + 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 0;
> + }
> +
> + if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> + return 0;
> +
> + skb->protocol = eth->h_proto;
> + skb_set_network_header(skb, nhoff);
> + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
I think you can drop skb_set_transport_header(). The core does it in
validate_xmit_skb().
(Sashiko's medium one is IMO correct...)
Björn
Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: Jason Xing
Date: Tue, 01 Dec 2026 02:56
Date: Tue, 01 Dec 2026 02:56
23 lines
12961 bytes
12961 bytes
On Tue, Dec 1, 2026 at 3:53 AM Björn Töpel <bjorn@kernel.org> wrote: ... > > + skb->protocol = eth->h_proto; > > + skb_set_network_header(skb, nhoff); > > + skb_set_transport_header(skb, skb_checksum_start_offset(skb)); > > I think you can drop skb_set_transport_header(). The core does it in > validate_xmit_skb(). Actually, no. validate_xmit_skb() calls netif_skb_features()->ice_features_check()->skb_network_header_len() (which uses transport_header to compute) first, then skb_set_transport_header(). So if we remove this one, ICE driver will run into trouble. While trying to fix this bug, I found the contract between the core stack and drivers is a bit hard to read. There are so many cases to consider carefully before getting my hands on it. Thanks, Jason
Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: Björn Töpel
Date: Tue, 01 Dec 2026 07:23
Date: Tue, 01 Dec 2026 07:23
22 lines
8631 bytes
8631 bytes
Jason Xing <kerneljasonxing@gmail.com> writes: > On Tue, Dec 1, 2026 at 3:53 AM Björn Töpel <bjorn@kernel.org> wrote: > ... >> > + skb->protocol = eth->h_proto; >> > + skb_set_network_header(skb, nhoff); >> > + skb_set_transport_header(skb, skb_checksum_start_offset(skb)); >> >> I think you can drop skb_set_transport_header(). The core does it in >> validate_xmit_skb(). > > Actually, no. validate_xmit_skb() calls > netif_skb_features()->ice_features_check()->skb_network_header_len() > (which uses transport_header to compute) first, then > skb_set_transport_header(). So if we remove this one, ICE driver will > run into trouble. Ah! Got it, sorry for the noise! Björn
Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Author: Jason Xing
Date: Tue, 01 Dec 2026 07:36
Date: Tue, 01 Dec 2026 07:36
183 lines
19006 bytes
19006 bytes
On Mon, Nov 30, 2026 at 7:12 PM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>
> 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).
>
> - [Medium] xsk_skb_csum() (net/xdp/xsk.c:1071-1076) assumes that the
> user-supplied csum_start is the L4 header right after the outermost L3…
> - [Low] The commit message of "xsk: fill in header offsets for TX
> checksum offload" relies on its companion commit "net: reset the mac…
>
> --
>
> xsk: fill in header offsets for TX checksum offload
>
> This commit changes xsk_skb_sw_csum() into xsk_skb_csum(). For
> CHECKSUM_PARTIAL skbs built from AF_XDP TX metadata, the new function
> parses the Ethernet header and any VLAN tags. It then sets skb->protocol,
> the network header and the transport header, so that the checksum
> request can be offloaded to hardware.
>
> > 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.
>
> [Severity: Low]
> This has no runtime effect in this tree, but could the dependency be
> named explicitly? "the previous patch" seems to mean "net: reset the mac
> header in __dev_direct_xmit()". That commit has a different Fixes tag
> (35fcde7f8deb) and is also Cc stable.
>
> Before this patch, skb->protocol stayed 0 for xsk skbs, so
> skb_vlan_tagged_multi() returned early:
>
> include/linux/if_vlan.h:skb_vlan_tagged_multi() {
> ...
> if (likely(!eth_type_vlan(protocol)))
> return false;
> ...
> veh = skb_vlan_eth_hdr(skb);
> ...
> }
>
> skb->protocol is now set to ETH_P_8021Q/ETH_P_8021AD for in-band VLAN
> frames, so this dereferences skb_mac_header(). That is only valid
> because the companion patch calls skb_reset_mac_header() in
> __dev_direct_xmit() before validate_xmit_skb_list().
>
> Suppose this patch is backported to stable without the companion. Would
> a VLAN-tagged copy-mode frame that requests XDP_TXMD_FLAGS_CHECKSUM then
> read through an unset mac header?
>
> Could the companion commit be referenced by subject, or could a stable
> dependency annotation be added?
>
> > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> > index 18cbd50047d80..ea94ba07db813 100644
> > --- a/net/xdp/xsk.c
> > +++ b/net/xdp/xsk.c
>
> [ ... ]
>
> > @@ -1026,12 +1030,51 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
>
> [ ... ]
>
> > + 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 0;
> > + }
> > +
> > + if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> > + return 0;
> > +
> > + skb->protocol = eth->h_proto;
> > + skb_set_network_header(skb, nhoff);
> > + skb_set_transport_header(skb, skb_checksum_start_offset(skb));
>
> [Severity: Medium]
> Is a lower bound on csum_start enough here? The commit message says
> "request.csum_start is already the offset of the L4 header from the
> start of the frame, so the transport header is known exactly". However,
> nothing ties csum_start to the real L3 header length or to the L4
> protocol in the IP header.
>
> Before this patch skb->protocol was 0. On IP_CSUM/IPV6_CSUM-only devices
> the sequence was:
>
> can_checksum_protocol() fails
> harmonize_features() strips the checksum features
> skb_checksum_help() writes the checksum at csum_start + csum_offset
>
> Now an IPv4 frame keeps NETIF_F_IP_CSUM. In this case
> skb_csum_hwoffload_help() only looks at csum_offset:
>
> net/core/dev.c:skb_csum_hwoffload_help() {
> ...
> if (features & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)) {
> if (skb_has_ipv6_extension_hdr(skb))
> goto sw_checksum;
>
> switch (skb->csum_offset) {
> case offsetof(struct tcphdr, check):
> case offsetof(struct udphdr, check):
> return 0;
> ...
> }
>
> The catch for tunnels without skb->encapsulation only exists for IPv6.
>
> Drivers whose checksum engines pick the L4 type from the IP header then
> ignore csum_offset. For example, ice_tx_csum() on E810 (no ICE_F_GCS)
> and i40e_tx_enable_csum() both do:
>
> l4_proto = ip.v4->protocol;
>
> and ice programs IPLEN as (l3_len / 4).
>
> Take Eth/IPv4(proto=UDP)/UDP/IPv4/TCP, where user space asks for the
> inner TCP checksum with csum_start=62 and csum_offset=16. The check
> above passes (62 >= 14 + 20), and ice programs L4T=UDP with IPLEN=48/4.
>
> The NIC would then write a UDP checksum at 62 + 6 = 68, which is inside
> the inner TCP sequence number. The real checksum field at 78 keeps the
> pseudo-header seed.
>
> There is a separate case. ice_features_check() only rejects odd network
> header lengths:
>
> len = skb_network_header_len(skb);
> if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
> goto out_rm_features;
>
> A length like 70 (VXLAN inner TCP, 84 - 14) is truncated to 68 in the
> dword-granular IPLEN field. The hardware L4 start then no longer matches
> csum_start.
>
> Could UDP-encapsulated IPv4 frames that used to get a correct software
> checksum now leave the NIC with a corrupted checksum?
>
> Would it be safer to leave the skb untouched unless both of these hold?
>
> csum_start - nhoff equals the real L3 header length (IHL * 4 for IPv4,
> 40 for IPv6)
> the L3 next protocol (TCP/UDP) matches csum_offset
In reply to your V2's review, I mistakenly thought this type of packet
would not cause any unexpected damage here. Actually, the encapsulated
packet will compute and write the csum value into the wrong position.
Prior to this, the encapsulated packet always fell back to software
checksum.
I'll add the above checks on top of the current patch then.
IIUC, AF_PACKET has the similar issue.
Thanks,
Jason
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads