From: Jason Xing <kerneljasonxing@gmail.com>
To: willemb@google.com, magnus.karlsson@intel.com,
maciej.fijalkowski@intel.com, sdf@fomichev.me, bjorn@kernel.org,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Jason Xing <kerneljasonxing@gmail.com>,
stable@vger.kernel.org, Petr Oros <poros@redhat.com>
Subject: [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit()
Date: Fri, 27 Nov 2026 18:53:46 +0800 [thread overview]
Message-ID: <20261127105347.72997-2-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20261127105347.72997-1-kerneljasonxing@gmail.com>
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>
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
next prev parent reply other threads:[~2026-11-27 10:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:53 [PATCH net v2 0/2] xsk: handle two header issues Jason Xing
2026-11-27 10:53 ` Jason Xing [this message]
2026-11-27 14:38 ` [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit() Björn Töpel
2026-11-27 10:53 ` [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload Jason Xing
2026-11-27 16:40 ` Björn Töpel
2026-11-29 9:10 ` Jason Xing
2026-11-28 10:54 ` sashiko-bot
2026-11-28 11:47 ` netdev-bot+sashiko
2026-11-29 11:13 ` 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=20261127105347.72997-2-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=poros@redhat.com \
--cc=sdf@fomichev.me \
--cc=stable@vger.kernel.org \
--cc=willemb@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.