public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Emil Tsalapatis <emil@etsalapatis.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, memxor@gmail.com,
	daniel@iogearbox.net, eddyz87@gmail.com, song@kernel.org,
	Emil Tsalapatis <emil@etsalapatis.com>
Subject: [PATCH bpf-next v5 1/9] bpf: Upgrade scalar to PTR_TO_ARENA on arena pointer addition
Date: Fri, 10 Apr 2026 12:30:33 -0400	[thread overview]
Message-ID: <20260410163041.8063-2-emil@etsalapatis.com> (raw)
In-Reply-To: <20260410163041.8063-1-emil@etsalapatis.com>

The compiler sometimes stores the result of a PTR_TO_ARENA + SCALAR
addition into the scalar register rather than the pointer register.
Handle this case by upgrading the destination scalar register to
PTR_TO_ARENA, matching the existing handling when the destination is
already PTR_TO_ARENA.

Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
Acked-by: Song Liu <song@kernel.org>
---
 kernel/bpf/verifier.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 594260c1f382..30c3e26aae96 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16641,11 +16641,32 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
 	int err;
 
 	dst_reg = &regs[insn->dst_reg];
-	src_reg = NULL;
+	if (BPF_SRC(insn->code) == BPF_X)
+		src_reg = &regs[insn->src_reg];
+	else
+		src_reg = NULL;
 
-	if (dst_reg->type == PTR_TO_ARENA) {
+	/* Case where at least one operand is an arena. */
+	if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
 		struct bpf_insn_aux_data *aux = cur_aux(env);
 
+		if (dst_reg->type != PTR_TO_ARENA) {
+			/* Can't do arena arithmetic with non-scalars. */
+			if (dst_reg->type != SCALAR_VALUE) {
+				verbose(env, "R%d %s R%d: Invalid operation between "
+						"bpf_reg_state types %s and %s\n",
+					insn->dst_reg,
+					bpf_alu_string[opcode >> 4],
+					insn->src_reg,
+					reg_type_str(env, dst_reg->type),
+					reg_type_str(env, src_reg->type));
+				return -EACCES;
+			}
+
+			*dst_reg = *src_reg;
+			dst_reg->subreg_def = env->insn_idx + 1;
+		}
+
 		if (BPF_CLASS(insn->code) == BPF_ALU64)
 			/*
 			 * 32-bit operations zero upper bits automatically.
-- 
2.53.0


  reply	other threads:[~2026-04-10 16:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 16:30 [PATCH bpf-next v5 0/9] Introduce arena library and runtime Emil Tsalapatis
2026-04-10 16:30 ` Emil Tsalapatis [this message]
2026-04-10 17:34   ` [PATCH bpf-next v5 1/9] bpf: Upgrade scalar to PTR_TO_ARENA on arena pointer addition bot+bpf-ci
2026-04-10 17:55     ` Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 2/9] selftests/bpf: Add test for scalar/arena " Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 3/9] selftests/bpf: Move bpf_arena_spin_lock.h to the top level Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 4/9] selftests/bpf: Deduplicate WRITE_ONCE macro between headers Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 5/9] selftests/bpf: Add basic libarena scaffolding Emil Tsalapatis
2026-04-10 18:39   ` Song Liu
2026-04-10 19:44     ` Kumar Kartikeya Dwivedi
2026-04-10 20:12       ` Emil Tsalapatis
2026-04-10 22:06         ` Song Liu
2026-04-10 22:50           ` Alexei Starovoitov
2026-04-10 23:06             ` Song Liu
2026-04-10 16:30 ` [PATCH bpf-next v5 6/9] selftests/bpf: Add arena ASAN runtime to libarena Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 7/9] selftests/bpf: Add ASAN support for libarena selftests Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 8/9] selftests/bpf: Add buddy allocator for libarena Emil Tsalapatis
2026-04-10 16:30 ` [PATCH bpf-next v5 9/9] selftests/bpf: Add selftests for libarena buddy allocator Emil Tsalapatis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260410163041.8063-2-emil@etsalapatis.com \
    --to=emil@etsalapatis.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox