Blob Blame History Raw
From: "Paulo Alcantara (SUSE)" <pc@cjr.nz>
Date: Wed, 4 Dec 2019 11:25:06 -0300
Subject: [PATCH] cifs: Fix lookup of SMB connections on multichannel
Git-commit: 3345bb44bacd99413a3dc0dcd9a99449d88d4dda
Patch-mainline: v5.5-rc1
References: bsc#1192606

With the addition of SMB session channels, we introduced new TCP
server pointers that have no sessions or tcons associated with them.

In this case, when we started looking for TCP connections, we might
end up picking session channel rather than the master connection,
hence failing to get either a session or a tcon.

In order to fix that, this patch introduces a new "is_channel" field
to TCP_Server_Info structure so we can skip session channels during
lookup of connections.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Acked-by: Enzo Matsumiya <ematsumiya@suse.de>
---
 fs/cifs/cifsglob.h |    1 +
 fs/cifs/connect.c  |    6 +++++-
 fs/cifs/sess.c     |    3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -775,6 +775,7 @@ struct TCP_Server_Info {
 	 * reconnect.
 	 */
 	int nr_targets;
+	bool is_channel; /* if a session channel */
 };
 
 struct cifs_credits {
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -2706,7 +2706,11 @@ cifs_find_tcp_session(struct smb_vol *vo
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
-		if (!match_server(server, vol))
+		/*
+		 * Skip ses channels since they're only handled in lower layers
+		 * (e.g. cifs_send_recv).
+		 */
+		if (server->is_channel || !match_server(server, vol))
 			continue;
 
 		++server->srv_count;
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -213,6 +213,9 @@ cifs_ses_add_channel(struct cifs_ses *se
 		chan->server = NULL;
 		goto out;
 	}
+	spin_lock(&cifs_tcp_ses_lock);
+	chan->server->is_channel = true;
+	spin_unlock(&cifs_tcp_ses_lock);
 
 	/*
 	 * We need to allocate the server crypto now as we will need