Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Fix use of sk->sk_reuseport from sk_assign

In testing, we found that for request sockets the sk->sk_reuseport field
may yet be uninitialized, which caused bpf_sk_assign() to randomly
succeed or return -ESOCKTNOSUPPORT when handling the forward ACK in a
three-way handshake.

Fix it by only applying the reuseport check for full sockets.

Fixes: cf7fbe660f2d ("bpf: Add socket assign support")
Signed-off-by: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200408033540.10339-1-joe@wand.net.nz

authored by

Joe Stringer and committed by
Daniel Borkmann
8e368dc7 eb203f4b

+1 -1
+1 -1
net/core/filter.c
··· 5925 5925 return -EOPNOTSUPP; 5926 5926 if (unlikely(dev_net(skb->dev) != sock_net(sk))) 5927 5927 return -ENETUNREACH; 5928 - if (unlikely(sk->sk_reuseport)) 5928 + if (unlikely(sk_fullsock(sk) && sk->sk_reuseport)) 5929 5929 return -ESOCKTNOSUPPORT; 5930 5930 if (sk_is_refcounted(sk) && 5931 5931 unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))