BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Nicholas Carlini <npc@anthropic.com>,
	 kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf v2 1/2] bpf: Compare stack frames in regs_exact()
Date: Fri, 18 Sep 2026 11:13:24 -0700	[thread overview]
Message-ID: <c6c10b90702c49a3d791751a09df4f97799a1f28.camel@gmail.com> (raw)
In-Reply-To: <20260918011313.3053497-2-memxor@gmail.com>

On Fri, 2026-09-18 at 03:13 +0200, Kumar Kartikeya Dwivedi wrote:
> regs_exact() compares the register state up to id, followed by the ID
> mappings, but does not compare frameno. The PTR_TO_STACK case in regsafe()
> checks frameno separately, which is bypassed when exact comparison is
> requested. Consequently, infinite-loop detection can treat pointers to
> different stack frames as the same pointer and reject a finite loop.
> 
> For example, initialize fp-8 to zero in the caller and to one in the
> callee, then pass the caller's fp-8 to the callee as r1:
> 
>     loop:
>         r0 = *(u64 *)(r1 + 0);
>         if r0 != 0 goto done;
>         r1 = r10;
>         r1 += -8;
>         goto loop;
>     done:
>         exit;
> 
> The loop terminates after reading the callee's slot on its second
> iteration. At the loop header, however, the only relevant difference is
> r1's frameno, so exact comparison incorrectly reports an infinite loop.
> The same problem occurs when the pointer is spilled to the stack.
> 
> Move frameno into the type-specific metadata union, ahead of id, so the
> existing prefix comparison in regs_exact() covers it. Ordinary stack
> pointers do not use another union member. Iterator and IRQ stack-slot
> states use their dedicated union views and do not need a frame lookup.
> This also keeps bpf_reg_state at 80 bytes.
> 
> Move the states_maybe_looping() boundary from frameno to precise after the
> field relocation. Its prefix comparison continues to cover the complete
> value state and now includes frameno.
> 
> Continue to ignore precise. Precision marks control whether pruning may
> ignore scalar ranges; they do not change the represented values, and exact
> comparison already compares those ranges unconditionally. Marks can also
> change through backtracking while an ancestor state is still being
> explored.
> 
> Fixes: d5b892fd607a ("bpf: make infinite loop detection in is_state_visited() exact")
> Reported-by: Eduard Zingerman <eddyz87@gmail.com>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

...

  reply	other threads:[~2026-09-18 18:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  1:13 [PATCH bpf v2 0/2] Compare stack frames in exact register states Kumar Kartikeya Dwivedi
2026-09-18  1:13 ` [PATCH bpf v2 1/2] bpf: Compare stack frames in regs_exact() Kumar Kartikeya Dwivedi
2026-09-18 18:13   ` Eduard Zingerman [this message]
2026-09-18  1:13 ` [PATCH bpf v2 2/2] selftests/bpf: Cover frame changes in bounded loops Kumar Kartikeya Dwivedi
2026-09-18 18:15   ` Eduard Zingerman

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=c6c10b90702c49a3d791751a09df4f97799a1f28.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=memxor@gmail.com \
    --cc=npc@anthropic.com \
    /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