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 Closes: https://lore.kernel.org/all/20260817153957.3177627-1-poros@redhat.com/ Suggested-by: Eric Dumazet Reviewed-by: Björn Töpel Signed-off-by: Jason Xing --- 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