Skip to content

Commit a43f95f

Browse files
winnscodesmfrench
authored andcommitted
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. Signed-off-by: Winston Wen <[email protected]> Reviewed-by: Paulo Alcantara <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c1ed39e commit a43f95f

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ struct cifs_ses {
10621062
unsigned long chans_need_reconnect;
10631063
/* ========= end: protected by chan_lock ======== */
10641064
struct cifs_ses *dfs_root_ses;
1065+
struct nls_table *local_nls;
10651066
};
10661067

10671068
static inline bool

fs/smb/client/cifssmb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
129129
}
130130
spin_unlock(&server->srv_lock);
131131

132-
nls_codepage = load_nls_default();
132+
nls_codepage = ses->local_nls;
133133

134134
/*
135135
* need to prevent multiple threads trying to simultaneously
@@ -200,7 +200,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
200200
rc = -EAGAIN;
201201
}
202202

203-
unload_nls(nls_codepage);
204203
return rc;
205204
}
206205

fs/smb/client/connect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
18421842
CIFS_MAX_PASSWORD_LEN))
18431843
return 0;
18441844
}
1845+
1846+
if (strcmp(ctx->local_nls->charset, ses->local_nls->charset))
1847+
return 0;
1848+
18451849
return 1;
18461850
}
18471851

@@ -2286,6 +2290,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
22862290

22872291
ses->sectype = ctx->sectype;
22882292
ses->sign = ctx->sign;
2293+
ses->local_nls = load_nls(ctx->local_nls->charset);
22892294

22902295
/* add server as first channel */
22912296
spin_lock(&ses->chan_lock);

fs/smb/client/misc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)
9595
return;
9696
}
9797

98+
unload_nls(buf_to_free->local_nls);
9899
atomic_dec(&sesInfoAllocCount);
99100
kfree(buf_to_free->serverOS);
100101
kfree(buf_to_free->serverDomain);

fs/smb/client/smb2pdu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
242242
}
243243
spin_unlock(&server->srv_lock);
244244

245-
nls_codepage = load_nls_default();
245+
nls_codepage = ses->local_nls;
246246

247247
/*
248248
* need to prevent multiple threads trying to simultaneously
@@ -324,7 +324,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
324324
rc = -EAGAIN;
325325
}
326326
failed:
327-
unload_nls(nls_codepage);
328327
return rc;
329328
}
330329

0 commit comments

Comments
 (0)