From: "Arthur Fabre" <afabre@cloudflare.com>
To: "Eduard Zingerman" <eddyz87@gmail.com>, <bpf@vger.kernel.org>
Cc: "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
<kernel-team@cloudflare.com>
Subject: Re: [PATCH bpf v3 2/2] selftests/bpf: Test r0 and ref lifetime after BPF-BPF call with abnormal return
Date: Wed, 08 Jan 2025 21:46:19 +0100 [thread overview]
Message-ID: <D6WZI57R29GS.37Z8R92TTJJUG@cloudflare.com> (raw)
In-Reply-To: <f2b4420265b118f9aaaa329f86a5b52d48200281.camel@gmail.com>
On Mon Jan 6, 2025 at 9:34 PM CET, Eduard Zingerman wrote:
> On Mon, 2025-01-06 at 18:15 +0100, Arthur Fabre wrote:
[...]
> > +#define TEST(NAME, CALLEE) \
> > + SEC("socket") \
> > + __description("r0: " #NAME) \
> > + __failure __msg("math between ctx pointer and register with unbounded min value") \
> > + __naked int check_abnormal_ret_r0_##NAME(void) \
> > + { \
> > + asm volatile(" \
> > + r6 = r1; \
> > + r2 = r10; \
> > + r2 += -8; \
> > + call " #CALLEE "; \
> > + r6 += r0; \
> > + r0 = 0; \
> > + exit; \
> > + " : \
> > + : \
> > + : __clobber_all); \
> > + } \
> > + \
> > + SEC("socket") \
> > + __description("ref: " #NAME) \
> > + __failure __msg("math between ctx pointer and register with unbounded min value") \
> > + __naked int check_abnormal_ret_ref_##NAME(void) \
> > + { \
> > + asm volatile(" \
> > + r6 = r1; \
> > + r7 = r10; \
> > + r7 += -8; \
> > + r2 = r7; \
> > + call " #CALLEE "; \
> > + r0 = *(u64*)(r7 + 0); \
> > + r6 += r0; \
> > + exit; \
> > + " : \
> > + : \
> > + : __clobber_all); \
> > + }
>
> Nit: I think having both cases is an overkill, as both effectively
> test if branching occur.
Fair enough, I can drop the reference tests.
> [...]
>
> > +struct {
> > + __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
> > + __uint(max_entries, 1);
> > + __uint(key_size, sizeof(int));
> > + __array(values, void(void));
> > +} map_prog SEC(".maps") = {
> > + .values = {
> > + [0] = (void *)&dummy_prog,
> > + },
> > +};
> > +
> > +static __noinline __used
> > +int callee_tail_call(struct __sk_buff *skb, __u64 *foo)
> > +{
> > + bpf_tail_call(skb, &map_prog, 0);
> > + *foo = 1;
> > + return 0;
> > +}
>
> Nit: I'd also add a test where invalid action is taken
> after bpf_tail_call inside the callee,
> just to make sure that both branches are explored.
Good idea, I'll add that in and resend. Thanks for the feedback!
>
> > +
> > +SEC("socket")
> > +__description("r0 not set by tail_call")
> > +__failure __msg("R0 !read_ok")
> > +int check_abnormal_ret_tail_call_fail(struct __sk_buff *skb)
> > +{
> > + return bpf_tail_call(skb, &map_prog, 0);
> > +}
> > +
> > +char _license[] SEC("license") = "GPL";
prev parent reply other threads:[~2025-01-08 20:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 17:15 [PATCH bpf v3 0/2] bpf: Account for early exit of bpf_tail_call() and LD_ABS Arthur Fabre
2025-01-06 17:15 ` [PATCH bpf v3 1/2] " Arthur Fabre
2025-01-06 20:31 ` Eduard Zingerman
2025-01-08 20:44 ` Arthur Fabre
2025-01-06 17:15 ` [PATCH bpf v3 2/2] selftests/bpf: Test r0 and ref lifetime after BPF-BPF call with abnormal return Arthur Fabre
2025-01-06 20:34 ` Eduard Zingerman
2025-01-08 20:46 ` Arthur Fabre [this message]
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=D6WZI57R29GS.37Z8R92TTJJUG@cloudflare.com \
--to=afabre@cloudflare.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@cloudflare.com \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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