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=1796379658; b=f3ONprtB9KWpviI0Ezd0eSBgsRcAlJZbQuQjBXohGBXOrUfxTcngvzeFytsi0lxjv8Ry kmyCqipyvjZPGENYE+VFyAe7ySxxQrF9C1FCyAVsyQvDW+L2nC+5pNsTBlK/GBFBQt8XT t7YvksPrARbymwKRrJsOH8FAQpM6y89RoW5HemW2SVNcc1g7Ko/A06EkYaIZ4c+eV7N93 3hGqfb4Zu+Fg17n0D3D7/mVlnpOTeQHsUWbawDvBq04JErZOZQqMDrpvWMyNgihCamZBK 3WWyWsvb9TXMVTH7Jz9w2yaXpwvLCDmhj8jxwke7k6q0b15Cjbz7UmY1dkBFXodnCPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379658; 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=2Rtktgk5kSmg6il56IgMKMnM6k3tl5bYVuBdawLxxts=; b=z9PcZ5pERLhFhQSv6NI08T53PwQ/5Mpy0gntqtutaqmBOm//CRhtEcAV3QnTetRxVOa+ OpTRbzWbknWuanqNgy0m5SOwYrHL/IBB5tCTXQgdJDD1CId4PZgiXMy7oDbGYJSwXiuPB oQX5ysfqk6XTFduJWrsoBQ6X6FuKRFdsVLhGOiXqz+Y45TjynHKR74fdG6F0X/GtOSf6H oZY7giHgGmmoKYTia+JunZnuE7GHmu8x8jXqW0aGaiiER+JFRgVqAPZWHCEtTDR9xQz6R i93EDh0flumMp4SLnduhKpHQrvbZa9uaoXPckPVs32c4GsAH5xhhCVFzUxgGwk55Hjw== 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=jYe3wqxs; 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 B5105606A322; Fri, 4 Dec 2026 10:20:58 +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=jYe3wqxs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 322341F000C2; Fri, 4 Dec 2026 10:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379658; bh=2Rtktgk5kSmg6il56IgMKMnM6k3tl5bYVuBdawLxxts=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jYe3wqxsXdBjo/4rceJIhz0qVBvCh+KE8Q4OkG/QRD9rzwjk66kvQmvnVpEzyt0Mw AjOqpVT9brsKnUBXzjxxBCarZYsyMbj9a23cxcnmv0OiOTvL3Fir9CyXa/SVQd3N4t ALCGSSLYjYhB0sviDQUj1apsiz/P1S5ZI662xVZU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0057/1059] bpf: Check the offset in bpf_skb_generic_{push,pop}() Date: Fri, 4 Dec 2026 18:53:08 +0900 Message-ID: <20261204100645.561369897@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit ee36c9aa44ef300cd651074bd97552b229337f85 ] To make room for len bytes at offset off, bpf_skb_generic_push() moves the first off bytes and clears len bytes after them. It assumes that the first off bytes are in the linear part. But in bpf_skb_adjust_room() off can be the end of the IP header, and this header can be in a frag. Then the function reads and writes after skb->tail, and can damage skb_shared_info. bpf_skb_generic_pop() checks off + len, but this u32 sum can wrap to a small value. bpf_skb_adjust_room() and bpf_skb_change_proto() calculate off from skb_mac_header_len(). This length is a very large u32 when network_header < mac_header. Then the check can pass, and memmove() reads and writes far outside the skb. Return -ENOMEM from both functions, like the present check, when off > skb->len. Thus the sum cannot wrap. In bpf_skb_generic_push() also pull the first off bytes into the linear part. Now bpf_skb_adjust_room() fails when a prog grows an skb that ends before off. network_header stays wrong. Fixes: 6578171a7ff0 ("bpf: add bpf_skb_change_proto helper") Fixes: 2be7e212d541 ("bpf: add bpf_skb_adjust_room helper") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-28-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 5a7ec964f740b..bdb60caa7b36b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3287,6 +3287,10 @@ static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto) static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len) { + /* The bytes in front of @off are moved with skb->data. */ + if (unlikely(off > skb->len || !pskb_may_pull(skb, off))) + return -ENOMEM; + /* Caller already did skb_cow() with meta_len+len as headroom, * so no need to do it here. */ @@ -3307,9 +3311,10 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) void *old_data; /* skb_ensure_writable() is not needed here, as we're - * already working on an uncloned skb. + * already working on an uncloned skb. The first test + * keeps off + len from wrapping. */ - if (unlikely(!pskb_may_pull(skb, off + len))) + if (unlikely(off > skb->len || !pskb_may_pull(skb, off + len))) return -ENOMEM; old_data = skb->data; -- 2.53.0