[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzY5BrSOWj8zc+hBd5jm_p4OaH7gzR5voEwOwvQFPvBcPw@mail.gmail.com>
Date: Mon, 26 Apr 2021 09:51:30 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Kernel Team <kernel-team@...com>
Subject: Re: [PATCH v2 bpf-next 01/16] bpf: Introduce bpf_sys_bpf() helper and
program type.
On Thu, Apr 22, 2021 at 5:26 PM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> From: Alexei Starovoitov <ast@...nel.org>
>
> Add placeholders for bpf_sys_bpf() helper and new program type.
>
> v1->v2:
> - check that expected_attach_type is zero
> - allow more helper functions to be used in this program type, since they will
> only execute from user context via bpf_prog_test_run.
>
> Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> ---
LGTM, see minor comments below.
Acked-by: Andrii Nakryiko <andrii@...nel.org>
> include/linux/bpf.h | 10 +++++++
> include/linux/bpf_types.h | 2 ++
> include/uapi/linux/bpf.h | 8 +++++
> kernel/bpf/syscall.c | 54 ++++++++++++++++++++++++++++++++++
> net/bpf/test_run.c | 43 +++++++++++++++++++++++++++
> tools/include/uapi/linux/bpf.h | 8 +++++
> 6 files changed, 125 insertions(+)
>
[...]
> +
> +const struct bpf_func_proto * __weak
> +tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> +{
> +
extra empty line
> + return bpf_base_func_proto(func_id);
> +}
> +
> +static const struct bpf_func_proto *
> +syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
> +{
> + switch (func_id) {
> + case BPF_FUNC_sys_bpf:
> + return &bpf_sys_bpf_proto;
> + default:
> + return tracing_prog_func_proto(func_id, prog);
> + }
> +}
> +
[...]
> + if (ctx_size_in) {
> + ctx = kzalloc(ctx_size_in, GFP_USER);
> + if (!ctx)
> + return -ENOMEM;
> + if (copy_from_user(ctx, ctx_in, ctx_size_in)) {
> + err = -EFAULT;
> + goto out;
> + }
> + }
> + retval = bpf_prog_run_pin_on_cpu(prog, ctx);
> +
> + if (copy_to_user(&uattr->test.retval, &retval, sizeof(u32)))
> + err = -EFAULT;
is there a point in trying to do another copy_to_user if this fails?
I.e., why not goto out here?
> + if (ctx_size_in)
> + if (copy_to_user(ctx_in, ctx, ctx_size_in)) {
> + err = -EFAULT;
> + goto out;
> + }
> +out:
> + kfree(ctx);
> + return err;
> +}
[...]
Powered by blists - more mailing lists