From: Jiri Olsa <olsajiri@gmail.com>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: bpf@vger.kernel.org, andrii@kernel.org, daniel@iogearbox.net,
ast@kernel.org
Subject: Re: [PATCH bpf-next v1 1/2] bpf: Fix ref_obj_id for dynptr data slices in verifier
Date: Thu, 21 Jul 2022 09:50:57 +0200 [thread overview]
Message-ID: <YtkFYeQwjqSZ2GOW@krava> (raw)
In-Reply-To: <20220721024821.251231-1-joannelkoong@gmail.com>
On Wed, Jul 20, 2022 at 07:48:20PM -0700, Joanne Koong wrote:
> When a data slice is obtained from a dynptr (through the bpf_dynptr_data API),
> the ref obj id of the dynptr must be found and then associated with the data
> slice.
>
> The ref obj id of the dynptr must be found *before* the caller saved regs are
> reset. Without this fix, the ref obj id tracking is not correct for
> dynptrs that are at an offset from the frame pointer.
>
> Please also note that the data slice's ref obj id must be assigned after the
> ret types are parsed, since RET_PTR_TO_ALLOC_MEM-type return regs get
> zero-marked.
>
> Fixes: 34d4ef5775f7("bpf: Add dynptr data slices");
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
LGTM
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> kernel/bpf/verifier.c | 30 +++++++++++++++++-------------
> 1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index c59c3df0fea6..00f9b5a77734 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -7341,6 +7341,22 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
> }
> }
> break;
> + case BPF_FUNC_dynptr_data:
> + /* Find the id of the dynptr we're tracking the reference of.
> + * We must do this before we reset caller saved regs.
> + *
> + * Please note as well that meta.ref_obj_id after the check_func_arg() calls doesn't
> + * already contain the dynptr ref obj id, since dynptrs are stored on the stack.
> + */
> + for (i = 0; i < MAX_BPF_FUNC_REG_ARGS; i++) {
> + if (arg_type_is_dynptr(fn->arg_type[i])) {
> + if (meta.ref_obj_id) {
> + verbose(env, "verifier internal error: multiple refcounted args in func\n");
> + return -EFAULT;
> + }
> + meta.ref_obj_id = stack_slot_get_id(env, ®s[BPF_REG_1 + i]);
> + }
> + }
> }
>
> if (err)
> @@ -7470,20 +7486,8 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
> /* For release_reference() */
> regs[BPF_REG_0].ref_obj_id = id;
> } else if (func_id == BPF_FUNC_dynptr_data) {
> - int dynptr_id = 0, i;
> -
> - /* Find the id of the dynptr we're acquiring a reference to */
> - for (i = 0; i < MAX_BPF_FUNC_REG_ARGS; i++) {
> - if (arg_type_is_dynptr(fn->arg_type[i])) {
> - if (dynptr_id) {
> - verbose(env, "verifier internal error: multiple dynptr args in func\n");
> - return -EFAULT;
> - }
> - dynptr_id = stack_slot_get_id(env, ®s[BPF_REG_1 + i]);
> - }
> - }
> /* For release_reference() */
> - regs[BPF_REG_0].ref_obj_id = dynptr_id;
> + regs[BPF_REG_0].ref_obj_id = meta.ref_obj_id;
> }
>
> do_refine_retval_range(regs, fn->ret_type, func_id, &meta);
> --
> 2.30.2
>
next prev parent reply other threads:[~2022-07-21 7:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 2:48 [PATCH bpf-next v1 1/2] bpf: Fix ref_obj_id for dynptr data slices in verifier Joanne Koong
2022-07-21 2:48 ` [PATCH bpf-next v1 2/2] selftests/bpf: add extra test for using dynptr data slice after release Joanne Koong
2022-07-21 17:27 ` Hao Luo
2022-07-22 16:40 ` Joanne Koong
2022-07-22 19:25 ` Hao Luo
2022-07-22 19:33 ` Hao Luo
2022-07-21 7:50 ` Jiri Olsa [this message]
2022-07-21 17:02 ` [PATCH bpf-next v1 1/2] bpf: Fix ref_obj_id for dynptr data slices in verifier Martin KaFai Lau
2022-07-22 16:52 ` Joanne Koong
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=YtkFYeQwjqSZ2GOW@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=joannelkoong@gmail.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