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: <CAEf4BzZUN-kH8LzPp76BHW-8iBX=QUKCHmpxid0hxapbZ6t9rw@mail.gmail.com>
Date:   Mon, 27 Jul 2020 15:02:18 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Song Liu <song@...nel.org>
Cc:     Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf 2/2] selftests/bpf: extend map-in-map selftest to
 detect memory leaks

On Mon, Jul 27, 2020 at 1:53 PM Song Liu <song@...nel.org> wrote:
>
> On Thu, Jul 23, 2020 at 6:17 PM Andrii Nakryiko <andriin@...com> wrote:
> >
> > Add test validating that all inner maps are released properly after skeleton
> > is destroyed. To ensure determinism, trigger kernel-size synchronize_rcu()
> > before checking map existence by their IDs.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@...com>
> > ---
> >  .../selftests/bpf/prog_tests/btf_map_in_map.c | 104 +++++++++++++++---
> >  1 file changed, 91 insertions(+), 13 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > index f7ee8fa377ad..043e8ffe03d1 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
> > @@ -5,10 +5,50 @@
> >
> >  #include "test_btf_map_in_map.skel.h"
> >
> > +static int duration;
> > +
> > +int bpf_map_id(struct bpf_map *map)
> Should this return __u32?

yeah, probably, will change

>
> > +{
> > +       struct bpf_map_info info;
> > +       __u32 info_len = sizeof(info);
> > +       int err;
> > +
> > +       memset(&info, 0, info_len);
> > +       err = bpf_obj_get_info_by_fd(bpf_map__fd(map), &info, &info_len);
> > +       if (err)
> > +               return 0;
> > +       return info.id;
> > +}
> > +
> > +int kern_sync_rcu() {
>
> int kern_sync_rcu(void)
> {
> ...
>
> A comment for this function would be nice too.

Sure.

>
> > +       int inner_map_fd, outer_map_fd, err, zero = 0;
> > +
> > +       inner_map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, 4, 4, 1, 0);
> > +       if (CHECK(inner_map_fd < 0, "inner_map_create", "failed %d\n", -errno))
> > +               return -1;
> > +
> > +       outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
> > +                                            sizeof(int), inner_map_fd, 1, 0);
> > +       if (CHECK(outer_map_fd < 0, "outer_map_create", "failed %d\n", -errno)) {
> > +               close(inner_map_fd);
> > +               return -1;
> > +       }
> > +
> > +       err = bpf_map_update_elem(outer_map_fd, &zero, &inner_map_fd, 0);
> > +       if (err)
> > +               err = -errno;
> > +       CHECK(err, "outer_map_update", "failed %d\n", err);
> > +       close(inner_map_fd);
> > +       close(outer_map_fd);
> > +       return err;
> > +}
> > +
> >  void test_btf_map_in_map(void)
> >  {
> > -       int duration = 0, err, key = 0, val;
> > +       int err, key = 0, val, i;
> >         struct test_btf_map_in_map* skel;
> > +       int outer_arr_fd, outer_hash_fd;
> > +       int fd, map1_fd, map2_fd, map1_id, map2_id;
> nit: reverse Christmas tree.

We don't enforce that and it hasn't been a requirement for a long
time. It's better to minimize a code churn rather than preserving
pretty line ordering.


>
> >
> >         skel = test_btf_map_in_map__open_and_load();
> >         if (CHECK(!skel, "skel_open", "failed to open&load skeleton\n"))
> > @@ -18,32 +58,70 @@ void test_btf_map_in_map(void)
> >         if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
> >                 goto cleanup;
> >

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ