| From 5dca2f5212b5d1a2b58607986b219bf60db9a07b Mon Sep 17 00:00:00 2001 |
| From: Ursula Braun <ubraun@linux.ibm.com> |
| Date: Tue, 29 Oct 2019 12:41:26 +0100 |
| Subject: [PATCH] net/smc: fix refcounting for non-blocking connect() |
| |
| commit 301428ea3708188dc4a243e6e6b46c03b46a0fbc upstream. |
| |
| 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> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c |
| index fe4bdec855be..7c4d59524c58 100644 |
| --- a/net/smc/af_smc.c |
| +++ b/net/smc/af_smc.c |
| @@ -697,8 +697,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); |
| |
| @@ -843,6 +841,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; |
| -- |
| 2.7.4 |
| |