From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1E4941E5724; Wed, 8 Apr 2026 18:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672587; cv=none; b=KRvaHZjCpyVojtbiYiwjn7N+gqMckttWoLqgFYGGlUbW0NnWRD/Gx8EtjBAJX4Pe0fIaeRN2W64n5xVt+nM9kEahK+IFPKjUE3BWERXjZLKNyMkbYneCVzhZtHH0A7Rjr0jR0OMj4AqhCwX3hLgbRkh+IgqbLVsBWJ7jUMHaDHE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672587; c=relaxed/simple; bh=A5aAgwvV9GK7htLqRK3z2MPiVdqexu9mvxsacPHgJ4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l4hii8BrpktoV+3BZD/dG2Z5/UNwZlANvF8pvuzhN8tnLZ3m8rX9CxoyqHJaq0RESFFoyELhusjDPTNsF1hfvF7ZhCncVKoIeVQTkPwM5skdWNz8spGYC5PVHSXZ9/oz6UL5kGT5KgswAftiwcUMTw3yMXkCDq6etDBEzR4YnW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BeqooH2S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="BeqooH2S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0FCEC19421; Wed, 8 Apr 2026 18:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775672587; bh=A5aAgwvV9GK7htLqRK3z2MPiVdqexu9mvxsacPHgJ4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BeqooH2SFPqfsyfJnOXasPY7EsYCihkCjNKABxnDVXoWXVi/6KQRq9HF3D4u+y4WR MOPtIqxXxZzhkeN0+T535Plpxn3gATmFRrF/bFyhSuADosx/jyhfssMaua19XUln6X 2yiPqJFIF+I//UABgxFoICmGElAdZeUQgR1P8fY0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Amery Hung , Eduard Zingerman , Sasha Levin Subject: [PATCH 6.6 032/160] bpf: Fix regsafe() for pointers to packet Date: Wed, 8 Apr 2026 20:01:59 +0200 Message-ID: <20260408175914.409039564@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175913.177092714@linuxfoundation.org> References: <20260408175913.177092714@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit a8502a79e832b861e99218cbd2d8f4312d62e225 ] In case rold->reg->range == BEYOND_PKT_END && rcur->reg->range == N regsafe() may return true which may lead to current state with valid packet range not being explored. Fix the bug. Fixes: 6d94e741a8ff ("bpf: Support for pointers beyond pkt_end.") Signed-off-by: Alexei Starovoitov Signed-off-by: Andrii Nakryiko Reviewed-by: Daniel Borkmann Reviewed-by: Amery Hung Acked-by: Eduard Zingerman Link: https://lore.kernel.org/bpf/20260331204228.26726-1-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 226f2cd338d67..e33cd755d6197 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -16148,8 +16148,13 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold, * since someone could have accessed through (ptr - k), or * even done ptr -= k in a register, to get a safe access. */ - if (rold->range > rcur->range) + if (rold->range < 0 || rcur->range < 0) { + /* special case for [BEYOND|AT]_PKT_END */ + if (rold->range != rcur->range) + return false; + } else if (rold->range > rcur->range) { return false; + } /* If the offsets don't match, we can't trust our alignment; * nor can we be sure that we won't fall out of range. */ -- 2.53.0