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]
Message-ID: <CAEf4BzYh4kSOJmjVrmZ2VLiO9GsZPiSpFXkXevy74_ByS6S12A@mail.gmail.com>
Date:   Mon, 5 Oct 2020 14:28:10 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Hangbin Liu <liuhangbin@...il.com>
Cc:     bpf <bpf@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>,
        Networking <netdev@...r.kernel.org>,
        Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCHv2 bpf 3/3] selftest/bpf: test pinning map with reused map fd

On Sat, Oct 3, 2020 at 1:55 AM Hangbin Liu <liuhangbin@...il.com> wrote:
>
> This add a test to make sure that we can still pin maps with
> reused map fd.
>
> Signed-off-by: Hangbin Liu <liuhangbin@...il.com>
> ---
>  .../selftests/bpf/prog_tests/pinning.c        | 46 ++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/pinning.c b/tools/testing/selftests/bpf/prog_tests/pinning.c
> index 041952524c55..299f99ef92b2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/pinning.c
> +++ b/tools/testing/selftests/bpf/prog_tests/pinning.c
> @@ -37,7 +37,7 @@ void test_pinning(void)
>         struct stat statbuf = {};
>         struct bpf_object *obj;
>         struct bpf_map *map;
> -       int err;
> +       int err, map_fd;
>         DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
>                 .pin_root_path = custpath,
>         );
> @@ -213,6 +213,50 @@ void test_pinning(void)
>         if (CHECK(err, "stat custpinpath", "err %d errno %d\n", err, errno))
>                 goto out;
>
> +       /* remove the custom pin path to re-test it with reuse fd below */
> +       err = unlink(custpinpath);
> +       if (CHECK(err, "unlink custpinpath", "err %d errno %d\n", err, errno))
> +               goto out;
> +
> +       err = rmdir(custpath);
> +       if (CHECK(err, "rmdir custpindir", "err %d errno %d\n", err, errno))
> +               goto out;
> +
> +       bpf_object__close(obj);
> +
> +       /* test pinning at custom path with reuse fd */
> +       obj = bpf_object__open_file(file, NULL);
> +       if (CHECK_FAIL(libbpf_get_error(obj))) {

please use CHECK, might try new ASSERT_OK_PTR(obj, "obj_open") as well

> +               obj = NULL;
> +               goto out;
> +       }
> +
> +       map_fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(__u32),
> +                               sizeof(__u64), 1, 0);
> +       if (CHECK(map_fd < 0, "create pinmap manually", "fd %d\n", map_fd))
> +               goto out;
> +
> +       map = bpf_object__find_map_by_name(obj, "pinmap");
> +       if (CHECK(!map, "find map", "NULL map"))

here and below you are not closing map_fd on error

> +               goto out;
> +
> +       err = bpf_map__reuse_fd(map, map_fd);
> +       if (CHECK(err, "reuse pinmap fd", "err %d errno %d\n", err, errno))
> +               goto out;
> +
> +       err = bpf_map__set_pin_path(map, custpinpath);
> +       if (CHECK(err, "set pin path", "err %d errno %d\n", err, errno))
> +               goto out;
> +
> +       err = bpf_object__load(obj);
> +       if (CHECK(err, "custom load", "err %d errno %d\n", err, errno))
> +               goto out;
> +
> +       /* check that pinmap was pinned at the custom path */
> +       err = stat(custpinpath, &statbuf);
> +       if (CHECK(err, "stat custpinpath", "err %d errno %d\n", err, errno))
> +               goto out;
> +
>  out:
>         unlink(pinpath);
>         unlink(nopinpath);
> --
> 2.25.4
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ