From: Yonghong Song <yonghong.song@linux.dev>
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>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v3 2/2] selftests/bpf: Add tests with stack ptr register in conditional jmp
Date: Wed, 21 May 2025 13:57:53 -0700 [thread overview]
Message-ID: <5761ffe9-fc09-4f06-9311-0eed40a693fb@linux.dev> (raw)
In-Reply-To: <6dd9752a-4bec-423d-8936-8757251f2b50@gmail.com>
On 5/21/25 12:02 PM, Eduard Zingerman wrote:
>
> On 2025-05-21 10:04, Yonghong Song wrote:
>
> [...]
>
>> @@ -178,4 +178,57 @@ __naked int state_loop_first_last_equal(void)
>> );
>> }
>> +__used __naked static void __bpf_cond_op_r10(void)
>> +{
>> + asm volatile (
>> + "r2 = 2314885393468386424 ll;"
>> + "goto +0;"
>> + "if r2 <= r10 goto +3;"
>> + "if r1 >= -1835016 goto +0;"
>> + "if r2 <= 8 goto +0;"
>> + "if r3 <= 0 goto +0;"
>> + "exit;"
>> + ::: __clobber_all);
>> +}
>> +
>> +SEC("?raw_tp")
>> +__success __log_level(2)
>> +__msg("8: (bd) if r2 <= r10 goto pc+3")
>> +__msg("9: (35) if r1 >= 0xffe3fff8 goto pc+0")
>> +__msg("10: (b5) if r2 <= 0x8 goto pc+0")
>> +__msg("mark_precise: frame1: last_idx 10 first_idx 0 subseq_idx -1")
>> +__msg("mark_precise: frame1: regs=r2 stack= before 9: (35) if r1 >=
>> 0xffe3fff8 goto pc+0")
>> +__msg("mark_precise: frame1: regs=r2 stack= before 8: (bd) if r2 <=
>> r10 goto pc+3")
>> +__msg("mark_precise: frame1: regs=r2 stack= before 7: (05) goto pc+0")
>> +__naked void bpf_cond_op_r10(void)
>> +{
>> + asm volatile (
>> + "r3 = 0 ll;"
>> + "call __bpf_cond_op_r10;"
>> + "r0 = 0;"
>> + "exit;"
>> + ::: __clobber_all);
>> +}
>
> This was probably a part of the repro, but I'm not sure
> this test adds much compared to test below.
> The changes do not interact with subprogram calls handling.
It does not interact with subprogram due the patch 1. Without patch 1,
the error will happen (see commit message of patch 1):
0: (18) r3 = 0x0 ; R3_w=0
2: (85) call pc+2
caller:
R10=fp0
callee:
frame1: R1=ctx() R3_w=0 R10=fp0
5: frame1: R1=ctx() R3_w=0 R10=fp0
; asm volatile (" \ @ verifier_precision.c:184
5: (18) r2 = 0x20202000256c6c78 ; frame1: R2_w=0x20202000256c6c78
7: (05) goto pc+0
8: (bd) if r2 <= r10 goto pc+3 ; frame1: R2_w=0x20202000256c6c78 R10=fp0
9: (35) if r1 >= 0xffe3fff8 goto pc+0 ; frame1: R1=ctx()
10: (b5) if r2 <= 0x8 goto pc+0
mark_precise: frame1: last_idx 10 first_idx 0 subseq_idx -1
mark_precise: frame1: regs=r2 stack= before 9: (35) if r1 >= 0xffe3fff8 goto pc+0
mark_precise: frame1: regs=r2 stack= before 8: (bd) if r2 <= r10 goto pc+3
mark_precise: frame1: regs=r2,r10 stack= before 7: (05) goto pc+0
mark_precise: frame1: regs=r2,r10 stack= before 5: (18) r2 = 0x20202000256c6c78
mark_precise: frame1: regs=r10 stack= before 2: (85) call pc+2
BUG regs 400
>
>> +
>> +SEC("?raw_tp")
>> +__success __log_level(2)
>> +__msg("3: (bf) r3 = r10")
>> +__msg("4: (bd) if r3 <= r2 goto pc+1")
>> +__msg("5: (b5) if r2 <= 0x8 goto pc+2")
>> +__msg("mark_precise: frame0: last_idx 5 first_idx 0 subseq_idx -1")
>> +__msg("mark_precise: frame0: regs=r2 stack= before 4: (bd) if r3 <=
>> r2 goto pc+1")
>> +__msg("mark_precise: frame0: regs=r2 stack= before 3: (bf) r3 = r10")
>> +__naked void bpf_cond_op_not_r10(void)
>> +{
>> + asm volatile (
>> + "r0 = 0;"
>> + "r2 = 2314885393468386424 ll;"
>> + "r3 = r10;"
>> + "if r3 <= r2 goto +1;"
>> + "if r2 <= 8 goto +2;"
>
> I think it would be good to add two more cases here:
> - dst register is pointer to stack
The previous test "r2 <= r10" should already cover this since r10 is a pointer to stack.
> - both src and dst registers are pointers to stack
I actually thought about this as well, e.g.,
r2 = r10
r3 = r10
if r2 <= r3 goto +0
if r2 <= 8 goto +0
But since r2 is actually a stack pointer, then r2 does not need
backtracking. So r2 <= r3 won't be backtracked too.
But if you feel such an example still valuable, I can add it too.
>
>> + "r0 = 2 ll;"
>> + "exit;"
>> + ::: __clobber_all);
>> +}
>> +
>> char _license[] SEC("license") = "GPL";
next prev parent reply other threads:[~2025-05-21 20:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 17:04 [PATCH bpf-next v3 1/2] bpf: Do not include stack ptr register in precision backtracking bookkeeping Yonghong Song
2025-05-21 17:04 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add tests with stack ptr register in conditional jmp Yonghong Song
2025-05-21 19:02 ` Eduard Zingerman
2025-05-21 20:57 ` Yonghong Song [this message]
2025-05-21 21:03 ` Eduard Zingerman
2025-05-21 18:55 ` [PATCH bpf-next v3 1/2] bpf: Do not include stack ptr register in precision backtracking bookkeeping Eduard Zingerman
2025-05-21 20:34 ` Yonghong Song
2025-05-21 20:58 ` Eduard Zingerman
2025-05-21 21:35 ` Yonghong Song
2025-05-21 21:59 ` Eduard Zingerman
2025-05-21 22:04 ` Eduard Zingerman
2025-05-21 22:38 ` Andrii Nakryiko
2025-05-21 22:49 ` Eduard Zingerman
2025-05-22 2:53 ` Yonghong Song
2025-05-22 20:05 ` Andrii Nakryiko
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=5761ffe9-fc09-4f06-9311-0eed40a693fb@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@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