From patchwork Mon Jul 24 02:10:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Winston Wen X-Patchwork-Id: 13323380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D06E8C001DC for ; Mon, 24 Jul 2023 02:15:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231217AbjGXCP5 (ORCPT ); Sun, 23 Jul 2023 22:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbjGXCPm (ORCPT ); Sun, 23 Jul 2023 22:15:42 -0400 Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C517B2111; Sun, 23 Jul 2023 19:14:05 -0700 (PDT) X-QQ-mid: bizesmtp78t1690164740tg9ld4pi Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 24 Jul 2023 10:11:58 +0800 (CST) X-QQ-SSF: 01400000000000F0I000000A0000000 X-QQ-FEAT: RumxddD8MdA+0nVTY5mTz+KglAS8oWEoRwf/bUWEYT3aQ269LJW73I/Uu+q2v FkUX5/tO3YkHDQS0XJZmnh2Jxb+IVtCA0PYpS2Uu7u2l2OS3uOrVuS4rqcFaxgyLX2hnJNw JbHg70O3xkWPWaPi665gZkFuuwOW4M8ZzHBZ8CMgrsin//3F98LHgvqaZlXK3All5ePWIMS uSdAyLMLBiK4ec5GrhTuVZKNvNkPHx0Nc5Fdu5DI5sLIPtVKXPimpOXmdDQg14vtjpXgqta rfca7ZGT6cS2ei/naFX4SXWbyP9jn8AQwKhxHzJxApdBWbrRvbC7n/RzLwdK1jLwzhmeMGm GyN4CzKspLHj1ZVzfCG5o2upMkgmXyicU/+YmoVqXxvdJf+M0N2yFXEgpcpRr+SLZTsig5J FOZF1Z9JAn4= X-QQ-GoodBg: 1 X-BIZMAIL-ID: 18095699350768677073 From: Winston Wen To: Steve French , Alexander Viro , Christian Brauner , linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Winston Wen , Stephen Rothwell , Paulo Alcantara Subject: [PATCH 1/2] fs/nls: make load_nls() take a const parameter Date: Mon, 24 Jul 2023 10:10:56 +0800 Message-Id: <20230724021057.2958991-2-wentao@uniontech.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724021057.2958991-1-wentao@uniontech.com> References: <20230724021057.2958991-1-wentao@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org load_nls() take a char * parameter, use it to find nls module in list or construct the module name to load it. This change make load_nls() take a const parameter, so we don't need do some cast like this: ses->local_nls = load_nls((char *)ctx->local_nls->charset); Suggested-by: Stephen Rothwell Signed-off-by: Winston Wen Reviewed-by: Paulo Alcantara Reviewed-by: Christian Brauner --- fs/nls/nls_base.c | 4 ++-- include/linux/nls.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c index 52ccd34b1e79..a026dbd3593f 100644 --- a/fs/nls/nls_base.c +++ b/fs/nls/nls_base.c @@ -272,7 +272,7 @@ int unregister_nls(struct nls_table * nls) return -EINVAL; } -static struct nls_table *find_nls(char *charset) +static struct nls_table *find_nls(const char *charset) { struct nls_table *nls; spin_lock(&nls_lock); @@ -288,7 +288,7 @@ static struct nls_table *find_nls(char *charset) return nls; } -struct nls_table *load_nls(char *charset) +struct nls_table *load_nls(const char *charset) { return try_then_request_module(find_nls(charset), "nls_%s", charset); } diff --git a/include/linux/nls.h b/include/linux/nls.h index 499e486b3722..e0bf8367b274 100644 --- a/include/linux/nls.h +++ b/include/linux/nls.h @@ -47,7 +47,7 @@ enum utf16_endian { /* nls_base.c */ extern int __register_nls(struct nls_table *, struct module *); extern int unregister_nls(struct nls_table *); -extern struct nls_table *load_nls(char *); +extern struct nls_table *load_nls(const char *charset); extern void unload_nls(struct nls_table *); extern struct nls_table *load_nls_default(void); #define register_nls(nls) __register_nls((nls), THIS_MODULE) From patchwork Mon Jul 24 02:10:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Winston Wen X-Patchwork-Id: 13323386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E9B2C001B0 for ; Mon, 24 Jul 2023 02:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229548AbjGXC1G (ORCPT ); Sun, 23 Jul 2023 22:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbjGXC1E (ORCPT ); Sun, 23 Jul 2023 22:27:04 -0400 Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E35911B2; Sun, 23 Jul 2023 19:26:38 -0700 (PDT) X-QQ-mid: bizesmtp78t1690164752tggch2gi Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 24 Jul 2023 10:12:24 +0800 (CST) X-QQ-SSF: 01400000000000F0I000000A0000000 X-QQ-FEAT: zT6n3Y95oi2Cl8HTEJaV8QLCzDOwqIswU3tSII1nlVeqIaqwntzGWcesdfnhk FIR4I5Wvvy3CizUvFZXIOHr4pMxJpAVy0J9xEAMRgnTz0Pzhv39Z1ecN2jhOQvN2L2YzKmW mM92SOv+8QlOF2wI8BTJx28iG9vw2NX1mIHgATOpk/1AKVo3fcT5SZqPmW+PZsoOlcU4QOU 1XrSEBi0c4Fx7M81iFEDnF41vFV4/4AJHqL3fEvHwjCT6ZFzVLHKR1Axl/TMgrU1XIjfxYF 4sjz2/ldBu/61n9T843omaMsG4Z58DK7F1UXJEtQ/dLVFu+VpKEh5cKos95rfSJlLQI8Dbp WPRZEkfbsVMxFvBBuEs7gSjPbxw/8s+zUhYWdQRmlFUImVoOatd+da1FtjMekaA0fiRVFyA mXzvCOS7l0VhS39NJaAp5A== X-QQ-GoodBg: 1 X-BIZMAIL-ID: 5556009522538608373 From: Winston Wen To: Steve French , Alexander Viro , Christian Brauner , linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Winston Wen , Paulo Alcantara Subject: [PATCH 2/2] cifs: fix charset issue in reconnection Date: Mon, 24 Jul 2023 10:10:57 +0800 Message-Id: <20230724021057.2958991-3-wentao@uniontech.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230724021057.2958991-1-wentao@uniontech.com> References: <20230724021057.2958991-1-wentao@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz6a-1 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 Reviewed-by: Paulo Alcantara --- fs/smb/client/cifsglob.h | 1 + fs/smb/client/cifssmb.c | 3 +-- fs/smb/client/connect.c | 5 +++++ fs/smb/client/misc.c | 1 + fs/smb/client/smb2pdu.c | 3 +-- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index e5eec6d38d02..657dee4b2c8c 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -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 diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c index 9dee267f1893..25503f1a4fd2 100644 --- a/fs/smb/client/cifssmb.c +++ b/fs/smb/client/cifssmb.c @@ -129,7 +129,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) } spin_unlock(&server->srv_lock); - nls_codepage = load_nls_default(); + nls_codepage = ses->local_nls; /* * need to prevent multiple threads trying to simultaneously @@ -200,7 +200,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) rc = -EAGAIN; } - unload_nls(nls_codepage); return rc; } diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 9280e253bf09..238538dde4e3 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -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; } @@ -2286,6 +2290,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); diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c index 70dbfe6584f9..d7e85d9a2655 100644 --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -95,6 +95,7 @@ sesInfoFree(struct cifs_ses *buf_to_free) return; } + unload_nls(buf_to_free->local_nls); atomic_dec(&sesInfoAllocCount); kfree(buf_to_free->serverOS); kfree(buf_to_free->serverDomain); diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index e04766fe6f80..a457f07f820d 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -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; }