Commit 301428ea authored by Ursula Braun's avatar Ursula Braun Committed by David S. Miller

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: 50717a37 ("net/smc: nonblocking connect rework")
Reviewed-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
Signed-off-by: default avatarUrsula Braun <ubraun@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ad9bd8da
...@@ -707,8 +707,6 @@ static int __smc_connect(struct smc_sock *smc) ...@@ -707,8 +707,6 @@ static int __smc_connect(struct smc_sock *smc)
int smc_type; int smc_type;
int rc = 0; int rc = 0;
sock_hold(&smc->sk); /* sock put in passive closing */
if (smc->use_fallback) if (smc->use_fallback)
return smc_connect_fallback(smc, smc->fallback_rsn); return smc_connect_fallback(smc, smc->fallback_rsn);
...@@ -853,6 +851,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr, ...@@ -853,6 +851,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
rc = kernel_connect(smc->clcsock, addr, alen, flags); rc = kernel_connect(smc->clcsock, addr, alen, flags);
if (rc && rc != -EINPROGRESS) if (rc && rc != -EINPROGRESS)
goto out; goto out;
sock_hold(&smc->sk); /* sock put in passive closing */
if (flags & O_NONBLOCK) { if (flags & O_NONBLOCK) {
if (schedule_work(&smc->connect_work)) if (schedule_work(&smc->connect_work))
smc->connect_nonblock = 1; smc->connect_nonblock = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment