Skip to content

Commit

Permalink
net/smc: fix refcounting for non-blocking connect()
Browse files Browse the repository at this point in the history
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: 50717a3 ("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>
  • Loading branch information
Ursula Braun authored and David S. Miller committed Oct 30, 2019
1 parent ad9bd8d commit 301428e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/smc/af_smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,6 @@ static int __smc_connect(struct smc_sock *smc)
int smc_type;
int rc = 0;

sock_hold(&smc->sk); /* sock put in passive closing */

if (smc->use_fallback)
return smc_connect_fallback(smc, smc->fallback_rsn);

Expand Down Expand Up @@ -853,6 +851,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
rc = kernel_connect(smc->clcsock, addr, alen, flags);
if (rc && rc != -EINPROGRESS)
goto out;

sock_hold(&smc->sk); /* sock put in passive closing */
if (flags & O_NONBLOCK) {
if (schedule_work(&smc->connect_work))
smc->connect_nonblock = 1;
Expand Down

0 comments on commit 301428e

Please sign in to comment.