Article View: linux.kernel.netdev
Article #24130[PATCH net v3 1/2] net: reset the mac header in __dev_direct_xmit()
From: 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
Technical Details
Message-ID:
<20261129111056.11124-2-kerneljasonxing@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373462-linux-kernel-netdev=dewy.ruReferences:
<20261129111056.11124-1-kerneljasonxing@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373462-linux-kernel-netdev=dewy.ru
From: kerneljasonxing@gmail.com (Jason Xing)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 1/2] net: reset the mac header in __dev_direct_xmit()
Date: Sun, 29 Nov 2026 19:10:55 +0800
Organization: Usenet Network
Message-ID: <20261129111056.11124-2-kerneljasonxing@gmail.com>
References: <20261129111056.11124-1-kerneljasonxing@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1156649"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Eg+Zs+y/NwhTWsY38Ulr1KstZj8= sha256:D9Ki9dc+q7XWcJU5O+0TweGk1K75ANB7f7ICZ2X9wG4=
sha1:QFbM7b6iZWJ/quiY8eyVNEae0qg= sha256:tIWNn2JZCDRzgMXgQkHKH66VgH5JYbjjVZP11Of5Fnk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id DFC07125F98; Sun, 29 Nov 2026 14:11:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id wG0n483z8klz;
Sun, 29 Nov 2026 14:11:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373462-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 888D9125F94; Sun, 29 Nov 2026 14:11:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 4FE5F601730; Sun, 29 Nov 2026 11:11:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795950674;
b=WoorGLbccXhsuZ+dZIMqP8CZSX59Bgc921MNsbwzHjmb3VT37K1FmfV4c96AXij/6M2g
p8WuoQ0kJOkJfUYJWkclBRjPQfnuDfb2sHXf/PTPp+o/Uun/jsKJ1/tepvvnp5sY8U51x
4+OzjiQPAO+ik57NhoTPyJJF575sL/++rLh6JP364hKCwm0pN+ZIApOm6YG6SD0FZPu2k
gprkoJUh3zWTKYT4UT8vgZ0enkYCLQ74IFEhKj8KMIi+X5Y0TBqo/UNaMeuR91b8dhju/
IsHQY53VScEmH6IbMGlf85CHMlrUoRDAmRQRHq9YXyO73kdU7pt74Eru4OUTxzWRnPw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795950674;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding;
bh=MONZdEku5HVj5ezhmFClOUpIzykrax+77+Z7AM41gMA=;
b=o4E8AouZ9TKwcthrO61IhSlvkqjUpsJ/MGbOAGeMuVX6e5RK/KTAfuHZVs4Zh/EaADuv
trEuvk82gYEhA47xIDaUqZflY85NJFXxaw3qfjkL/NhwyrzU3eepToKAemvwahPuW0ZJM
VKSIpaUwI5RjhOM+w+7IuHNfQ9m7IIWvzdYR6U3RkPkruOzDbh4S3lvwTgOoEvo92ySlT
evH+WWTtpwtvoWAL+TJpA0Yt/ONmU4yB+65RU4HBU7e6hpBEZsVbZzBWJBKV6P/4AM6E0
Umdp5IMOtJxfu1wXj5UHepIwybcoUkHGXBAMQgAyxDGW56supjz2X9PQjxw4ISJndHA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L0tjAngX;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 51BBC606A335;
Sun, 29 Nov 2026 11:11:14 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L0tjAngX
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795950673;
b=NX7gnwYFXQ4Iy9TxrcpsgS1KLRpZLh8wD0xI51WfyYhTdsgtpb12FAvRCuMsOhLK5sw7
kVUQsO6v/bpFrXhfZUSE3J31+D2YYaWbHWWYzPwA3P9T2nBpygh23mAHkfp5WMYRKIr5V
lpu6Znjnen1FxMf08nxSO5f+oYsqqfYrhLDLWlbqBy3W+XMEvoTAppHQn/68CkGoXRPYm
goDsRDtxHRe3Z6GO62i0G6/0UD62wk6bc8RyE28A3WmnnVe7mSnoqODn1vPvL3MK+s8yB
vbtXMwSWBg0Yu+Rlpjq4sCFBJnL45HdN3y1PHCdt+J5NpiNYOV19SFkesulzg5nnpgQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795950673;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Type:Content-Transfer-Encoding;
bh=MONZdEku5HVj5ezhmFClOUpIzykrax+77+Z7AM41gMA=;
b=h3yL0O02vvnq1o76a4zYY2N6C5T6Whads3nALmrmjj0EIAmfqabZ4vd5re07GgkblURT
hizQcV46IUBmKQoW3mc84sKUkvQc69uGktetedFnMfX0OHVPDsgufsLpYerH4wX2w/IaK
pDkfpJUkU2q8fOYTcm98VVt/RQ+ivjEKfT8qcY/lLZUme7z0fv5rvLqlXD61+ZbrPj4Y+
jo8btKFl7fj4NsFt6y5VyMK2xOF9l7HSQ/kWytHceY4izKtvBFNtcwUzC6s8iMn2hxxbV
Lx5c010CPtnSUmZbz5hu4CgvDcc/8hD9ZbTmwyT4QeHCIX+wueNXOyHnFVQBs3CaVtA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L0tjAngX;
arc=none smtp.remote-ip=74.125.82.179
X-Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCCEA606A325
for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 11:11:12 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCCEA606A325
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-385c497bf94so11547512eec.1
for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 03:11:12 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795950672; x=1796555472; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=MONZdEku5HVj5ezhmFClOUpIzykrax+77+Z7AM41gMA=;
b=L0tjAngXfoDXty93k9jqT1wbprKhXSKRdv9rGTGW576uBhEUEejJFziVquRsj9GpQk
UqqxXueffSPc3YoWH4DOVV+pY6aRQFL3LvhMgzJVzQkPU+xWD3UeAjwi1mZrXNv+7S7B
9luIRqXIpaLOgIrQEVqs1Z25Tp+yf92OIiW7mVQJFcru65APpWUGhXi8a681IlkCFpQn
zssL9JB+liKhxxgS6SGCAHO2uo24pSesGaMrJ4cx7msU1tPDui4aRtbDenBodPtOtBcM
hyswQukaYE8EI2neFDapBjlW+kX97PhFMTgVoAwyvSklXT8e+2vp2kY9o0nHDX6Fv+CV
ZLwg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795950672; x=1796555472;
h=content-transfer-encoding:content-type:mime-version:references
:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=MONZdEku5HVj5ezhmFClOUpIzykrax+77+Z7AM41gMA=;
b=LLYWNRJUB3vMsqIMlmswQWEE4Prj2mnm5lHIOGdszE1L3Hq/V3oS3DyG5y+dur3T+D
ug0CNAXqXnwpjuhDFJv9IbruecfemB+AaKyqAHoYDcs9rrJny5NL9s0ezNZsrg+Ipgjh
+hzIIh8e8GQcDaIfJajlJHksOezQ7xKcBJGVd1w6D9cO4XSF0+T2UvOg1A4kXh0jWO/O
6nrAEcgmjhkV5ZMs8GzUGpdObGwHd9L3jteJ/YSC1qGM3he81somnShlnOwS5rT9kMtP
5rMP1j35ZcZRHr2OFkcR5iwiNNTBysPt3R8QfCI042DjZCfMEo+KKpw4zYqyaJond3St
EMig==
X-Gm-Message-State: APuU4Z85PbC00DryZDLwJ9KudPRAbwLZI1QHdSqNTTdxYVtrnOmRRdsu
2hvui9Qgpvo2xMDDyvwjMnILdgjoBYfNv4hb6f3f4bswASO58krvcP7O
X-Gm-Gg: AZFdTZc3DZ9fhAs+r+NCZac3jUz8EqwsvhOH+GP5UXXi+w+69vwKmboiS95ftvWvb10
/stJTnGkPWacob1Fzr7wes8o+E2VZkGDEURVa9AqgtWOLYAXLcaF5qetCAnTzfktt9yYFc7v5kK
AdL45/ZL4jhjHdF7x4ZrhVLqfe8fq7Z6R/kuqdbhTiISO+0ZZnqpsyIIRnjJzsGiYeXLH9j8TQP
fxj/9i1duLW+R3CV4BGX0cPDSlN6Z+s04AQGNAq5iBtrGpOTXc6+A2sDXIItzT+jb12bYdzMEgC
3RpIIQx7VeY9U/LI83pwWLcAzaDLg+ebbgDvrRC+fsOShiHb/URtUEmJwB9G6Q1AgYOxgpaDu56
NEfa+GkWHDc4yYPrt5lQg2Z1Cb2WoGAI/dGD6mFlrE6/ViLSK96lWOoZAO11g9NN3j8ot+bi9Si
TBmz/3oFqp5VzKfFFq7IFlpLeCMJnvBFPJTjiC7/PeqTYmRkOghlcOjHHotEU5BNvk6A6jJEIKc
37jlvLvMYBgemBRQuW+5reZN83WeGXn4pP9fcorD8j0Sqi/+Zv2n3MHQcUgvszrpJdBav3FDTy8
a4kDSqfYPsp5mJnwtVN/yS5lp2Co9bCqBYABOlayAeAQm2BjPHoEL/hNRcfaZNzkn8X9n7KMuqw
B3cYvlvuhfn06ZixJ+pumeT3Kdw2rxBYXN9VMYAMftucs1vtBIOrRjsE7JmiKQA4bCIbzAaquQ6
wr3PV/+6ebFinnaU4Low==
X-Received: by 2002:a05:7301:3a82:b0:374:ea35:9069 with SMTP id 5a478bee46e88-3856fb67380mr27003606eec.39.1795950671923;
Sun, 29 Nov 2026 03:11:11 -0800 (PST)
X-Received: from localhost.localdomain ([38.114.108.154])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567ea2cc5sm81277415eec.29.2026.11.29.03.11.08
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Sun, 29 Nov 2026 03:11:11 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
bpf@vger.kernel.org,
Jason Xing <kerneljasonxing@gmail.com>,
stable@vger.kernel.org,
Petr Oros <poros@redhat.com>
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261129111056.11124-1-kerneljasonxing@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list