Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796111867; b=MdxKi7omXzg3SpGLETwRIPqrD16JvObGQJOVJKmfrenfCqHkjdHWhG5WroBk08UqhUWI Kx1aLZ2qFcdC8GJsawD+A8i3FbRfQ8PUzTKRYNR+3mjf4B6UN/+djKr3/Xof6VOon5Njh U3FDrVTd2dJT+aeEmF2bqF9ELnx+CJeHPaHt118F+Vd8cAnJRMW7SG4W23Mmj1bnC5x82 uuIMtGJpfulHB66H5wEebgPEzb6F/sGYFF44TuAbxjmEPZ/PFSiDhf5tIk5aiP6G21DXG cQRF9J/jc/Gg+BTc5TL9zq1/ux4Ec6jMrCogw7p0L5ukdTU7cp+FZsCjNcnKRFkgc5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111867; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=YfGRRpi2nqQAkMu12UGLAPWgeUETPnEWZNiiJr2rautzbegT0TY+0+oK3JNEhOlL9p5Q t/wFYKAckHGcoclytxPPgMEFPF0Rp7lXhyBBlEYR9wv2uMbhdGnC5K3ZZj5gSej04UI56 qkoEh1Wdc9MuHCYy4upuqW2X2PvE9frMhwkYRuDRiDZ5j9IbtkkuxrAYNTlr6oeRHRWuR 2ktn7t/j4+1KnXWQl+MRmX7bVi0kxPE6WpmoN/+8Yyzz1vTz/SncU2wD/ji08BBJ9wwsl UNoZgoeSZhuONf9dUKSdWulS7n+8nuuKguPGwRsFSKepjLf9vRLahObDOK4qvHxWcGQ== 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="K0d6/MzD"; arc=none smtp.remote-ip=74.125.82.181 Received: from mail-dy1-f181.google.com (mail-dy1-f181.google.com [74.125.82.181]) (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 0D75F606A31A for ; Tue, 1 Dec 2026 07:57:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0D75F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=K0d6/MzD Received: by mail-dy1-f181.google.com with SMTP id 5a478bee46e88-386cf1041cdso11164659eec.0 for ; Mon, 30 Nov 2026 23:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796111866; x=1796716666; 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=K0d6/MzDiOXdOEcyHhsXEeJ9kOznobJeT7YAqSoEOrSw12Cx3F46XMvHhCwfsyb5fj TIJ4PTrj4y2+76HwaxglPrJVxIPSma08yTP0ILEOgBzLaJYIBuY4D7FvInHQkYswcnc+ lU9ig2WxNx1Xpua/CUWZ+K+Gm7zn4FAY4CAOK0jbbBTNWU3J5tEGPGiP1llQgXicVJFW 4a7h7ZPztg7zwjF87TUq3y86pP+dNJp9sMcAcloahbT9sY5jaz8T24PMLPVdwBsFdTJ2 E9kb4P7dpECPApCAhHRJ0w8NNE/2Az3O5HFDMDtt0a6j2knT4YFfuscMQ+TxHMtAznYm CXRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796111866; x=1796716666; 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=vQzvsl262OP+v4vMOa6HVszK2mApaCwmX3ewUwrq2py19MwNyTQ3Heo/b+at3lNDuW OFVUuhPbeUZHNf6JfqlhutWukRUnpnfl2S9TBVf1GDIYGR1wIUux8wUtVNRiff1hOtcM U5KQeztZuywsMlaG4sgQBIQsiRtz30hHctYLrF2a3ifCpBGBjBTQDktCPN8yNfoQL6en 6m+oi4c8cRk/Y/H2hiAcndUCq9+3px0+TV5xwhhM/zvC4s4k3pRUkoZNKvNzQ9DY+//r Wr+biDdyk3RujCkYbg0XMvsXHv9mmtk3Xc3N78wpIHH2c5FlKw+yKBml25yBcLcAxfY2 is0Q== X-Forwarded-Encrypted: i=1; AL+hErGbC/xy+e34Tn9jtBBw7N3uu/AFY1mxTzziBjb2/RmFQuhyWvrB379rfzXdMxTzPXD6Ixc=@vger.kernel.org X-Gm-Message-State: APuU4Z+jWAeE1HCXtYcQQHzJJxSYJ4tSQZVX0l7pZ58cPzgZ6f/D2L2E 75KRsn2DmD30MRmIk53XxDdtVi4N3sdR0muD1w8wGtnoffHRtm8vV/Wj X-Gm-Gg: AZFdTZde34lkxVCAj9YR/5ixRgXkm1qa2ezZYBfL9lOBwS/4uY5Lvq2pYOxO8cSYY1w 1s7XVqGZqaVIuLGb6VDNClWMkRJr9kWqp9D6ha1O8hSXFXPOBVPUUYZJctWq3FK08KWUJJWZvTC qfmCk5NwCx3q5HG6FAN8W1gLGkSZy1OHEBBZOxUqaP1YCZJCxw4hwHjd3ImzKxOrwURKo2yaKcR z6uuhDggqGX/Nuh7bFMvNCJORhALQKJbTZ+fHXMeJDMBwxTz97mRy0INTS+fx5cn8Y+pN5ApHsy DODTSc9bive1UU4AHIWlhJx3EYTKiBnFnNE3DbFbY/3Qz2iYJVy3UV3F4y2CsDI5l6LEteK8bY+ ulM0ArwfjuqwLeIffJj03eL2cKh5OXul9jOcJ68K4jR5ZVcsCYw4HxgyZYBvoxW/Vh25wcikpD+ 7UQPVheCkat2/XcZfyINxGvsdQsaVsHPy4Lcwb8NPVAcZnz4LF4iWsGBXIK3w79JVrTtd0WZUjw TyaekDCeIwLF8ruAJxZNB/D2kqx021/rhVNtuyGUISoXDuPPPaP+1XsNWXGXhAyIHRtrC3co47r 2qt1vO9lNARKpYUSF0Zh/QMWrcenKeC1O0k1NAZc+y+LlIo1TB1LRd3FaEMG3Ai5Zshd+Aof9Cv gB3LybEOas716nRc1yJPlPWz2mwdNw3os6XAtq/E1uL5wPcWGH5lAIVT6v5m9cfe//w9ocu8L X-Received: by 2002:a05:693c:37c8:b0:386:a0d1:1b41 with SMTP id 5a478bee46e88-386a0d136aemr41166110eec.34.1796111866048; Mon, 30 Nov 2026 23:57:46 -0800 (PST) Received: from localhost.localdomain ([38.114.108.154]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e7f59sm112046693eec.6.2026.11.30.23.57.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 23:57:45 -0800 (PST) From: Jason Xing 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 , stable@vger.kernel.org, Petr Oros Subject: [PATCH net v4 1/2] net: reset the mac header in __dev_direct_xmit() Date: Tue, 1 Dec 2026 15:57:30 +0800 Message-ID: <20261201075731.36746-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201075731.36746-1-kerneljasonxing@gmail.com> References: <20261201075731.36746-1-kerneljasonxing@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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