Re: [RFC bpf-next 1/2] bpf: Fail uprobe multi link with negative offset

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

 



On Thu, Dec 14, 2023 at 1:07 AM Jiri Olsa <olsajiri@xxxxxxxxx> wrote:
>
> On Wed, Dec 13, 2023 at 03:43:04PM -0800, Andrii Nakryiko wrote:
> > On Wed, Dec 13, 2023 at 6:12 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> > >
> > > Currently the __uprobe_register will return 0 (success) when called with
> > > negative offset. The reason is that the call to register_for_each_vma and
> > > then build_map_info won't return error for negative offset. They just won't
> > > do anything - no matching vma is found so there's no registered breakpoint
> > > for the uprobe.
> > >
> > > I don't think we can change the behaviour of __uprobe_register and fail
> > > for negative uprobe offset, because apps might depend on that already.
> > >
> > > But I think we can still make the change and check for it on bpf multi
> > > link syscall level.
> > >
> > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> > > ---
> > >  kernel/trace/bpf_trace.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > > index 774cf476a892..0dbf8d9b3ace 100644
> > > --- a/kernel/trace/bpf_trace.c
> > > +++ b/kernel/trace/bpf_trace.c
> > > @@ -3397,6 +3397,11 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
> > >                         goto error_free;
> > >                 }
> > >
> > > +               if (uprobes[i].offset < 0) {
> >
> > offset in UAPI is defined as unsigned, so how can it be negative?
>
> right, but then it's passed to uprobe_register_refctr as loff_t which is 'long long'

ah, so it's not rejected because uprobe_register expects signed offset
(for some reason...) and it only does

if (offset > i_size_read(inode))

got it, thanks.

>
> jirka
>
> >
> > > +                       err = -EINVAL;
> > > +                       goto error_free;
> > > +               }
> > > +
> > >                 uprobes[i].link = link;
> > >
> > >                 if (flags & BPF_F_UPROBE_MULTI_RETURN)
> > > --
> > > 2.43.0
> > >





[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