lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 3 Nov 2022 23:03:01 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Jiri Olsa <olsajiri@...il.com>
Cc:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Song Liu <songliubraving@...com>,
        Peter Zijlstra <peterz@...radead.org>,
        Martin KaFai Lau <kafai@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>, Hao Luo <haoluo@...gle.com>,
        Stanislav Fomichev <sdf@...gle.com>,
        LKML <linux-kernel@...r.kernel.org>, bpf@...r.kernel.org,
        Steven Rostedt <rostedt@...dmis.org>,
        Ingo Molnar <mingo@...nel.org>,
        Arnaldo Carvalho de Melo <acme@...nel.org>
Subject: Re: [PATCH bpf-next 1/3] perf/core: Prepare sample data before
 calling BPF

Hi Jiri,

On Tue, Nov 1, 2022 at 3:03 AM Jiri Olsa <olsajiri@...il.com> wrote:
>
> On Mon, Oct 31, 2022 at 10:23:38PM -0700, Namhyung Kim wrote:
> > To allow bpf overflow handler to access the perf sample data, it needs to
> > prepare missing but requested data before calling the handler.
> >
> > I'm taking a conservative approach to allow a list of sample formats only
> > instead of allowing them all.  For now, IP and ADDR data are allowed and
> > I think it's good enough to build and verify general BPF-based sample
> > filters for perf events.
> >
> > Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> > ---
> >  kernel/events/core.c | 40 +++++++++++++++++++++++++++++++---------
> >  1 file changed, 31 insertions(+), 9 deletions(-)
> >
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index aefc1e08e015..519f30c33a24 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -7329,8 +7329,10 @@ void perf_prepare_sample(struct perf_event_header *header,
> >       filtered_sample_type = sample_type & ~data->sample_flags;
> >       __perf_event_header__init_id(header, data, event, filtered_sample_type);
> >
> > -     if (sample_type & (PERF_SAMPLE_IP | PERF_SAMPLE_CODE_PAGE_SIZE))
> > -             data->ip = perf_instruction_pointer(regs);
> > +     if (sample_type & (PERF_SAMPLE_IP | PERF_SAMPLE_CODE_PAGE_SIZE)) {
> > +             if (filtered_sample_type & PERF_SAMPLE_IP)
> > +                     data->ip = perf_instruction_pointer(regs);
> > +     }
> >
> >       if (sample_type & PERF_SAMPLE_CALLCHAIN) {
> >               int size = 1;
> > @@ -10006,6 +10008,32 @@ static void perf_event_free_filter(struct perf_event *event)
> >  }
> >
> >  #ifdef CONFIG_BPF_SYSCALL
> > +static void bpf_prepare_sample(struct bpf_prog *prog,
> > +                            struct perf_event *event,
> > +                            struct perf_sample_data *data,
> > +                            struct pt_regs *regs)
> > +{
> > +     u64 filtered_sample_type;
> > +
> > +     filtered_sample_type = event->attr.sample_type & ~data->sample_flags;
>
> could we add the same comment in here as is in perf_prepare_sample
>
>         /*
>          * Clear the sample flags that have already been done by the
>          * PMU driver.
>          */
>
> it took me while to recall while we set addr to 0 in here ;-)

Sorry about that! :)  I'll add the comment.

Thanks,
Namhyung


>
> > +
> > +     if (prog->call_get_stack &&
> > +         (filtered_sample_type & PERF_SAMPLE_CALLCHAIN)) {
> > +             data->callchain = perf_callchain(event, regs);
> > +             data->sample_flags |= PERF_SAMPLE_CALLCHAIN;
> > +     }
> > +
> > +     if (filtered_sample_type & PERF_SAMPLE_IP) {
> > +             data->ip = perf_instruction_pointer(regs);
> > +             data->sample_flags |= PERF_SAMPLE_IP;
> > +     }
> > +
> > +     if (filtered_sample_type & PERF_SAMPLE_ADDR) {
> > +             data->addr = 0;
> > +             data->sample_flags |= PERF_SAMPLE_ADDR;
> > +     }
> > +}
> > +
> >  static void bpf_overflow_handler(struct perf_event *event,
> >                                struct perf_sample_data *data,
> >                                struct pt_regs *regs)
> > @@ -10023,13 +10051,7 @@ static void bpf_overflow_handler(struct perf_event *event,
> >       rcu_read_lock();
> >       prog = READ_ONCE(event->prog);
> >       if (prog) {
> > -             if (prog->call_get_stack &&
> > -                 (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) &&
> > -                 !(data->sample_flags & PERF_SAMPLE_CALLCHAIN)) {
> > -                     data->callchain = perf_callchain(event, regs);
> > -                     data->sample_flags |= PERF_SAMPLE_CALLCHAIN;
> > -             }
> > -
> > +             bpf_prepare_sample(prog, event, data, regs);
> >               ret = bpf_prog_run(prog, &ctx);
> >       }
> >       rcu_read_unlock();
> > --
> > 2.38.1.273.g43a17bfeac-goog
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ