Skip to contentSkip to conversation

cifs: get rid of cifs_mount_ctx::{origin,leaf}_fullpath

PATCH In review Paulo Alcantara 3 participants 13 messages Mar 29, 2023 – Mar 30, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 cifs: get rid of cifs_mount_ctx::{origin,leaf}_fullpath

leaf_fullpath is now part of smb3_fs_context structure, while origin_fullpath is just a variable in __dfs_mount_share() that is used when final tcon is available.

Get rid of those fields in cifs_mount_ctx structure and no-op kfree()'s.

---
 fs/cifs/cifsglob.h | 1 -
 fs/cifs/connect.c  | 2 --
 2 files changed, 3 deletions(-)
fs/cifs/cifsglob.h +0 -1
index 08a73dcb7786..c5e3a0fc7983 100644
@@ -1750,7 +1750,6 @@ struct cifs_mount_ctx {
 	struct TCP_Server_Info *server;
 	struct cifs_ses *ses;
 	struct cifs_tcon *tcon;
-	char *origin_fullpath, *leaf_fullpath;
 	struct list_head dfs_ses_list;
 };
 
fs/cifs/connect.c +0 -2
index 1cbb90587995..ef50f603e640 100644
@@ -3454,8 +3454,6 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 
 error:
 	dfs_put_root_smb_sessions(&mnt_ctx.dfs_ses_list);
-	kfree(mnt_ctx.origin_fullpath);
-	kfree(mnt_ctx.leaf_fullpath);
 	cifs_mount_put_conns(&mnt_ctx);
 	return rc;
 }
Signature · 1 line
2.40.0
#1 lore raw

PATCH 2/5 cifs: get rid of unnecessary ifdef

No need to ifdef around TCP_Server_Info::{origin,leaf}_fullpath as they're declared regardless CONFIG_CIFS_DFS_UPCALL.

---
 fs/cifs/connect.c | 2 --
 1 file changed, 2 deletions(-)
fs/cifs/connect.c +0 -2
index ef50f603e640..7c3e090a0f13 100644
@@ -993,10 +993,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
 		 */
 	}
 
-#ifdef CONFIG_CIFS_DFS_UPCALL
 	kfree(server->origin_fullpath);
 	kfree(server->leaf_fullpath);
-#endif
 	kfree(server);
 
 	length = atomic_dec_return(&tcpSesAllocCount);
Signature · 1 line
2.40.0
#3 lore raw

PATCH 3/5 cifs: avoid races in parallel reconnects in smb1

In reply to Paulo Alcantara

Prevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in cifs_reconnect_tcon() while reconnecting session and tcon.

---
 fs/cifs/cifssmb.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
fs/cifs/cifssmb.c +15 -6
index 38a697eca305..c9d57ba84be4 100644
@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
 	int rc;
 	struct cifs_ses *ses;
 	struct TCP_Server_Info *server;
-	struct nls_table *nls_codepage;
+	struct nls_table *nls_codepage = NULL;
 
 	/*
 	 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
@@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
 	}
 	spin_unlock(&tcon->tc_lock);
 
+again:
 	rc = cifs_wait_for_server_reconnect(server, tcon->retry);
 	if (rc)
 		return rc;
@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
 	}
 	spin_unlock(&ses->chan_lock);
 
-	nls_codepage = load_nls_default();
-
+	mutex_lock(&ses->session_mutex);
 	/*
 	 * Recheck after acquire mutex. If another thread is negotiating
 	 * and the server never sends an answer the socket will be closed
@@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
 	spin_lock(&server->srv_lock);
 	if (server->tcpStatus == CifsNeedReconnect) {
 		spin_unlock(&server->srv_lock);
+		mutex_lock(&ses->session_mutex);
+
+		if (tcon->retry)
+			goto again;
 		rc = -EHOSTDOWN;
 		goto out;
 	}
 	spin_unlock(&server->srv_lock);
 
+	nls_codepage = load_nls_default();
+
 	/*
 	 * need to prevent multiple threads trying to simultaneously
 	 * reconnect the same SMB session
 	 */
+	spin_lock(&ses->ses_lock);
 	spin_lock(&ses->chan_lock);
-	if (!cifs_chan_needs_reconnect(ses, server)) {
+	if (!cifs_chan_needs_reconnect(ses, server) &&
+	    ses->ses_status == SES_GOOD) {
 		spin_unlock(&ses->chan_lock);
+		spin_unlock(&ses->ses_lock);
 
 		/* this means that we only need to tree connect */
 		if (tcon->need_reconnect)
 			goto skip_sess_setup;
 
-		rc = -EHOSTDOWN;
+		mutex_unlock(&ses->session_mutex);
 		goto out;
 	}
 	spin_unlock(&ses->chan_lock);
+	spin_unlock(&ses->ses_lock);
 
-	mutex_lock(&ses->session_mutex);
 	rc = cifs_negotiate_protocol(0, ses, server);
 	if (!rc)
 		rc = cifs_setup_session(0, ses, server, nls_codepage);
Signature · 1 line
2.40.0
#6 lore raw

PATCH 4/5 cifs: prevent infinite recursion in CIFSGetDFSRefer()

In reply to Paulo Alcantara

We can't call smb_init() in CIFSGetDFSRefer() as cifs_reconnect_tcon() may end up calling CIFSGetDFSRefer() again to get new DFS referrals and thus causing an infinite recursion.

---
 fs/cifs/cifssmb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cifs/cifssmb.c +7 -2
index c9d57ba84be4..0d30b17494e4 100644
@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
 		return -ENODEV;
 
 getDFSRetry:
-	rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB,
-		      (void **) &pSMBr);
+	/*
+	 * Use smb_init_no_reconnect() instead of smb_init() as
+	 * CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus
+	 * causing an infinite recursion.
+	 */
+	rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc,
+				   (void **)&pSMB, (void **)&pSMBr);
 	if (rc)
 		return rc;
 
Signature · 1 line
2.40.0
#9 lore raw

PATCH 5/5 cifs: get rid of dead check in smb2_reconnect()

In reply to Paulo Alcantara

The SMB2_IOCTL check in the switch statement will never be true as we return earlier from smb2_reconnect() if @smb2_command == SMB2_IOCTL.

---
 fs/cifs/smb2pdu.c | 1 -
 1 file changed, 1 deletion(-)
fs/cifs/smb2pdu.c +0 -1
index 6bd2aa6af18f..2b92132097dc 100644
@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 	case SMB2_READ:
 	case SMB2_WRITE:
 	case SMB2_LOCK:
-	case SMB2_IOCTL:
 	case SMB2_QUERY_DIRECTORY:
 	case SMB2_CHANGE_NOTIFY:
 	case SMB2_QUERY_INFO:
Signature · 1 line
2.40.0
#12 lore raw
In reply to Paulo Alcantara

Reviewed-by me

Quoted 42 lines · Paulo Alcantara

leaf_fullpath is now part of smb3_fs_context structure, while origin_fullpath is just a variable in __dfs_mount_share() that is used when final tcon is available.

Get rid of those fields in cifs_mount_ctx structure and no-op kfree()'s.

---
 fs/cifs/cifsglob.h | 1 -
 fs/cifs/connect.c  | 2 --
 2 files changed, 3 deletions(-)
fs/cifs/cifsglob.h +0 -1
index 08a73dcb7786..c5e3a0fc7983 100644
@@ -1750,7 +1750,6 @@ struct cifs_mount_ctx {
        struct TCP_Server_Info *server;
        struct cifs_ses *ses;
        struct cifs_tcon *tcon;
-       char *origin_fullpath, *leaf_fullpath;
        struct list_head dfs_ses_list;
 };
 
fs/cifs/connect.c +0 -3
index 1cbb90587995..ef50f603e640 100644
@@ -3454,8 +3454,6 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 
 error:
        dfs_put_root_smb_sessions(&mnt_ctx.dfs_ses_list);
-       kfree(mnt_ctx.origin_fullpath);
-       kfree(mnt_ctx.leaf_fullpath);
        cifs_mount_put_conns(&mnt_ctx);
        return rc;
 }
--

2.40.0

#2 lore raw

Re: [PATCH 2/5] cifs: get rid of unnecessary ifdef

In reply to Paulo Alcantara

reviewed-by me

Quoted 27 lines · Paulo Alcantara

No need to ifdef around TCP_Server_Info::{origin,leaf}_fullpath as they're declared regardless CONFIG_CIFS_DFS_UPCALL.

---
 fs/cifs/connect.c | 2 --
 1 file changed, 2 deletions(-)
fs/cifs/connect.c +0 -3
index ef50f603e640..7c3e090a0f13 100644
@@ -993,10 +993,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
                 */
        }
 
-#ifdef CONFIG_CIFS_DFS_UPCALL
        kfree(server->origin_fullpath);
        kfree(server->leaf_fullpath);
-#endif
        kfree(server);
 
        length = atomic_dec_return(&tcpSesAllocCount);
--

2.40.0

#4 lore raw

Re: [PATCH 3/5] cifs: avoid races in parallel reconnects in smb1

In reply to Paulo Alcantara

reviewed-by me

Quoted 86 lines · Paulo Alcantara

Prevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in cifs_reconnect_tcon() while reconnecting session and tcon.

---
 fs/cifs/cifssmb.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
fs/cifs/cifssmb.c +15 -7
index 38a697eca305..c9d57ba84be4 100644
@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        int rc;
        struct cifs_ses *ses;
        struct TCP_Server_Info *server;
-       struct nls_table *nls_codepage;
+       struct nls_table *nls_codepage = NULL;
 
        /*
         * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
@@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        }
        spin_unlock(&tcon->tc_lock);
 
+again:
        rc = cifs_wait_for_server_reconnect(server, tcon->retry);
        if (rc)
                return rc;
@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        }
        spin_unlock(&ses->chan_lock);
 
-       nls_codepage = load_nls_default();
-
+       mutex_lock(&ses->session_mutex);
        /*
         * Recheck after acquire mutex. If another thread is negotiating
         * and the server never sends an answer the socket will be closed
@@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        spin_lock(&server->srv_lock);
        if (server->tcpStatus == CifsNeedReconnect) {
                spin_unlock(&server->srv_lock);
+               mutex_lock(&ses->session_mutex);
+
+               if (tcon->retry)
+                       goto again;
                rc = -EHOSTDOWN;
                goto out;
        }
        spin_unlock(&server->srv_lock);
 
+       nls_codepage = load_nls_default();
+
        /*
         * need to prevent multiple threads trying to simultaneously
         * reconnect the same SMB session
         */
+       spin_lock(&ses->ses_lock);
        spin_lock(&ses->chan_lock);
-       if (!cifs_chan_needs_reconnect(ses, server)) {
+       if (!cifs_chan_needs_reconnect(ses, server) &&
+           ses->ses_status == SES_GOOD) {
                spin_unlock(&ses->chan_lock);
+               spin_unlock(&ses->ses_lock);
 
                /* this means that we only need to tree connect */
                if (tcon->need_reconnect)
                        goto skip_sess_setup;
 
-               rc = -EHOSTDOWN;
+               mutex_unlock(&ses->session_mutex);
                goto out;
        }
        spin_unlock(&ses->chan_lock);
+       spin_unlock(&ses->ses_lock);
 
-       mutex_lock(&ses->session_mutex);
        rc = cifs_negotiate_protocol(0, ses, server);
        if (!rc)
                rc = cifs_setup_session(0, ses, server, nls_codepage);
--

2.40.0

#7 lore raw

Re: [PATCH 4/5] cifs: prevent infinite recursion in CIFSGetDFSRefer()

In reply to Paulo Alcantara

reviewed-by me

Quoted 33 lines · Paulo Alcantara

We can't call smb_init() in CIFSGetDFSRefer() as cifs_reconnect_tcon() may end up calling CIFSGetDFSRefer() again to get new DFS referrals and thus causing an infinite recursion.

---
 fs/cifs/cifssmb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cifs/cifssmb.c +7 -3
index c9d57ba84be4..0d30b17494e4 100644
@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
                return -ENODEV;
 
 getDFSRetry:
-       rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB,
-                     (void **) &pSMBr);
+       /*
+        * Use smb_init_no_reconnect() instead of smb_init() as
+        * CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus
+        * causing an infinite recursion.
+        */
+       rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc,
+                                  (void **)&pSMB, (void **)&pSMBr);
        if (rc)
                return rc;
 
--

2.40.0

#10 lore raw

Re: [PATCH 5/5] cifs: get rid of dead check in smb2_reconnect()

In reply to Paulo Alcantara

reviewed-by me

Quoted 24 lines · Paulo Alcantara

The SMB2_IOCTL check in the switch statement will never be true as we return earlier from smb2_reconnect() if @smb2_command == SMB2_IOCTL.

---
 fs/cifs/smb2pdu.c | 1 -
 1 file changed, 1 deletion(-)
fs/cifs/smb2pdu.c +0 -2
index 6bd2aa6af18f..2b92132097dc 100644
@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
        case SMB2_READ:
        case SMB2_WRITE:
        case SMB2_LOCK:
-       case SMB2_IOCTL:
        case SMB2_QUERY_DIRECTORY:
        case SMB2_CHANGE_NOTIFY:
        case SMB2_QUERY_INFO:
--

2.40.0

#5 lore raw

Re: [PATCH 3/5] cifs: avoid races in parallel reconnects in smb1

In reply to Paulo Alcantara

added ronnie's RB and merged into cifs-2.6.git for-next (I will hold off on patches 1 and 2 since they are cleanup until 6.4-rc)

Quoted 86 lines · Paulo Alcantara

Prevent multiple threads of doing negotiate, session setup and tree connect by holding @ses->session_mutex in cifs_reconnect_tcon() while reconnecting session and tcon.

---
 fs/cifs/cifssmb.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
fs/cifs/cifssmb.c +15 -7
index 38a697eca305..c9d57ba84be4 100644
@@ -71,7 +71,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        int rc;
        struct cifs_ses *ses;
        struct TCP_Server_Info *server;
-       struct nls_table *nls_codepage;
+       struct nls_table *nls_codepage = NULL;
 
        /*
         * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
@@ -99,6 +99,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        }
        spin_unlock(&tcon->tc_lock);
 
+again:
        rc = cifs_wait_for_server_reconnect(server, tcon->retry);
        if (rc)
                return rc;
@@ -110,8 +111,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        }
        spin_unlock(&ses->chan_lock);
 
-       nls_codepage = load_nls_default();
-
+       mutex_lock(&ses->session_mutex);
        /*
         * Recheck after acquire mutex. If another thread is negotiating
         * and the server never sends an answer the socket will be closed
@@ -120,29 +120,38 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
        spin_lock(&server->srv_lock);
        if (server->tcpStatus == CifsNeedReconnect) {
                spin_unlock(&server->srv_lock);
+               mutex_lock(&ses->session_mutex);
+
+               if (tcon->retry)
+                       goto again;
                rc = -EHOSTDOWN;
                goto out;
        }
        spin_unlock(&server->srv_lock);
 
+       nls_codepage = load_nls_default();
+
        /*
         * need to prevent multiple threads trying to simultaneously
         * reconnect the same SMB session
         */
+       spin_lock(&ses->ses_lock);
        spin_lock(&ses->chan_lock);
-       if (!cifs_chan_needs_reconnect(ses, server)) {
+       if (!cifs_chan_needs_reconnect(ses, server) &&
+           ses->ses_status == SES_GOOD) {
                spin_unlock(&ses->chan_lock);
+               spin_unlock(&ses->ses_lock);
 
                /* this means that we only need to tree connect */
                if (tcon->need_reconnect)
                        goto skip_sess_setup;
 
-               rc = -EHOSTDOWN;
+               mutex_unlock(&ses->session_mutex);
                goto out;
        }
        spin_unlock(&ses->chan_lock);
+       spin_unlock(&ses->ses_lock);
 
-       mutex_lock(&ses->session_mutex);
        rc = cifs_negotiate_protocol(0, ses, server);
        if (!rc)
                rc = cifs_setup_session(0, ses, server, nls_codepage);
--

2.40.0

Signature · 3 lines
Thanks,

Steve
#8 lore raw

Re: [PATCH 4/5] cifs: prevent infinite recursion in CIFSGetDFSRefer()

In reply to Paulo Alcantara

added cc:stable and added ronnie's RB and merged into cifs-2.6.git for-next

Quoted 33 lines · Paulo Alcantara

We can't call smb_init() in CIFSGetDFSRefer() as cifs_reconnect_tcon() may end up calling CIFSGetDFSRefer() again to get new DFS referrals and thus causing an infinite recursion.

---
 fs/cifs/cifssmb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/cifs/cifssmb.c +7 -3
index c9d57ba84be4..0d30b17494e4 100644
@@ -4382,8 +4382,13 @@ CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
                return -ENODEV;
 
 getDFSRetry:
-       rc = smb_init(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc, (void **) &pSMB,
-                     (void **) &pSMBr);
+       /*
+        * Use smb_init_no_reconnect() instead of smb_init() as
+        * CIFSGetDFSRefer() may be called from cifs_reconnect_tcon() and thus
+        * causing an infinite recursion.
+        */
+       rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, ses->tcon_ipc,
+                                  (void **)&pSMB, (void **)&pSMBr);
        if (rc)
                return rc;
 
--

2.40.0

Signature · 3 lines
Thanks,

Steve
#11 lore raw

Re: [PATCH 5/5] cifs: get rid of dead check in smb2_reconnect()

In reply to Paulo Alcantara

added ronnie's RB and merged into cifs-2.6.git for-next

Quoted 24 lines · Paulo Alcantara

The SMB2_IOCTL check in the switch statement will never be true as we return earlier from smb2_reconnect() if @smb2_command == SMB2_IOCTL.

---
 fs/cifs/smb2pdu.c | 1 -
 1 file changed, 1 deletion(-)
fs/cifs/smb2pdu.c +0 -2
index 6bd2aa6af18f..2b92132097dc 100644
@@ -310,7 +310,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
        case SMB2_READ:
        case SMB2_WRITE:
        case SMB2_LOCK:
-       case SMB2_IOCTL:
        case SMB2_QUERY_DIRECTORY:
        case SMB2_CHANGE_NOTIFY:
        case SMB2_QUERY_INFO:
--

2.40.0

Signature · 3 lines
Thanks,

Steve