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]
Date:   Thu, 29 Oct 2020 15:24:50 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...omium.org>,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] libbpf hashmap: Avoid undefined behavior in hash_bits

On Thu, Oct 29, 2020 at 3:10 PM Ian Rogers <irogers@...gle.com> wrote:
>
> If bits is 0, the case when the map is empty, then the >> is the size of
> the register which is undefined behavior - on x86 it is the same as a
> shift by 0.
> Avoid calling hash_bits with bits == 0 by adding additional empty
> hashmap tests.
>
> Suggested-by: Andrii Nakryiko <andriin@...com>,
> Suggested-by: Song Liu <songliubraving@...com>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---

I didn't realize you'd need to add three extra checks. If that's the
case, let's just add `if (!bits) return 0;` to hash_bits() and be done
with it. Please keep
hashmap__for_each_key_entry_safe/hashmap__for_each_key_entry changes,
they are ok regardless.

>  tools/lib/bpf/hashmap.c | 12 ++++++++++--
>  tools/lib/bpf/hashmap.h | 12 ++++++------
>  2 files changed, 16 insertions(+), 8 deletions(-)
>

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ