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 v2 2/2] selftests/bpf: Test r0 bounds after BPF to BPF call with abnormal return
Date: Mon, 16 Dec 2024 18:39:36 +0100 [thread overview]
Message-ID: <D6DB4NCLQZC9.I7DUNKR9RORW@bobby> (raw)
In-Reply-To: <76401f4502366c2d9221758f9034aa7bb2d831a3.camel@gmail.com>
On Sat Dec 14, 2024 at 12:55 AM CET, Eduard Zingerman wrote:
> On Fri, 2024-12-13 at 22:27 +0100, Arthur Fabre wrote:
[...]
> > +++ b/tools/testing/selftests/bpf/progs/verifier_abnormal_ret.c
> > @@ -0,0 +1,88 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +#include <linux/bpf.h>
> > +#include <bpf/bpf_helpers.h>
> > +#include "../../../include/linux/filter.h"
> > +#include "bpf_misc.h"
> > +
> > +#define TEST(NAME, CALLEE) \
> > + SEC("socket") \
> > + __description("abnormal_ret: " #NAME) \
> > + __failure __msg("math between ctx pointer and register with unbounded min value") \
> > + __naked void check_abnormal_ret_##NAME(void) \
> > + { \
>
> Nit: this one and 'callee_tail_call' could be plain C.
>
> > + asm volatile(" \
> > + r6 = r1; \
> > + call " #CALLEE "; \
> > + r6 += r0; \
> > + r0 = 0; \
> > + exit; \
> > + " : \
> > + : \
> > + : __clobber_all); \
> > + }
>
> [...]
>
> > +static __naked __noinline __used
> > +int callee_tail_call(void)
> > +{
> > + asm volatile(" \
> > + r2 = %[map_prog] ll; \
> > + r3 = 0; \
> > + call %[bpf_tail_call]; \
> > + r0 = 0; \
> > + exit; \
> > +" :
> > + : __imm(bpf_tail_call), __imm_addr(map_prog)
> > + : __clobber_all);
> > +}
> > +
> > +char _license[] SEC("license") = "GPL";
Thanks for the review! Good point, I'll try to write them in C.
It might not be possible to do them both entirely: clang also doesn't
know that bpf_tail_call() can return, so it assumes the callee() will
return a constant r0. It sometimes optimizes branches / loads out
because of this.
next prev parent reply other threads:[~2024-12-16 17:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 21:27 [PATCH bpf v2 0/2] Don't trust r0 bounds after BPF to BPF calls with abnormal returns Arthur Fabre
2024-12-13 21:27 ` [PATCH bpf v2 1/2] bpf: " Arthur Fabre
2024-12-13 23:52 ` Eduard Zingerman
2024-12-13 21:27 ` [PATCH bpf v2 2/2] selftests/bpf: Test r0 bounds after BPF to BPF call with abnormal return Arthur Fabre
2024-12-13 23:55 ` Eduard Zingerman
2024-12-16 17:39 ` Arthur Fabre [this message]
2024-12-16 18:05 ` Alexei Starovoitov
2024-12-16 18:50 ` Eduard Zingerman
2024-12-16 19:47 ` Alexei Starovoitov
2024-12-16 20:45 ` Arthur Fabre
2024-12-16 18:50 ` Eduard Zingerman
2024-12-16 17:45 ` [PATCH bpf v2 0/2] Don't trust r0 bounds after BPF to BPF calls with abnormal returns Arthur Fabre
2024-12-16 18:03 ` Alexei Starovoitov
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=D6DB4NCLQZC9.I7DUNKR9RORW@bobby \
--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 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.