From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379378; b=xiFswNfRZpetNpNs3JZaG+Euxbti7A55LvLNLYaBVsaoXOI1PwdI67Fcx7A2ebJ8IiGW /dQ6IrC5iJ6unGNt0/kjwWef3DNgMsVPFWUVWE3L3Sco4tPRsUWm/DxnWAAwH5Se8Hmga vz5w2aZ5eUs8dXxhsgiVvEr2f48wemIvcbd5FH3p86xGc6UA02hjaO1Qb5jhO3/lkNqdj WnQbRkkW9cjW+NxYCmu/YFLXumOOiBqSZ6WEWJXQiZENhMdRn81/zVm/s1tgUeGhpdrXH CYkSYCYQQ49WZbQO92TcQ4Hcq9orakAbi+JhBcMAsU9hpjBHShguKZ41ubWF1dnHZwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379378; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=OTwWxzWYMvS2g7gXnI+GMZl41YKwQswUtbYyE1eN1lk=; b=W0r5GtLidkd9XG+34ZGT/z6lE5TOjGiGINAbkt6WzorKyazFQOxiP28j2gIGyjVjIlrG nKPLnLtVh9O3Q938kCoUHI1k1GRpXfpXY3olL7mS57V8FSGuj4UCIKZ6O4rpW5d3+XjWi 6SHidmzc3fbuZ+zPN1fXy5iYK4x1WBmgNY9KyoMiX0QmZBFTsqRqqsqKan10srC8PwQRD q8Dzq+GMCPp5W3CyABG7Y8NPHcyH3Cv+jpkmHfXbwYXO4Jcj8Y7W0wFBlDf2Bfwy2Tu25 AsUCs+5cxii6ynvoS2CMQAqy9JD72hD0Uhm4V5nAkgpHt1MiXlKeyGqa+C8ueVVixKw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=V5TfFNBx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8C79606A32F; Fri, 4 Dec 2026 10:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=V5TfFNBx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68CDC1F000C2; Fri, 4 Dec 2026 10:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379377; bh=OTwWxzWYMvS2g7gXnI+GMZl41YKwQswUtbYyE1eN1lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V5TfFNBxqC1hzgz0VAircDaPR+sUjV7pvwkiDX/OfbRqKMd+1fhz/BsAlaNB6VdrG aeDGXF0ud2o3qhYkMAaphJROqosQehPxfUh5xOurEfwnwf5ig+3L8X7UvCfYRWnl8j /8DbYwQ09hpUcdCe4VbSvwt2yCvufDeaaneYKzhw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Eric Dumazet , "Michael S. Tsirkin" , Paolo Abeni , Artem Dinaburg , Sasha Levin Subject: [PATCH 6.18 008/703] net: reject a negative TCP header offset in qdisc_pkt_len_segs_init() Date: Fri, 4 Dec 2026 18:58:27 +0900 Message-ID: <20261204100627.763416229@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 35d2d6e5ac0d22428b2a0216061f3330c095393c ] qdisc_pkt_len_segs_init() stores skb_transport_offset(), or the inner offset, in the unsigned hdr_len. A header in front of skb->data gives a negative offset. For an offset a little below zero, pskb_may_pull() gets a small length and succeeds. Then a 64-bit kernel reads the TCP header far after the skb and can crash. Further below zero pskb_may_pull() fails. Commit 28a57fb2c5df ("net: iptunnel: fix stale transport header during tunnel decapsulation") fixed one source of such offsets. Other code that removes bytes from the front of a packet can leave the same stale header. Return SKB_DROP_REASON_SKB_BAD_GSO for a negative offset in the TCP branch. SKB_GSO_UDP_L4 and the other GSO types read no header and still get a wrong qdisc_pkt_len(). On a 64-bit kernel only packets that cause the read after the skb today get a new result. Then __dev_queue_xmit() drops them and returns -EINVAL, but sch_handle_ingress() ignores the result. Their content can be valid. Thus the code that leaves the header stale needs its own fix. Fixes: 7fb4c1967011 ("net: pull headers in qdisc_pkt_len_segs_init()") Signed-off-by: Alexei Starovoitov Reviewed-by: Eric Dumazet Acked-by: Michael S. Tsirkin CC: stable@vger.kernel.org Link: https://patch.msgid.link/20261101194433.2637113-1-alexei.starovoitov@gmail.com Signed-off-by: Paolo Abeni [ Backport to 6.18.y: in 6.18.y the function is qdisc_pkt_len_init() and __dev_queue_xmit() is its only caller; sch_handle_ingress() does not call it. The code change is identical to upstream. ] Signed-off-by: Artem Dinaburg Signed-off-by: Sasha Levin --- net/core/dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 40f3bb73c0ca3..c0aa4e8625b5d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4164,7 +4164,9 @@ static enum skb_drop_reason qdisc_pkt_len_init(struct sk_buff *skb) if (likely(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6))) { const struct tcphdr *th; - if (!pskb_may_pull(skb, hdr_len + sizeof(struct tcphdr))) + /* A header in front of skb->data gives a negative offset. */ + if ((int)hdr_len < 0 || + !pskb_may_pull(skb, hdr_len + sizeof(struct tcphdr))) return SKB_DROP_REASON_SKB_BAD_GSO; th = (const struct tcphdr *)(skb->data + hdr_len); -- 2.53.0