]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, sockmap: fix map elem deletion race with smap_stop_sock
authorDaniel Borkmann <daniel@iogearbox.net>
Thu, 16 Aug 2018 19:49:09 +0000 (21:49 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 16 Aug 2018 21:58:08 +0000 (14:58 -0700)
commitfeda7dd03e28c709f65c64b8456a66cdef5dbd3b
tree16e5a7b40f898efe4a8976cb2e179ec2f1b7ce3b
parentd8df2d00681df637c4fd2b6edfedc2111e23c0ec
bpf, sockmap: fix map elem deletion race with smap_stop_sock

The smap_start_sock() and smap_stop_sock() are each protected under
the sock->sk_callback_lock from their call-sites except in the case
of sock_map_delete_elem() where we drop the old socket from the map
slot. This is racy because the same sock could be part of multiple
sock maps, so we run smap_stop_sock() in parallel, and given at that
point psock->strp_enabled might be true on both CPUs, we might for
example wrongly restore the sk->sk_data_ready / sk->sk_write_space.
Therefore, hold the sock->sk_callback_lock as well on delete. Looks
like ceebdc27c8d6 ("bpf: sockmap, remove STRPARSER map_flags and add
multi-map support") had this right, but later on 7275ffb3592a ("bpf:
sockhash fix omitted bucket lock in sock_close") removed it again
from delete leaving this smap_stop_sock() instance unprotected.

Fixes: 7275ffb3592a ("bpf: sockhash fix omitted bucket lock in sock_close")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/sockmap.c