summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUrsula Braun <ubraun@linux.ibm.com>2019-10-29 07:41:26 -0400
committerDavid S. Miller <davem@davemloft.net>2019-10-29 21:09:50 -0400
commit301428ea3708188dc4a243e6e6b46c03b46a0fbc (patch)
treed4deee3abb8aa430a567609272aa9df7369c21d3
parentad9bd8daf2f9938572b0604e1280fefa8f338581 (diff)
net/smc: fix refcounting for non-blocking connect()
If a nonblocking socket is immediately closed after connect(), the connect worker may not have started. This results in a refcount problem, since sock_hold() is called from the connect worker. This patch moves the sock_hold in front of the connect worker scheduling. Reported-by: syzbot+4c063e6dea39e4b79f29@syzkaller.appspotmail.com Fixes: 50717a37db03 ("net/smc: nonblocking connect rework") Reviewed-by: Karsten Graul <kgraul@linux.ibm.com> Signed-off-by: Ursula Braun <ubraun@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/smc/af_smc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index cea3c36ea0da..47946f489fd4 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -707,8 +707,6 @@ static int __smc_connect(struct smc_sock *smc)
707 int smc_type; 707 int smc_type;
708 int rc = 0; 708 int rc = 0;
709 709
710 sock_hold(&smc->sk); /* sock put in passive closing */
711
712 if (smc->use_fallback) 710 if (smc->use_fallback)
713 return smc_connect_fallback(smc, smc->fallback_rsn); 711 return smc_connect_fallback(smc, smc->fallback_rsn);
714 712
@@ -853,6 +851,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
853 rc = kernel_connect(smc->clcsock, addr, alen, flags); 851 rc = kernel_connect(smc->clcsock, addr, alen, flags);
854 if (rc && rc != -EINPROGRESS) 852 if (rc && rc != -EINPROGRESS)
855 goto out; 853 goto out;
854
855 sock_hold(&smc->sk); /* sock put in passive closing */
856 if (flags & O_NONBLOCK) { 856 if (flags & O_NONBLOCK) {
857 if (schedule_work(&smc->connect_work)) 857 if (schedule_work(&smc->connect_work))
858 smc->connect_nonblock = 1; 858 smc->connect_nonblock = 1;