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: <CAEf4Bza+vB-rJD9NNphsU8UbiD06JH9wLzDvX5ZCKnLALSPNpw@mail.gmail.com>
Date:   Fri, 4 Feb 2022 14:55:16 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Mauricio Vásquez <mauricio@...volk.io>
Cc:     Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Quentin Monnet <quentin@...valent.com>
Subject: Re: [PATCH bpf-next] libbpf: Fix strict mode calculation

On Fri, Feb 4, 2022 at 2:05 PM Mauricio Vásquez <mauricio@...volk.io> wrote:
>
> The correct formula to get all possible values is
> ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) as stated in
> libbpf_set_strict_mode().
>
> Fixes: 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")
>
> Signed-off-by: Mauricio Vásquez <mauricio@...volk.io>
> ---
>  tools/bpf/bpftool/main.c                     |  6 +++++-
>  tools/testing/selftests/bpf/prog_tests/btf.c | 10 ++++++++--

please split changes to bpftool and separately selftests/bpf (and in
v2 you'll have a separate libbpf patch as well).

>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
> index 9d01fa9de033..c5b27e41d1e9 100644
> --- a/tools/bpf/bpftool/main.c
> +++ b/tools/bpf/bpftool/main.c
> @@ -483,8 +483,12 @@ int main(int argc, char **argv)
>                 /* Allow legacy map definitions for skeleton generation.
>                  * It will still be rejected if users use LIBBPF_STRICT_ALL
>                  * mode for loading generated skeleton.
> +                *
> +                * __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
> +                * get all possible values we compensate last +1, and then (2*x - 1)
> +                * to get the bit mask
>                  */
> -               mode = (__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
> +               mode = ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
>                 ret = libbpf_set_strict_mode(mode);
>                 if (ret)
>                         p_err("failed to enable libbpf strict mode: %d", ret);
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
> index 14f9b6136794..90d5cd4f504c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c
> @@ -4533,6 +4533,7 @@ static void do_test_file(unsigned int test_num)
>         struct btf_ext *btf_ext = NULL;
>         struct bpf_prog_info info = {};
>         struct bpf_object *obj = NULL;
> +       enum libbpf_strict_mode mode;
>         struct bpf_func_info *finfo;
>         struct bpf_program *prog;
>         __u32 info_len, rec_size;
> @@ -4560,8 +4561,13 @@ static void do_test_file(unsigned int test_num)
>         has_btf_ext = btf_ext != NULL;
>         btf_ext__free(btf_ext);
>
> -       /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
> -       libbpf_set_strict_mode((__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS);
> +       /* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps
> +        * __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
> +        * get all possible values we compensate last +1, and then (2*x - 1)
> +        * to get the bit mask
> +        */
> +       mode = ((__LIBBPF_STRICT_LAST - 1) * 2 - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS
> +       libbpf_set_strict_mode(mode);
>         obj = bpf_object__open(test->file);
>         err = libbpf_get_error(obj);
>         if (CHECK(err, "obj: %d", err))
> --
> 2.25.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ