netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Ursula Braun <ubraun@linux.ibm.com>,
	syzbot+96d3f9ff6a86d37e44c8@syzkaller.appspotmail.com,
	Karsten Graul <kgraul@linux.ibm.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-s390@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 117/187] net/smc: add fallback check to connect()
Date: Fri, 27 Dec 2019 12:39:45 -0500	[thread overview]
Message-ID: <20191227174055.4923-117-sashal@kernel.org> (raw)
In-Reply-To: <20191227174055.4923-1-sashal@kernel.org>

From: Ursula Braun <ubraun@linux.ibm.com>

[ Upstream commit 86434744fedf0cfe07a9eee3f4632c0e25c1d136 ]

FASTOPEN setsockopt() or sendmsg() may switch the SMC socket to fallback
mode. Once fallback mode is active, the native TCP socket functions are
called. Nevertheless there is a small race window, when FASTOPEN
setsockopt/sendmsg runs in parallel to a connect(), and switch the
socket into fallback mode before connect() takes the sock lock.
Make sure the SMC-specific connect setup is omitted in this case.

This way a syzbot-reported refcount problem is fixed, triggered by
different threads running non-blocking connect() and FASTOPEN_KEY
setsockopt.

Reported-by: syzbot+96d3f9ff6a86d37e44c8@syzkaller.appspotmail.com
Fixes: 6d6dd528d5af ("net/smc: fix refcount non-blocking connect() -part 2")
Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/smc/af_smc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 737b49909a7a..6a6d3b2aa5a9 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -854,6 +854,8 @@ static int smc_connect(struct socket *sock, struct sockaddr *addr,
 		goto out;
 
 	sock_hold(&smc->sk); /* sock put in passive closing */
+	if (smc->use_fallback)
+		goto out;
 	if (flags & O_NONBLOCK) {
 		if (schedule_work(&smc->connect_work))
 			smc->connect_nonblock = 1;
@@ -1716,8 +1718,6 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 		sk->sk_err = smc->clcsock->sk->sk_err;
 		sk->sk_error_report(sk);
 	}
-	if (rc)
-		return rc;
 
 	if (optlen < sizeof(int))
 		return -EINVAL;
@@ -1725,6 +1725,8 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 		return -EFAULT;
 
 	lock_sock(sk);
+	if (rc || smc->use_fallback)
+		goto out;
 	switch (optname) {
 	case TCP_ULP:
 	case TCP_FASTOPEN:
@@ -1736,15 +1738,14 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 			smc_switch_to_fallback(smc);
 			smc->fallback_rsn = SMC_CLC_DECL_OPTUNSUPP;
 		} else {
-			if (!smc->use_fallback)
-				rc = -EINVAL;
+			rc = -EINVAL;
 		}
 		break;
 	case TCP_NODELAY:
 		if (sk->sk_state != SMC_INIT &&
 		    sk->sk_state != SMC_LISTEN &&
 		    sk->sk_state != SMC_CLOSED) {
-			if (val && !smc->use_fallback)
+			if (val)
 				mod_delayed_work(system_wq, &smc->conn.tx_work,
 						 0);
 		}
@@ -1753,7 +1754,7 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 		if (sk->sk_state != SMC_INIT &&
 		    sk->sk_state != SMC_LISTEN &&
 		    sk->sk_state != SMC_CLOSED) {
-			if (!val && !smc->use_fallback)
+			if (!val)
 				mod_delayed_work(system_wq, &smc->conn.tx_work,
 						 0);
 		}
@@ -1764,6 +1765,7 @@ static int smc_setsockopt(struct socket *sock, int level, int optname,
 	default:
 		break;
 	}
+out:
 	release_sock(sk);
 
 	return rc;
-- 
2.20.1


  parent reply	other threads:[~2019-12-27 17:51 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191227174055.4923-1-sashal@kernel.org>
2019-12-27 17:37 ` [PATCH AUTOSEL 5.4 008/187] mwifiex: fix possible heap overflow in mwifiex_process_country_ie() Sasha Levin
2020-01-06 22:51   ` Brian Norris
2020-01-09 15:29     ` Sasha Levin
2020-01-09 17:33       ` Brian Norris
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 014/187] netfilter: ctnetlink: netns exit must wait for callbacks Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 017/187] netfilter: nf_tables_offload: Check for the NETDEV_UNREGISTER event Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 018/187] mwifiex: Fix heap overflow in mmwifiex_process_tdls_action_frame() Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 025/187] netfilter: nf_queue: enqueue skbs with NULL dst Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 033/187] netfilter: nft_set_rbtree: bogus lookup/get on consecutive elements in named sets Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 034/187] netfilter: nf_tables: validate NFT_SET_ELEM_INTERVAL_END Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 035/187] netfilter: nf_tables: validate NFT_DATA_VALUE after nft_data_init() Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 036/187] netfilter: nf_tables: skip module reference count bump on object updates Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 037/187] netfilter: nf_tables_offload: return EOPNOTSUPP if rule specifies no actions Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 038/187] netfilter: bridge: make sure to pull arp header in br_nf_forward_arp() Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 049/187] mlxsw: spectrum_router: Remove unlikely user-triggerable warning Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 050/187] selftests: forwarding: Delete IPv6 address at the end Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 052/187] net: ethernet: ti: davinci_cpdma: fix warning "device driver frees DMA memory with different size" Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 053/187] af_packet: set defaule value for tmo Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 054/187] fjes: fix missed check in fjes_acpi_add Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 055/187] NFC: nxp-nci: Fix probing without ACPI Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 056/187] Revert "iwlwifi: assign directly to iwl_trans->cfg in QuZ detection" Sasha Levin
2019-12-30  5:48   ` Anders Kaseorg
2020-01-05 15:42     ` Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 057/187] iwlwifi: pcie: move power gating workaround earlier in the flow Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 067/187] bnxt_en: Fix MSIX request logic for RDMA driver Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 068/187] bnxt_en: Return error if FW returns more data than dump length Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 069/187] net: ena: fix napi handler misbehavior when the napi budget is zero Sasha Levin
2019-12-27 17:38 ` [PATCH AUTOSEL 5.4 071/187] bpf, riscv: Limit to 33 tail calls Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 072/187] bpf, mips: " Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 073/187] bpftool: Don't crash on missing jited insns or ksyms Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 080/187] samples: bpf: Replace symbol compare of trace_event Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 081/187] samples: bpf: fix syscall_tp due to unused syscall Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 087/187] net: usb: lan78xx: Fix suspend/resume PHY register access error Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 088/187] qede: Fix multicast mac configuration Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 090/187] mac80211: fix TID field in monitor mode transmit Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 091/187] cfg80211: fix double-free after changing network namespace Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 100/187] bpf: Clear skb->tstamp in bpf_redirect when necessary Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 101/187] bnxt: apply computed clamp value for coalece parameter Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 102/187] ipv6/addrconf: only check invalid header values when NETLINK_F_STRICT_CHK is set Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 103/187] tcp/dccp: fix possible race __inet_lookup_established() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 104/187] 6pack,mkiss: fix possible deadlock Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 107/187] net: marvell: mvpp2: phylink requires the link interrupt Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 108/187] hv_netvsc: Fix tx_table init in rndis_set_subchannel() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 109/187] bnx2x: Do not handle requests from VFs after parity Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 110/187] bnx2x: Fix logic to get total no. of PFs per engine Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 111/187] bonding: fix active-backup transition after link failure Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 112/187] gtp: do not allow adding duplicate tid and ms_addr pdp context Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 113/187] gtp: fix wrong condition in gtp_genl_dump_pdp() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 114/187] gtp: fix an use-after-free in ipv4_pdp_find() Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 115/187] gtp: avoid zero size hashtable Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 116/187] net: phylink: fix interface passed to mac_link_up Sasha Levin
2019-12-27 17:39 ` Sasha Levin [this message]
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 118/187] cxgb4: Fix kernel panic while accessing sge_info Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 119/187] net: usb: lan78xx: Fix error message format specifier Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 122/187] rfkill: Fix incorrect check to avoid NULL pointer dereference Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 128/187] net: dsa: b53: Fix egress flooding settings Sasha Levin
2019-12-27 17:39 ` [PATCH AUTOSEL 5.4 129/187] net: gemini: Fix memory leak in gmac_setup_txqs Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191227174055.4923-117-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=jakub.kicinski@netronome.com \
    --cc=kgraul@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+96d3f9ff6a86d37e44c8@syzkaller.appspotmail.com \
    --cc=ubraun@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).