Skip to contentSkip to conversation

cifs: fix charset issue in reconnection

PATCH Superseded Winston Wen 2 participants 3 messages Jul 17, 2023 – Jul 18, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix charset issue in reconnection

We need to specify charset, like "iocharset=utf-8", in mount options for Chinese path if the nls_default don't support it, such as iso8859-1, the default value for CONFIG_NLS_DEFAULT.

But now in reconnection the nls_default is used, instead of the one we specified and used in mount, and this can lead to mount failure.

---
 fs/smb/client/cifsglob.h | 1 +
 fs/smb/client/connect.c  | 6 ++++++
 fs/smb/client/smb2pdu.c  | 3 +--
 3 files changed, 8 insertions(+), 2 deletions(-)
fs/smb/client/cifsglob.h +1 -0
index c9a87d0123ce..31cadf9b2a98 100644
@@ -1062,6 +1062,7 @@ struct cifs_ses {
 	unsigned long chans_need_reconnect;
 	/* ========= end: protected by chan_lock ======== */
 	struct cifs_ses *dfs_root_ses;
+	struct nls_table *local_nls;
 };
 
 static inline bool
fs/smb/client/connect.c +6 -0
index 5dd09c6d762e..abb69a6d4fce 100644
@@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
 			    CIFS_MAX_PASSWORD_LEN))
 			return 0;
 	}
+
+	if (strcmp(ctx->local_nls->charset, ses->local_nls->charset))
+		return 0;
+
 	return 1;
 }
 
@@ -2027,6 +2031,7 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
 		}
 	}
 
+	unload_nls(ses->local_nls);
 	sesInfoFree(ses);
 	cifs_put_tcp_session(server, 0);
 }
@@ -2286,6 +2291,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
 
 	ses->sectype = ctx->sectype;
 	ses->sign = ctx->sign;
+	ses->local_nls = load_nls(ctx->local_nls->charset);
 
 	/* add server as first channel */
 	spin_lock(&ses->chan_lock);
fs/smb/client/smb2pdu.c +1 -2
index e04766fe6f80..a457f07f820d 100644
@@ -242,7 +242,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 	}
 	spin_unlock(&server->srv_lock);
 
-	nls_codepage = load_nls_default();
+	nls_codepage = ses->local_nls;
 
 	/*
 	 * need to prevent multiple threads trying to simultaneously
@@ -324,7 +324,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
 		rc = -EAGAIN;
 	}
 failed:
-	unload_nls(nls_codepage);
 	return rc;
 }
 
Signature · 1 line
2.40.1
#1 lore raw
Quoted 42 lines · Winston Wen

We need to specify charset, like "iocharset=utf-8", in mount options for Chinese path if the nls_default don't support it, such as iso8859-1, the default value for CONFIG_NLS_DEFAULT.

But now in reconnection the nls_default is used, instead of the one we specified and used in mount, and this can lead to mount failure.

---
 fs/smb/client/cifsglob.h | 1 +
 fs/smb/client/connect.c  | 6 ++++++
 fs/smb/client/smb2pdu.c  | 3 +--
 3 files changed, 8 insertions(+), 2 deletions(-)
fs/smb/client/cifsglob.h +1 -0
index c9a87d0123ce..31cadf9b2a98 100644
@@ -1062,6 +1062,7 @@ struct cifs_ses {
 	unsigned long chans_need_reconnect;
 	/* ========= end: protected by chan_lock ======== */
 	struct cifs_ses *dfs_root_ses;
+	struct nls_table *local_nls;
 };
 
 static inline bool
fs/smb/client/connect.c +4 -0
index 5dd09c6d762e..abb69a6d4fce 100644
@@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
 			    CIFS_MAX_PASSWORD_LEN))
 			return 0;
 	}
+
+	if (strcmp(ctx->local_nls->charset, ses->local_nls->charset))
+		return 0;
+
 	return 1;
 }
 

fs/smb/client/connect.c void __cifs_put_smb_ses(struct cifs_ses *ses) · line 2034

Quoted 4 lines
fs/smb/client/connect.c +1 -0
@@ -2027,6 +2031,7 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
 		}
 	}
 
+	unload_nls(ses->local_nls);

Please move this call to sesInfoFree().

cifs_reconnect_tcon() also needs to be fixed by using @ses->local_nls rather than load_nls_default().

Otherwise, looks good te me. Thanks!

#2 lore raw
Quoted 44 lines · On Mon, 17 Jul 2023 13:00:16 -0300 Paulo Alcantara <[email protected]> wrote:
Quoted 42 lines · Winston Wen

We need to specify charset, like "iocharset=utf-8", in mount options for Chinese path if the nls_default don't support it, such as iso8859-1, the default value for CONFIG_NLS_DEFAULT.

But now in reconnection the nls_default is used, instead of the one we specified and used in mount, and this can lead to mount failure.

---
 fs/smb/client/cifsglob.h | 1 +
 fs/smb/client/connect.c  | 6 ++++++
 fs/smb/client/smb2pdu.c  | 3 +--
 3 files changed, 8 insertions(+), 2 deletions(-)
fs/smb/client/cifsglob.h +1 -0
index c9a87d0123ce..31cadf9b2a98 100644
@@ -1062,6 +1062,7 @@ struct cifs_ses {
 	unsigned long chans_need_reconnect;
 	/* ========= end: protected by chan_lock ======== */
 	struct cifs_ses *dfs_root_ses;
+	struct nls_table *local_nls;
 };
 
 static inline bool
fs/smb/client/connect.c +4 -0
index 5dd09c6d762e..abb69a6d4fce 100644
@@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses
 *ses, struct smb3_fs_context *ctx) CIFS_MAX_PASSWORD_LEN))
 			return 0;
 	}
+
+	if (strcmp(ctx->local_nls->charset,
 ses->local_nls->charset))
+		return 0;
+
 	return 1;
 }
Quoted 7 lines

fs/smb/client/connect.c void __cifs_put_smb_ses(struct cifs_ses *ses) · line 2034

Quoted 5 lines
fs/smb/client/connect.c +1 -0
@@ -2027,6 +2031,7 @@ void __cifs_put_smb_ses(struct cifs_ses *ses)
 		}
 	}
 
+	unload_nls(ses->local_nls);

Please move this call to sesInfoFree().

Thanks, fixed.

Quoted 3 lines

cifs_reconnect_tcon() also needs to be fixed by using @ses->local_nls rather than load_nls_default().

Thanks, fixed. I totally missed this.

Quoted 3 lines

Otherwise, looks good te me. Thanks!

Thanks for the review!

Signature · 2 lines
Thanks,
Winston