bpf: net: Avoid copying sk_user_data of reuseport_array during sk_clone
authorMartin KaFai Lau <kafai@fb.com>
Thu, 9 Jul 2020 06:11:04 +0000 (23:11 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 9 Jul 2020 20:03:31 +0000 (22:03 +0200)
commitf3dda7a679df183e798b86e7b6ec05ab35476de3
tree5546f846bf465d85da12656e19b9fa40d20c180b
parent365f9ae4ee36037e2a9268fe7296065356840b4c
bpf: net: Avoid copying sk_user_data of reuseport_array during sk_clone

It makes little sense for copying sk_user_data of reuseport_array during
sk_clone_lock().  This patch reuses the SK_USER_DATA_NOCOPY bit introduced in
commit f1ff5ce2cd5e ("net, sk_msg: Clear sk_user_data pointer on clone if tagged").
It is used to mark the sk_user_data is not supposed to be copied to its clone.

Although the cloned sk's sk_user_data will not be used/freed in
bpf_sk_reuseport_detach(), this change can still allow the cloned
sk's sk_user_data to be used by some other means.

Freeing the reuseport_array's sk_user_data does not require a rcu grace
period.  Thus, the existing rcu_assign_sk_user_data_nocopy() is not
used.

Fixes: 5dc4c4b7d4e8 ("bpf: Introduce BPF_MAP_TYPE_REUSEPORT_SOCKARRAY")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/20200709061104.4018798-1-kafai@fb.com
kernel/bpf/reuseport_array.c