Re: [PATCH v6 bpf-next 08/11] bpf: Add bpf_perf_link_fill_common()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 7, 2023 at 6:00 AM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
>
> On Wed, Jun 28, 2023 at 4:53 AM Yafang Shao <laoar.shao@xxxxxxxxx> wrote:
> >
> > Add a new helper bpf_perf_link_fill_common(), which will be used by
> > perf_link based tracepoint, kprobe and uprobe.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
> > ---
> >  kernel/bpf/syscall.c | 34 ++++++++++++++++++++++++++++++++++
> >  1 file changed, 34 insertions(+)
> >
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index 4aa6e5776a04..72de91beabbc 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -3364,6 +3364,40 @@ static void bpf_perf_link_dealloc(struct bpf_link *link)
> >         kfree(perf_link);
> >  }
> >
> > +static int bpf_perf_link_fill_common(const struct perf_event *event,
> > +                                    char __user *uname, u32 ulen,
> > +                                    u64 *probe_offset, u64 *probe_addr,
> > +                                    u32 *fd_type)
> > +{
> > +       const char *buf;
> > +       u32 prog_id;
> > +       size_t len;
> > +       int err;
> > +
> > +       if (!ulen ^ !uname)
> > +               return -EINVAL;
> > +       if (!uname)
> > +               return 0;
> > +
> > +       err = bpf_get_perf_event_info(event, &prog_id, fd_type, &buf,
> > +                                     probe_offset, probe_addr);
> > +       if (err)
> > +               return err;
> > +
> > +       len = strlen(buf);
> > +       if (buf) {
>
> if buf is NULL, strlen above will crash, so you need to calculate len
> inside this if branch

Nice catch. Will fix it.

-- 
Regards
Yafang





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux