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] [day] [month] [year] [list]
Message-ID: <CAM9d7chEOJJTX3F-5Nzy+BBpr5dBnayHDx9MOSmkC0axrttzJQ@mail.gmail.com>
Date:   Wed, 7 Sep 2022 10:51:27 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        Jiri Olsa <jolsa@...nel.org>, Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        LKML <linux-kernel@...r.kernel.org>,
        linux-perf-users <linux-perf-users@...r.kernel.org>,
        Marco Elver <elver@...gle.com>, Song Liu <song@...nel.org>
Subject: Re: [PATCH v3] perf test: Skip sigtrap test on old kernels

Hi Ian,

On Wed, Sep 7, 2022 at 8:48 AM Ian Rogers <irogers@...gle.com> wrote:
>
> On Wed, Sep 7, 2022 at 12:12 AM Namhyung Kim <namhyung@...nel.org> wrote:
> >
> > If it runs on an old kernel, perf_event_open would fail because of the
> > new fields sigtrap and sig_data.  Just skipping the test could miss an
> > actual bug in the kernel.
> >
> > Let's check BTF if it has the perf_event_attr.sigtrap field.
> >
> > Cc: Marco Elver <elver@...gle.com>
> > Acked-by: Song Liu <song@...nel.org>
> > Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> > ---
> > * move #include under #ifdef
> > * return true when BPF is not supported
> > * update comment
> >
> >  tools/perf/tests/sigtrap.c | 50 +++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 49 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/tests/sigtrap.c b/tools/perf/tests/sigtrap.c
> > index e32ece90e164..cdf75eab6a8a 100644
> > --- a/tools/perf/tests/sigtrap.c
> > +++ b/tools/perf/tests/sigtrap.c
> > @@ -54,6 +54,48 @@ static struct perf_event_attr make_event_attr(void)
> >         return attr;
> >  }
> >
> > +#ifdef HAVE_BPF_SKEL
> > +#include <bpf/btf.h>
> > +
> > +static bool attr_has_sigtrap(void)
> > +{
> > +       bool ret = false;
> > +       struct btf *btf;
> > +       const struct btf_type *t;
> > +       const struct btf_member *m;
> > +       const char *name;
> > +       int i, id;
> > +
> > +       btf = btf__load_vmlinux_btf();
> > +       if (btf == NULL) {
> > +               /* should be an old kernel */
> > +               return false;
> > +       }
> > +
> > +       id = btf__find_by_name_kind(btf, "perf_event_attr", BTF_KIND_STRUCT);
> > +       if (id < 0)
> > +               goto out;
> > +
> > +       t = btf__type_by_id(btf, id);
> > +       for (i = 0, m = btf_members(t); i < btf_vlen(t); i++, m++) {
> > +               name = btf__name_by_offset(btf, m->name_off);
> > +               if (!strcmp(name, "sigtrap")) {
> > +                       ret = true;
> > +                       break;
> > +               }
> > +       }
> > +out:
> > +       btf__free(btf);
> > +       return ret;
> > +}
> > +#else  /* !HAVE_BPF_SKEL */
> > +static bool attr_has_sigtrap(void)
> > +{
> > +       /* to maintain current behavior */
>
> nit: I don't think this comment will age well and the behavior of the
> function is a bit counterintuitive. Perhaps:
>
> /* If we don't have libbpf then guess we're on a newer kernel with
> sigtrap support. This will mean the test will fail on older kernels.
> */

Thanks for the clarification, will update!

Namhyung

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ