public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Enrico Scholz <enrico.scholz@sigma-chemnitz.de>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Meena Shanmugam <meenashanmugam@google.com>
Subject: [PATCH 5.10 60/66] SUNRPC: Dont call connect() more than once on a TCP socket
Date: Mon, 16 May 2022 21:37:00 +0200	[thread overview]
Message-ID: <20220516193621.147348223@linuxfoundation.org> (raw)
In-Reply-To: <20220516193619.400083785@linuxfoundation.org>

From: Trond Myklebust <trond.myklebust@hammerspace.com>

commit 89f42494f92f448747bd8a7ab1ae8b5d5520577d upstream.

Avoid socket state races due to repeated calls to ->connect() using the
same socket. If connect() returns 0 due to the connection having
completed, but we are in fact in a closing state, then we may leave the
XPRT_CONNECTING flag set on the transport.

Reported-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Fixes: 3be232f11a3c ("SUNRPC: Prevent immediate close+reconnect")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[meenashanmugam: Backported to 5.10: Fixed merge conflict in xs_tcp_setup_socket]
Signed-off-by: Meena Shanmugam <meenashanmugam@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/sunrpc/xprtsock.h |    1 +
 net/sunrpc/xprtsock.c           |   21 +++++++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

--- a/include/linux/sunrpc/xprtsock.h
+++ b/include/linux/sunrpc/xprtsock.h
@@ -89,5 +89,6 @@ struct sock_xprt {
 #define XPRT_SOCK_WAKE_WRITE	(5)
 #define XPRT_SOCK_WAKE_PENDING	(6)
 #define XPRT_SOCK_WAKE_DISCONNECT	(7)
+#define XPRT_SOCK_CONNECT_SENT	(8)
 
 #endif /* _LINUX_SUNRPC_XPRTSOCK_H */
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -2260,10 +2260,14 @@ static void xs_tcp_setup_socket(struct w
 	struct rpc_xprt *xprt = &transport->xprt;
 	int status = -EIO;
 
-	if (!sock) {
-		sock = xs_create_sock(xprt, transport,
-				xs_addr(xprt)->sa_family, SOCK_STREAM,
-				IPPROTO_TCP, true);
+	if (xprt_connected(xprt))
+		goto out;
+	if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT,
+			       &transport->sock_state) ||
+	    !sock) {
+		xs_reset_transport(transport);
+		sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family,
+				      SOCK_STREAM, IPPROTO_TCP, true);
 		if (IS_ERR(sock)) {
 			status = PTR_ERR(sock);
 			goto out;
@@ -2294,6 +2298,7 @@ static void xs_tcp_setup_socket(struct w
 		break;
 	case 0:
 	case -EINPROGRESS:
+		set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state);
 	case -EALREADY:
 		xprt_unlock_connect(xprt, transport);
 		return;
@@ -2345,13 +2350,9 @@ static void xs_connect(struct rpc_xprt *
 
 	WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport));
 
-	if (transport->sock != NULL && !xprt_connecting(xprt)) {
+	if (transport->sock != NULL) {
 		dprintk("RPC:       xs_connect delayed xprt %p for %lu "
-				"seconds\n",
-				xprt, xprt->reestablish_timeout / HZ);
-
-		/* Start by resetting any existing state */
-		xs_reset_transport(transport);
+			"seconds\n", xprt, xprt->reestablish_timeout / HZ);
 
 		delay = xprt_reconnect_delay(xprt);
 		xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO);



  parent reply	other threads:[~2022-05-16 20:07 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 19:36 [PATCH 5.10 00/66] 5.10.117-rc1 review Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 01/66] batman-adv: Dont skb_split skbuffs with frag_list Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 02/66] iwlwifi: iwl-dbg: Use del_timer_sync() before freeing Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 03/66] hwmon: (tmp401) Add OF device ID table Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 04/66] mac80211: Reset MBSSID parameters upon connection Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 05/66] net: Fix features skip in for_each_netdev_feature() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 06/66] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 07/66] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 08/66] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 09/66] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 10/66] ipv4: drop dst in multicast routing path Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 11/66] drm/nouveau: Fix a potential theorical leak in nouveau_get_backlight_name() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 12/66] netlink: do not reset transport header in netlink_recvmsg() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 13/66] sfc: Use swap() instead of open coding it Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 14/66] net: sfc: fix memory leak due to ptp channel Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 15/66] mac80211_hwsim: call ieee80211_tx_prepare_skb under RCU protection Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 16/66] nfs: fix broken handling of the softreval mount option Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 17/66] ionic: fix missing pci_release_regions() on error in ionic_probe() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 18/66] dim: initialize all struct fields Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 19/66] hwmon: (ltq-cputemp) restrict it to SOC_XWAY Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 20/66] selftests: vm: Makefile: rename TARGETS to VMTARGETS Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 21/66] s390/ctcm: fix variable dereferenced before check Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 22/66] s390/ctcm: fix potential memory leak Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 23/66] s390/lcs: fix variable dereferenced before check Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 24/66] net/sched: act_pedit: really ensure the skb is writable Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 25/66] net: bcmgenet: Check for Wake-on-LAN interrupt probe deferral Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 26/66] net: dsa: bcm_sf2: Fix Wake-on-LAN with mac_link_down() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 27/66] net/smc: non blocking recvmsg() return -EAGAIN when no data and signal_pending Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 28/66] net: sfc: ef10: fix memory leak in efx_ef10_mtd_probe() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 29/66] tls: Fix context leak on tls_device_down Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 30/66] gfs2: Fix filesystem block deallocation for short writes Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 31/66] hwmon: (f71882fg) Fix negative temperature Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 32/66] ASoC: max98090: Reject invalid values in custom control put() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 33/66] ASoC: max98090: Generate notifications on changes for custom control Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 34/66] ASoC: ops: Validate input values in snd_soc_put_volsw_range() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 35/66] s390: disable -Warray-bounds Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 36/66] net: emaclite: Dont advertise 1000BASE-T and do auto negotiation Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 37/66] net: sfp: Add tx-fault workaround for Huawei MA5671A SFP ONT Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 38/66] tcp: resalt the secret every 10 seconds Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 39/66] firmware_loader: use kernel credentials when reading firmware Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 40/66] tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 41/66] tty: n_gsm: fix mux activation issues in gsm_config() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 42/66] usb: cdc-wdm: fix reading stuck on device close Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 43/66] usb: typec: tcpci: Dont skip cleanup in .remove() on error Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 44/66] usb: typec: tcpci_mt6360: Update for BMC PHY setting Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 45/66] USB: serial: pl2303: add device id for HP LM930 Display Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 46/66] USB: serial: qcserial: add support for Sierra Wireless EM7590 Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 47/66] USB: serial: option: add Fibocom L610 modem Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 48/66] USB: serial: option: add Fibocom MA510 modem Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 49/66] slimbus: qcom: Fix IRQ check in qcom_slim_probe Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 50/66] serial: 8250_mtk: Fix UART_EFR register address Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 51/66] serial: 8250_mtk: Fix register address for XON/XOFF character Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 52/66] ceph: fix setting of xattrs on async created inodes Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 53/66] drm/nouveau/tegra: Stop using iommu_present() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 54/66] i40e: i40e_main: fix a missing check on list iterator Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 55/66] net: atlantic: always deep reset on pm op, fixing up my null deref regression Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 56/66] cgroup/cpuset: Remove cpus_allowed/mems_allowed setup in cpuset_init_smp() Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 57/66] drm/vmwgfx: Initialize drm_mode_fb_cmd2 Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 58/66] SUNRPC: Clean up scheduling of autoclose Greg Kroah-Hartman
2022-05-16 19:36 ` [PATCH 5.10 59/66] SUNRPC: Prevent immediate close+reconnect Greg Kroah-Hartman
2022-05-16 19:37 ` Greg Kroah-Hartman [this message]
2022-05-16 19:37 ` [PATCH 5.10 61/66] SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() Greg Kroah-Hartman
2022-05-16 19:37 ` [PATCH 5.10 62/66] net: phy: Fix race condition on link status change Greg Kroah-Hartman
2022-05-16 19:37 ` [PATCH 5.10 63/66] arm[64]/memremap: dont abuse pfn_valid() to ensure presence of linear map Greg Kroah-Hartman
2022-05-16 19:37 ` [PATCH 5.10 64/66] ping: fix address binding wrt vrf Greg Kroah-Hartman
2022-05-16 19:37 ` [PATCH 5.10 65/66] usb: gadget: uvc: rename function to be more consistent Greg Kroah-Hartman
2022-05-16 19:37 ` [PATCH 5.10 66/66] usb: gadget: uvc: allow for application to cleanly shutdown Greg Kroah-Hartman
2022-05-17  3:38 ` [PATCH 5.10 00/66] 5.10.117-rc1 review Florian Fainelli

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=20220516193621.147348223@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=enrico.scholz@sigma-chemnitz.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meenashanmugam@google.com \
    --cc=stable@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.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