All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Eduard Zingerman" <eddyz87@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 v1 1/2] bpf: Compare stack frames in regs_exact()
Date: Mon, 14 Sep 2026 18:39:30 +0200	[thread overview]
Message-ID: <DLF6RNI22PV3.3DMVBHPB0BR8E@gmail.com> (raw)
In-Reply-To: <9c64f514a0afb6a491ff316246ec6cefa4adeff7.camel@gmail.com>

On Mon Sep 14, 2026 at 6:33 PM CEST, Eduard Zingerman wrote:
> On Mon, 2026-09-14 at 18: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.
>>
>> Include frameno in regs_exact() so both exact and ordinary stack-pointer
>> comparisons enforce it. The field stays zero for other register types.
>>
>> 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>
>> ---
>
> I'm going to land '[PATCH bpf v3 0/7] Misc bug fixes - part 5',
> which would be in conflict with this one.
> After that, could you please respin, but try to move frameno inside
> the bpf_reg_state's union or near the delta field?
>
> ...

Makes sense, will do.

  reply	other threads:[~2026-09-14 16:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 16:13 [PATCH bpf v1 0/2] bpf: Compare stack frames in exact register states Kumar Kartikeya Dwivedi
2026-09-14 16:13 ` [PATCH bpf v1 1/2] bpf: Compare stack frames in regs_exact() Kumar Kartikeya Dwivedi
2026-09-14 16:33   ` Eduard Zingerman
2026-09-14 16:39     ` Kumar Kartikeya Dwivedi [this message]
2026-09-14 17:10   ` bot+bpf-ci
2026-09-14 16:13 ` [PATCH bpf v1 2/2] selftests/bpf: Cover frame changes in bounded loops Kumar Kartikeya Dwivedi

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=DLF6RNI22PV3.3DMVBHPB0BR8E@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.