From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58B6B3C276D; Tue, 25 Aug 2026 13:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787665913; cv=none; b=u3YmxBqloU6dxNEJJn0KaF0D3YUjlIowUX4iHVAvX4v9N2uWVvIdKMK/wMcyfoAfnOlY/xvqPORci/G5OZI6uXr1Zt9xqFXl6eOdOedjV65Dqvkn45z0PcLDqjMgo1vYhvVzq4ibqXqA6CCs5H/4eWFmHvOj4nmVUGzaBkt8pv8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787665913; c=relaxed/simple; bh=TCwCnz8D6wiKpfn51u/aS8s5tou8yoJC1Bv9TViiI94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uZS3Ofp/4ZXjN3NmB4SiAQGpQdELwllOfWqAI0QyhZTZxwFFEwxxM9K+wRhesJLpAJviAi7b2pz6HGfbKQFXK9yviGvkxkFPIvUc/CSLAUQyemry75ZW6z+wHRUbrUHoQd8x1UjtaE/o85QKMnoqp/1Vx6IVVJgV59qf5+ltG80= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vB10JL2D; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vB10JL2D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE5D11F000E9; Tue, 25 Aug 2026 13:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787665912; bh=mVUzTmRCTnvuVsUvg9h3f/LyDI6jpHkFsLoXt+NVM7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vB10JL2D67kiL2isUu1f+vEr6OLGX2Uxu71i/2nnLBGDCxFf7IeZaHkq+VTjB+Sw5 6GpcXaSVAwkc8S7grIeX1jB7+ZT9dxuCNDBH/Jd6DtYnRJ3I1Biw3hQC4YEyaUQQRZ G117rAQt/zJFZ0bEcKKePg/KW9GGPiR9fzI/SH90= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qihang Tang , Willem de Bruijn , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 20/79] packet: use consistent hard_header_len in TX_RING send path Date: Tue, 25 Aug 2026 15:26:00 +0200 Message-ID: <20260825132542.469804360@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825132541.677185791@linuxfoundation.org> References: <20260825132541.677185791@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qihang Tang [ Upstream commit 21b5953e7494c16a42e6cd8cf110e18d13ae4a6b ] tpacket_snd() reads dev->hard_header_len independently for skb allocation and header construction in tpacket_fill_skb(). Concurrent netdevice reconfiguration can therefore make the reserved headroom smaller than the amount later pushed, or make copylen - hard_header_len negative. Snapshot hard_header_len once before processing ring frames and use it for the frame limit, headroom allocation, copy length, and skb construction. Pass the snapshot to tpacket_fill_skb(). The separate SOCK_DGRAM consistency problem between hard_header_len and header_ops->create is not addressed here. Fixes: 69e3c75f4d54 ("net: TX_RING and packet mmap") Cc: stable@vger.kernel.org Signed-off-by: Qihang Tang Reviewed-by: Willem de Bruijn Link: https://patch.msgid.link/20260805125729.19220-4-q.h.hack.winter@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2624,6 +2624,7 @@ static int packet_snd_vnet_parse(struct static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, void *frame, struct net_device *dev, void *data, int tp_len, __be16 proto, unsigned char *addr, int hlen, int copylen, + int hard_header_len, const struct sockcm_cookie *sockc) { union tpacket_uhdr ph; @@ -2655,8 +2656,8 @@ static int tpacket_fill_skb(struct packe } else if (copylen) { int hdrlen = min_t(int, copylen, tp_len); - skb_push(skb, dev->hard_header_len); - skb_put(skb, copylen - dev->hard_header_len); + skb_push(skb, hard_header_len); + skb_put(skb, copylen - hard_header_len); err = skb_store_bits(skb, 0, data, hdrlen); if (unlikely(err)) return err; @@ -2789,7 +2790,7 @@ static int tpacket_snd(struct packet_soc void *data; int len_sum = 0; int status = TP_STATUS_AVAILABLE; - int hlen, tlen, copylen = 0; + int hard_header_len, hlen, tlen, copylen = 0; long timeo; mutex_lock(&po->pg_vec_lock); @@ -2836,8 +2837,9 @@ static int tpacket_snd(struct packet_soc goto out_put; } + hard_header_len = READ_ONCE(dev->hard_header_len); if (po->sk.sk_socket->type == SOCK_RAW) - reserve = dev->hard_header_len; + reserve = hard_header_len; size_max = po->tx_ring.frame_size - (po->tp_hdrlen - sizeof(struct sockaddr_ll)); @@ -2875,7 +2877,7 @@ static int tpacket_snd(struct packet_soc goto tpacket_error; status = TP_STATUS_SEND_REQUEST; - hlen = LL_RESERVED_SPACE(dev); + hlen = LL_RESERVED_SPACE_EX(dev, hard_header_len); tlen = dev->needed_tailroom; if (packet_sock_flag(po, PACKET_SOCK_HAS_VNET_HDR)) { data += sizeof(vnet_hdr); @@ -2893,10 +2895,10 @@ static int tpacket_snd(struct packet_soc vnet_hdr.hdr_len); has_vnet_hdr = true; } - copylen = max_t(int, copylen, dev->hard_header_len); + copylen = max_t(int, copylen, hard_header_len); skb = sock_alloc_send_skb(&po->sk, hlen + tlen + sizeof(struct sockaddr_ll) + - (copylen - dev->hard_header_len), + (copylen - hard_header_len), !need_wait, &err); if (unlikely(skb == NULL)) { @@ -2906,7 +2908,8 @@ static int tpacket_snd(struct packet_soc goto out_status; } tp_len = tpacket_fill_skb(po, skb, ph, dev, data, tp_len, proto, - addr, hlen, copylen, &sockc); + addr, hlen, copylen, hard_header_len, + &sockc); if (likely(tp_len >= 0) && tp_len > dev->mtu + reserve && !packet_sock_flag(po, PACKET_SOCK_HAS_VNET_HDR) &&