On Thu, Apr 22, 2021 at 5:26 PM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > From: Alexei Starovoitov <ast@xxxxxxxxxx> > > 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@xxxxxxxxxx> > --- LGTM, see minor comments below. Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > 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; > +} [...]