bpf, sockmap: Use stricter sk state checks in sk_lookup_assign
authorJohn Fastabend <john.fastabend@gmail.com>
Wed, 3 Nov 2021 20:47:32 +0000 (13:47 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 8 Nov 2021 23:56:35 +0000 (00:56 +0100)
commit40a34121ac1dc52ed9cd34a8f4e48e32517a52fd
tree8e913e6d58d17d6ec21021ac48a05e5b636f615c
parent47b3708c6088a60e7dc3b809dbb0d4c46590b32f
bpf, sockmap: Use stricter sk state checks in sk_lookup_assign

In order to fix an issue with sockets in TCP sockmap redirect cases we plan
to allow CLOSE state sockets to exist in the sockmap. However, the check in
bpf_sk_lookup_assign() currently only invalidates sockets in the
TCP_ESTABLISHED case relying on the checks on sockmap insert to ensure we
never SOCK_CLOSE state sockets in the map.

To prepare for this change we flip the logic in bpf_sk_lookup_assign() to
explicitly test for the accepted cases. Namely, a tcp socket in TCP_LISTEN
or a udp socket in TCP_CLOSE state. This also makes the code more resilent
to future changes.

Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/20211103204736.248403-2-john.fastabend@gmail.com
include/linux/skmsg.h
net/core/filter.c
net/core/sock_map.c