summaryrefslogtreecommitdiff
path: root/net/core/sock.c
diff options
context:
space:
mode:
authorJoe Stringer <joe@wand.net.nz>2020-03-30 01:53:40 +0300
committerAlexei Starovoitov <ast@kernel.org>2020-03-30 23:45:05 +0300
commit7ae215d23c12a939005f35d1848ca55b6109b9c0 (patch)
treebc88bf441433f5bf7a3d66610adb5d1ad1707390 /net/core/sock.c
parent71489e21d720a09388b565d60ef87ae993c10528 (diff)
downloadlinux-7ae215d23c12a939005f35d1848ca55b6109b9c0.tar.xz
bpf: Don't refcount LISTEN sockets in sk_assign()
Avoid taking a reference on listen sockets by checking the socket type in the sk_assign and in the corresponding skb_steal_sock() code in the the transport layer, and by ensuring that the prefetch free (sock_pfree) function uses the same logic to check whether the socket is refcounted. Suggested-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Joe Stringer <joe@wand.net.nz> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20200329225342.16317-4-joe@wand.net.nz
Diffstat (limited to 'net/core/sock.c')
-rw-r--r--net/core/sock.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 87e3a03c9056..da32d9b6d09f 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2077,7 +2077,8 @@ EXPORT_SYMBOL(sock_efree);
#ifdef CONFIG_INET
void sock_pfree(struct sk_buff *skb)
{
- sock_gen_put(skb->sk);
+ if (sk_is_refcounted(skb->sk))
+ sock_gen_put(skb->sk);
}
EXPORT_SYMBOL(sock_pfree);
#endif /* CONFIG_INET */