xsk: reset the mac header in the generic Tx path
Subsystems (4)
PATCH 1/1 xsk: reset the mac header in the generic Tx path
__dev_queue_xmit() resets skb->mac_header, __dev_direct_xmit() does not, so a frame taking the qdisc bypass path reaches ndo_start_xmit() with the sentinel left by __finalize_skb_around() and skb_mac_header() points 65535 bytes past skb->head.
The packet socket reaches it through packet_direct_xmit(), and packet_parse_headers() was taught to anchor the header by commit c2707480cfbf ("net/packet: reset the MAC header on the packet-socket transmit path"). AF_XDP reaches it through __xsk_generic_xmit(), and net/xdp/xsk.c never sets the mac header.
ice reads eth->h_proto through skb_mac_header() on its ordinary Tx path. On an E810 every one of 2817224 AF_XDP frames reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct 0x88b5. An AF_PACKET sender on the same port read 0x88b5 in both runs.
On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90
Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in xsk_skb_init_misc(), which runs once per skb for both build paths. With IFF_TX_SKB_NO_LINEAR the offset still is not a real header, but it stays in bounds and no such driver reads it.
--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)
net/xdp/xsk.c +1 -0
@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);return 0 ; }
Signature · 1 line
2.54.0
Quoted 31 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Quoted 6 lines
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>
net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 13 lines
--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);
That's a good place to do the reset process. I will cook a follow-up patch to reset the network header.
Thanks,
Jason
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix leaves skb->network_header and skb->transport_header uninitialized in generic XDP TX, causing out-of-bounds reads during checksum offload. --
--- Patch [1]: [PATCH net] xsk: reset the mac header in the generic Tx path --- commit 28a4ae00fcc18f8550bef3cea318942f60fe0720
Author: Petr Oros <[email protected]>
xsk: reset the mac header in the generic Tx path
This commit fixes a bug where AF_XDP generic Tx leaves the MAC header uninitialized, leading to out-of-bounds reads in drivers. It sets the MAC header in xsk_skb_init_misc() to ensure the pointer stays in bounds.
net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 9 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);
[Severity: High]
This is a pre-existing issue and was not introduced by the patch under review, but does this incomplete fix leave skb->network_header and skb->transport_header uninitialized?
If a userspace application uses an AF_XDP socket in generic TX mode with the XDP_TXMD_FLAGS_CHECKSUM metadata flag set, xsk_skb_metadata() will set skb->ip_summed = CHECKSUM_PARTIAL without initializing the network or transport headers.
When the packet is passed to a NIC driver (like ice) that processes CHECKSUM_PARTIAL, it reads skb_network_header() and skb_transport_header():
drivers/net/ethernet/intel/ice/ice_txrx.c:ice_tx_csum() {
...
ip.hdr = skb_network_header(skb);
l4.hdr = skb_transport_header(skb);
...
}Because these headers are never initialized, network_header remains 0 (pointing to uninitialized SKB headroom) and transport_header remains ~0U (65535 bytes past skb->head).
Could this lead to out-of-bounds reads when drivers dereference these pointers, requiring us to safely anchor or parse the headers here as well (for example, via skb_probe_transport_header() as was previously done for AF_PACKET)?
Quoted 2 lines
net/xdp/xsk.c +0
-0return 0 ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 46 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +0
-0
net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 4 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);
I don't know, I had at some point the goal of removing our dependency on mac header in ndo_start_xmit(),
as this must be skb->data.
ice could use skb_eth_hdr() instead of eth_hdr() or skb_mac_header() and save few cycles.
Some drivers call skb_reset_mac_header(skb), this is really a mess.
With AI these days, it should not be too hard to completely remove our dependency on mac_header.
Quoted 57 lines · Eric Dumazet
Quoted 46 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +0
-0net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 4 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);I don't know, I had at some point the goal of removing our dependency on mac header in
ndo_start_xmit(),
as this must beskb->data.
Quoted 8 lines
ice could use
skb_eth_hdr()instead ofeth_hdr()orskb_mac_header()and save few cycles.Some drivers call
skb_reset_mac_header(skb), this is really a mess.With AI these days, it should not be too hard to completely remove our dependency on
mac_header.
I saw the status has been changed to 'rejected'. Why is that, I wonder? I think it's just a fix that can be done in xsk like skb_reset_network_header() that I'm going to add.
Your suggestion should target net-next if someone volunteers to implement it?
Thanks,
Jason
Quoted 64 lines · Jason Xing
Quoted 62 lines · Eric Dumazet
Quoted 46 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +0
-0net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 4 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);I don't know, I had at some point the goal of removing our dependency on mac header in
ndo_start_xmit(),
as this must beskb->data.ice could use
skb_eth_hdr()instead ofeth_hdr()orskb_mac_header()and save few cycles.Some drivers call
skb_reset_mac_header(skb), this is really a mess.
Quoted 8 lines
Quoted 3 lines
With AI these days, it should not be too hard to completely remove our dependency on
mac_header.I saw the status has been changed to 'rejected'. Why is that, I wonder? I think it's just a fix that can be done in xsk like
skb_reset_network_header()that I'm going to add.
skb_reset_network_header() is orthogonal.
Patching net/xdp/xsk.c (and follow-up network header resets) only covers one caller while leaving the core issue open.
The discrepancy is that __dev_queue_xmit() unconditionally executes skb_reset_mac_header(skb), whereas __dev_direct_xmit() does not.
As a result, other paths bypassing qdisc hit the exact same out-of-bounds read in ice. For example, AF_PACKET with PACKET_QDISC_BYPASS only resets mac_header in packet_parse_headers() under:
if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) &&
sock->type == SOCK_RAW) {skb_reset_mac_header(skb);
...
}
Any PACKET_QDISC_BYPASS socket using SOCK_DGRAM or SOCK_RAW with an explicit protocol (e.g. ETH_P_IP) sends an skb with mac_header unset (0xffff sentinel) directly into ndo_start_xmit().
If the core stack was expected to guarantee mac_header for direct xmit, that reset belongs in __dev_direct_xmit(), not duplicated in xsk, packet, selftests, etc.
Work in net-next would presumably audit / change all drivers to not rely on mac_header
being set (This I can do when net-next reopens)
Then we can remove skb_reset_mac_header(skb) from __dev_queue_xmit() and __dev_direct_xmit(), and from dpaa_tx() / dpaa_tx_extended()
Quoted 93 lines · Eric Dumazet
Quoted 64 lines · Jason Xing
Quoted 62 lines · Eric Dumazet
Quoted 46 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +0
-0net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 4 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);I don't know, I had at some point the goal of removing our dependency on mac header in
ndo_start_xmit(),
as this must beskb->data.ice could use
skb_eth_hdr()instead ofeth_hdr()orskb_mac_header()and save few cycles.Some drivers call
skb_reset_mac_header(skb), this is really a mess.Quoted 8 lines
Quoted 3 lines
With AI these days, it should not be too hard to completely remove our dependency on
mac_header.I saw the status has been changed to 'rejected'. Why is that, I wonder? I think it's just a fix that can be done in xsk like
skb_reset_network_header()that I'm going to add.
skb_reset_network_header()is orthogonal.Patching
net/xdp/xsk.c(and follow-up network header resets) only covers one caller while leaving the core issue open.The discrepancy is that
__dev_queue_xmit()unconditionally executesskb_reset_mac_header(skb), whereas__dev_direct_xmit()does not.As a result, other paths bypassing qdisc hit the exact same out-of-bounds read in ice. For example,
AF_PACKETwithPACKET_QDISC_BYPASSonly resetsmac_headerinpacket_parse_headers()under:if ((!skb->protocol ||
skb->protocol==htons(ETH_P_ALL)) &&
sock->type==SOCK_RAW) {skb_reset_mac_header(skb);
...
}
Quoted 7 lines
Any
PACKET_QDISC_BYPASSsocket usingSOCK_DGRAMorSOCK_RAWwith an explicit protocol (e.g.ETH_P_IP) sends an skb withmac_headerunset (0xffffsentinel) directly intondo_start_xmit().If the core stack was expected to guarantee
mac_headerfor direct xmit, that reset belongs in__dev_direct_xmit(), not duplicated in xsk, packet, selftests, etc.
Spot on. That's a general approach.
Quoted 7 lines
Work in net-next would presumably audit / change all drivers to not rely on
mac_header
being set (This I can do when net-next reopens)Then we can remove
skb_reset_mac_header(skb)from__dev_queue_xmit()and__dev_direct_xmit(), and fromdpaa_tx()/dpaa_tx_extended()
Thanks, Eric.
But my minor confusion is that the current patch still holds for the older stable kernels, right? So it seems reasonable to accept it in this way since it targets the net branch?
Thanks,
Jason
Poking this thread again.
Quoted 100 lines · Eric Dumazet
Quoted 64 lines · Jason Xing
Quoted 62 lines · Eric Dumazet
Quoted 46 lines · Petr Oros
__dev_queue_xmit()resetsskb->mac_header,__dev_direct_xmit()does not, so a frame taking the qdisc bypass path reachesndo_start_xmit()with the sentinel left by__finalize_skb_around()andskb_mac_header()points 65535 bytes pastskb->head.The packet socket reaches it through
packet_direct_xmit(), andpacket_parse_headers()was taught to anchor the header by commitc2707480cfbf("net/packet: reset the MAC header on the packet-socket transmit path").AF_XDPreaches it through__xsk_generic_xmit(), andnet/xdp/xsk.cnever sets the mac header.ice reads
eth->h_protothroughskb_mac_header()on its ordinary Tx path. On an E810 every one of 2817224AF_XDPframes reached the driver with the sentinel still in place, so the ethertype never came from the frame. With this patch all 5757920 frames of the same test carried the correct0x88b5. AnAF_PACKETsender on the same port read0x88b5in both runs.On a KFENCE kernel that read lands inside the pool and gets reported as a use after free of an unrelated object, 387 times in a 180 s run:
BUG: KFENCE: use-after-free read in ice_xmit_frame_ring+0xddb/0x1650 [ice] ice_xmit_frame_ring+0xddb/0x1650 [ice] __dev_direct_xmit+0x347/0x4d0 __xsk_generic_xmit+0xc13/0x1e70 __xsk_sendmsg.constprop.0.isra.0+0x519/0x640 xsk_sendmsg+0x6c/0x90Rerunning the same reproducer on the same E810 with this patch applied produced no reports and no bad reads.
Anchor the header in
xsk_skb_init_misc(), which runs once per skb for both build paths. WithIFF_TX_SKB_NO_LINEARthe offset still is not a real header, but it stays in bounds and no such driver reads it.Fixes 35fcde7f8deb ("xsk: support for Tx")Signed-off-by Petr Oros <[email protected]>--- net/xdp/xsk.c | 1 + 1 file changed, 1 insertion(+)net/xdp/xsk.c +0
-0net/xdp/xsk.c static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, · line 934
Quoted 4 lines
net/xdp/xsk.c +1
-0@@ -931,6 +931,7 @@ static int xsk_skb_init_misc(struct sk_buff *skb, struct xdp_sock *xs, skb->priority =READ_ONCE (xs->sk.sk_priority); skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +skb_reset_mac_header (skb);I don't know, I had at some point the goal of removing our dependency on mac header in
ndo_start_xmit(),
as this must beskb->data.ice could use
skb_eth_hdr()instead ofeth_hdr()orskb_mac_header()and save few cycles.Some drivers call
skb_reset_mac_header(skb), this is really a mess.Quoted 8 lines
Quoted 3 lines
With AI these days, it should not be too hard to completely remove our dependency on
mac_header.I saw the status has been changed to 'rejected'. Why is that, I wonder? I think it's just a fix that can be done in xsk like
skb_reset_network_header()that I'm going to add.
skb_reset_network_header()is orthogonal.Patching
net/xdp/xsk.c(and follow-up network header resets) only covers one caller while leaving the core issue open.The discrepancy is that
__dev_queue_xmit()unconditionally executesskb_reset_mac_header(skb), whereas__dev_direct_xmit()does not.As a result, other paths bypassing qdisc hit the exact same out-of-bounds read in ice. For example,
AF_PACKETwithPACKET_QDISC_BYPASSonly resetsmac_headerinpacket_parse_headers()under:if ((!skb->protocol ||
skb->protocol==htons(ETH_P_ALL)) &&
sock->type==SOCK_RAW) {skb_reset_mac_header(skb);
...
}Any
PACKET_QDISC_BYPASSsocket usingSOCK_DGRAMorSOCK_RAWwith an explicit protocol (e.g.ETH_P_IP) sends an skb withmac_headerunset (0xffffsentinel) directly intondo_start_xmit().If the core stack was expected to guarantee
mac_headerfor direct xmit, that reset belongs in__dev_direct_xmit(), not duplicated in xsk, packet, selftests, etc.
Quoted 6 lines
Work in net-next would presumably audit / change all drivers to not rely on
mac_header
being set (This I can do when net-next reopens)Then we can remove
skb_reset_mac_header(skb)from__dev_queue_xmit()and__dev_direct_xmit(), and fromdpaa_tx()/dpaa_tx_extended()
To clarify Eric's view: is the proposed TX contract that mac_header need not be initialized on entry to __dev_direct_xmit(), and rely on skb->data is at L2? What about skb->protocol and skb->network_header? For example, netkit L2 resets MAC locally, but relies on the existing protocol for peer RX, and its attached BPF can consume the existing network offset. (We just hit that internally for a packet sent from XSK/skb.)
...checksum-offload checks in __dev_direct_xmit() aside, since TX validation can also consume metadata before ndo_start_xmit().
Björn