bpf: fix struct htab_elem layout
authorAlexei Starovoitov <ast@fb.com>
Fri, 10 May 2019 02:33:53 +0000 (19:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 May 2019 17:43:40 +0000 (19:43 +0200)
commitaad9db666c2546b38c8c10f424a90c2f38b65493
treef5f2334c0c7712687d1fdaa16c925c9aa0ef504d
parent9b04b51089ceeccde8baafec484e1815cec5b18d
bpf: fix struct htab_elem layout

commit 9f691549f76d488a0c74397b3e51e943865ea01f upstream.

when htab_elem is removed from the bucket list the htab_elem.hash_node.next
field should not be overridden too early otherwise we have a tiny race window
between lookup and delete.
The bug was discovered by manual code analysis and reproducible
only with explicit udelay() in lookup_elem_raw().

Fixes: 6c9059817432 ("bpf: pre-allocate hash map elements")
Reported-by: Jonathan Perry <jonperry@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chenbo Feng <fengc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/hashtab.c