From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: bpf@vger.kernel.org, David Vernet <void@manifault.com>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v1 7/7] selftests/bpf: Add test for dynptr reinit in user_ringbuf callback
Date: Wed, 16 Nov 2022 01:11:13 +0530 [thread overview]
Message-ID: <20221115194113.ag6pocm2hvrskd3i@apollo> (raw)
In-Reply-To: <CAJnrk1aynT73OZJauUEn_OFkVBsZ0wGSZHjnDSKwUG_wYd1Opw@mail.gmail.com>
On Wed, Nov 16, 2022 at 12:06:36AM IST, Joanne Koong wrote:
> On Mon, Nov 14, 2022 at 4:01 PM Kumar Kartikeya Dwivedi
> <memxor@gmail.com> wrote:
> >
> > The original support for bpf_user_ringbuf_drain callbacks simply
> > short-circuited checks for the dynptr state, allowing users to pass
> > PTR_TO_DYNPTR (now CONST_PTR_TO_DYNPTR) to helpers that initialize a
> > dynptr. This bug would have also surfaced with other dynptr helpers in
> > the future that changed dynptr view or modified it in some way.
> >
> > Include test cases for all cases, i.e. both bpf_dynptr_from_mem and
> > bpf_ringbuf_reserve_dynptr, and ensure verifier rejects both of them.
> > Without the fix, both of these programs load and pass verification.
> >
> > Acked-by: David Vernet <void@manifault.com>
> > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>
> Acked-by: Joanne Koong <joannelkoong@gmail.com>
>
> Left a small comment below.
>
> > ---
> > .../selftests/bpf/prog_tests/user_ringbuf.c | 2 ++
> > .../selftests/bpf/progs/user_ringbuf_fail.c | 35 +++++++++++++++++++
> > 2 files changed, 37 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> > index 39882580cb90..500a63bb70a8 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c
> > @@ -676,6 +676,8 @@ static struct {
> > {"user_ringbuf_callback_discard_dynptr", "cannot release unowned const bpf_dynptr"},
> > {"user_ringbuf_callback_submit_dynptr", "cannot release unowned const bpf_dynptr"},
> > {"user_ringbuf_callback_invalid_return", "At callback return the register R0 has value"},
> > + {"user_ringbuf_callback_reinit_dynptr_mem", "Dynptr has to be an uninitialized dynptr"},
> > + {"user_ringbuf_callback_reinit_dynptr_ringbuf", "Dynptr has to be an uninitialized dynptr"},
> > };
> >
> > #define SUCCESS_TEST(_func) { _func, #_func }
> > diff --git a/tools/testing/selftests/bpf/progs/user_ringbuf_fail.c b/tools/testing/selftests/bpf/progs/user_ringbuf_fail.c
> > index 82aba4529aa9..7730d13c0cea 100644
> > --- a/tools/testing/selftests/bpf/progs/user_ringbuf_fail.c
> > +++ b/tools/testing/selftests/bpf/progs/user_ringbuf_fail.c
> > @@ -18,6 +18,13 @@ struct {
> > __uint(type, BPF_MAP_TYPE_USER_RINGBUF);
> > } user_ringbuf SEC(".maps");
> >
> > +struct {
> > + __uint(type, BPF_MAP_TYPE_RINGBUF);
> > + __uint(max_entries, 2);
> > +} ringbuf SEC(".maps");
> > +
> > +static int map_value;
> > +
> > static long
> > bad_access1(struct bpf_dynptr *dynptr, void *context)
> > {
> > @@ -175,3 +182,31 @@ int user_ringbuf_callback_invalid_return(void *ctx)
> >
> > return 0;
> > }
> > +
> > +static long
> > +try_reinit_dynptr_mem(struct bpf_dynptr *dynptr, void *context)
> > +{
> > + bpf_dynptr_from_mem(&map_value, 4, 0, dynptr);
> > + return 0;
> > +}
> > +
> > +static long
> > +try_reinit_dynptr_ringbuf(struct bpf_dynptr *dynptr, void *context)
> > +{
> > + bpf_ringbuf_reserve_dynptr(&ringbuf, 8, 0, dynptr);
> > + return 0;
> > +}
> > +
> > +SEC("?raw_tp/sys_nanosleep")
> > +int user_ringbuf_callback_reinit_dynptr_mem(void *ctx)
> > +{
> > + bpf_user_ringbuf_drain(&user_ringbuf, try_reinit_dynptr_mem, NULL, 0);
> > + return 0;
> > +}
> > +
> > +SEC("?raw_tp/sys_nanosleep")
>
> nit: here and above, I think this should just be "?raw_tp/" without
> the nanosleep, since there is no nanosleep tracepoint.
>
True, looks like it's the same for all prior cases in this file as well. I will
drop sys_nanosleep for all of them.
prev parent reply other threads:[~2022-11-15 19:41 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 0:01 [PATCH bpf-next v1 0/7] Dynptr refactorings Kumar Kartikeya Dwivedi
2022-11-15 0:01 ` [PATCH bpf-next v1 1/7] bpf: Refactor ARG_PTR_TO_DYNPTR checks into process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-15 4:15 ` Joanne Koong
2022-11-15 0:01 ` [PATCH bpf-next v1 2/7] bpf: Propagate errors from process_* checks in check_func_arg Kumar Kartikeya Dwivedi
2022-11-15 3:53 ` Joanne Koong
2022-11-15 0:01 ` [PATCH bpf-next v1 3/7] bpf: Rework process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-16 18:04 ` Joanne Koong
2022-11-17 21:11 ` David Vernet
2022-11-20 18:06 ` Kumar Kartikeya Dwivedi
2022-11-20 18:16 ` David Vernet
2022-11-15 0:01 ` [PATCH bpf-next v1 4/7] bpf: Rework check_func_arg_reg_off Kumar Kartikeya Dwivedi
2022-11-15 18:24 ` Joanne Koong
2022-11-17 23:42 ` David Vernet
2022-11-20 18:41 ` Kumar Kartikeya Dwivedi
2022-11-21 5:39 ` David Vernet
2022-11-15 0:01 ` [PATCH bpf-next v1 5/7] bpf: Move PTR_TO_STACK alignment check to process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-15 18:29 ` Joanne Koong
2022-11-17 23:49 ` David Vernet
2022-11-20 19:10 ` Kumar Kartikeya Dwivedi
2022-11-20 19:40 ` Alexei Starovoitov
2022-11-20 21:02 ` Kumar Kartikeya Dwivedi
2022-11-21 7:27 ` David Vernet
2022-12-07 20:41 ` Kumar Kartikeya Dwivedi
2022-11-15 0:01 ` [PATCH bpf-next v1 6/7] bpf: Use memmove for bpf_dynptr_{read,write} Kumar Kartikeya Dwivedi
2022-11-17 23:51 ` David Vernet
2022-11-15 0:01 ` [PATCH bpf-next v1 7/7] selftests/bpf: Add test for dynptr reinit in user_ringbuf callback Kumar Kartikeya Dwivedi
2022-11-15 18:36 ` Joanne Koong
2022-11-15 19:41 ` Kumar Kartikeya Dwivedi [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=20221115194113.ag6pocm2hvrskd3i@apollo \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=joannelkoong@gmail.com \
--cc=martin.lau@kernel.org \
--cc=void@manifault.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