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=1796384265; b=zJajc6YpPWPgHlaRONSIGFSmPTFj1d0KqqSRdV83JZLh7R1xfQN7UVAu6r6rG/vUUetN J1Puhfyy4Tl4TPjipKMtdgWzIU2SyGi4CTpNz/vsbpo8QU36fb7E5k2aVopK1MSaAEhDm aJ6HTd171cuBIyqIwfdwORMY+kgY84blpVVcq2tf5Gyu7NV69DOV9zEpxKDq8J+PDb9Pd pdYCnqzN1SHUMcqhPTYww33j0G+T1fSaPDTfz1Wzogx4Lo/A7lYYTC873uGzFU9iC+fLz uNUGCrpF7i7sq92a4v8OIKcc6a8TAQYbMa5pFVbzeM/0co+PzB7xmxKg7u4j4Cjdsqg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384265; 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=jXM5nNi7HGeXzYoCOCMH1UgOWaCMaPeBjGOnDzON3aA=; b=ypVZtsbgprw98y2zNX/v8L39pzmmz3L39uVcPVCWzw4U9r8iyOThlMTOzMd902Iox2Dy 6eBZFPtLQTUOVe+/IkhbWn9xdX8lFziOMMl4ivKEY8nUkr42yhSi3gPe/UnZ0aRbnn3Y5 y5s1A8C4J7S6JWQLB2o1gQtt8S7V+88k1OgrsGJgSXa0+A+ZEhNN+AOOO+Is9EJDzL7O7 /jMnSSQEQ7UVvMXatSZYBdIuJvKnB1Imv1Y4gChSRYO5HyM/+LWNo8rO6ng4Pymv9pFmh Lz+XlESPLcVmCv7SiHi+ZS2kNz99xi+01Itd89h/L+YdiDksA9DgPO3eQkbC/EGxwAA== 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=WUJ6WyxA; 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 5386C606A322; Fri, 4 Dec 2026 11:37:45 +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=WUJ6WyxA Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB9541F000C2; Fri, 4 Dec 2026 11:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384265; bh=jXM5nNi7HGeXzYoCOCMH1UgOWaCMaPeBjGOnDzON3aA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WUJ6WyxAYrLSdbE/lYLJGmJCyYT4qi1XzeCmx5c9WEFCAbIdLu/QOUaA0DEM8e4jY JZfQZVQaQvZeMAwaTNRy0gzUxr9UBq4aqDK7x179rLQ4iJHdfcLm2tIMwIwod25BQ1 +DuwEXmV3Si4xPkBHgfpe78PjV8k82u4SJ+4CHNI= 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.6 0078/1167] bpf: Check the offset in bpf_skb_generic_{push,pop}() Date: Fri, 4 Dec 2026 18:51:45 +0900 Message-ID: <20261204100704.116464186@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 d013cfa1e4857..34713be30ac5a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3295,6 +3295,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. */ @@ -3315,9 +3319,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