cifs: Fixes for SMB1 non-UNICODE 8-bit mode
Subsystems (2)
cover cifs: Fixes for SMB1 non-UNICODE 8-bit mode
SMB1 protocol supports non-UNICODE (8-bit OEM character set) and UNICODE (UTF-16) modes. Linux SMB1 client implements both of them but there are few bugs in processing non-UNICODE mode.
This patch series add a new mount option -o nounicode to disable UNICODE mode and force usage of non-UNICODE (8-bit OEM character set) mode. This allows to test non-UNICODE code path against modern/recent SMB servers which implements and prefer UNICODE mode.
And this patch series fixes SMB1 session setup and reading symlinks when UNICODE mode is not active.
Tested against Windows Server 2022 SMB1 server and older Samba SMB1 server.
Pali Rohár (5):
cifs: Add new mount option -o nounicode to disable SMB1 UNICODE mode
cifs: Fix encoding of SMB1 Session Setup Kerberos Request in
non-UNICODE mode
cifs: Add support for SMB1 Session Setup NTLMSSP Request in
non-UNICODE mode
cifs: Fix parsing reparse point with native symlink in SMB1
non-UNICODE session
cifs: Remove unicode parameter from parse_reparse_point() function
fs/smb/client/cifsfs.c | 4 ++ fs/smb/client/cifsglob.h | 2 + fs/smb/client/cifsproto.h | 2 +- fs/smb/client/cifssmb.c | 5 ++- fs/smb/client/connect.c | 32 +++++++++++++-- fs/smb/client/fs_context.c | 11 ++++++ fs/smb/client/fs_context.h | 2 + fs/smb/client/reparse.c | 25 ++++++------ fs/smb/client/sess.c | 81 ++++++++++++++++++++++++-------------- fs/smb/client/smb1ops.c | 4 +- fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2proto.h | 2 +- 12 files changed, 118 insertions(+), 53 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/5 cifs: Add new mount option -o nounicode to disable SMB1 UNICODE mode
SMB1 protocol supports non-UNICODE (8-bit OEM character set) and UNICODE (UTF-16) modes.
Linux SMB1 client implements both of them but currently does not allow to choose non-UNICODE mode when SMB1 server announce UNICODE mode support.
This change adds a new mount option -o nounicode to disable UNICODE mode and force usage of non-UNICODE (8-bit OEM character set) mode.
This allows to test non-UNICODE implementation of Linux SMB1 client against any SMB1 server, including modern and recent Windows SMB1 server.
--- fs/smb/client/cifsfs.c | 4 ++++ fs/smb/client/cifsglob.h | 2 ++ fs/smb/client/cifssmb.c | 5 ++++- fs/smb/client/connect.c | 32 +++++++++++++++++++++++++++++--- fs/smb/client/fs_context.c | 11 +++++++++++ fs/smb/client/fs_context.h | 2 ++ fs/smb/client/sess.c | 1 + fs/smb/client/smb1ops.c | 1 + 8 files changed, 54 insertions(+), 4 deletions(-)
fs/smb/client/cifsfs.c +4 -0
@@ -611,6 +611,10 @@ cifs_show_options(struct seq_file *s, struct dentry *root) cifs_sb->ctx->dir_mode);if (cifs_sb->ctx->iocharset)seq_printf (s,",iocharset=%s" , cifs_sb->ctx->iocharset); +if (tcon->ses->unicode ==0 ) +seq_puts (s,",nounicode" ); +else if (tcon->ses->unicode ==1 ) +seq_puts (s,",unicode" );if (tcon->seal)seq_puts (s,",seal" );else if (tcon->ses->server->ignore_signature)
fs/smb/client/cifsglob.h +2 -0
@@ -651,6 +651,7 @@ struct smb_version_values {unsigned int cap_unix;unsigned int cap_nt_find;unsigned int cap_large_files; +unsigned int cap_unicode;__u16 signing_enabled;__u16 signing_required;size_t create_lease_size;
@@ -1124,6 +1125,7 @@ struct cifs_ses {bool sign;/* is signing required? */ bool domainAuto:1;bool expired_pwd;/* track if access denied or expired pwd so can know if need to update */ +int unicode;unsigned int flags;__u16 session_flags;__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE ];
fs/smb/client/cifssmb.c +4 -1
@@ -423,7 +423,10 @@ CIFSSMBNegotiate(const unsigned int xid,return rc; pSMB->hdr.Mid =get_next_mid (server); - pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE |SMBFLG2_ERR_STATUS ); + pSMB->hdr.Flags2 |=SMBFLG2_ERR_STATUS ; + +if (ses->unicode !=0 ) + pSMB->hdr.Flags2 |=SMBFLG2_UNICODE ;if (should_set_ext_sec_flag (ses->sectype)) {cifs_dbg (FYI ,"Requesting extended security\n" );
fs/smb/client/connect.c +29 -3
@@ -2338,6 +2338,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) ses->cred_uid = ctx->cred_uid; ses->linux_uid = ctx->linux_uid; + ses->unicode = ctx->unicode; ses->sectype = ctx->sectype; ses->sign = ctx->sign; ses->local_nls =load_nls (ctx->local_nls->charset);
@@ -3928,7 +3929,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,struct TCP_Server_Info *server, struct nls_table *nls_info) { - int rc = -ENOSYS; + int rc = 0;struct TCP_Server_Info *pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr;struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr;
@@ -3980,6 +3981,26 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,if (!linuxExtEnabled) ses->capabilities &= (~server->vals->cap_unix); +/* +* Check if the server supports specified encoding mode. +* Zero value in vals->cap_unicode indidcates that chosen +* protocol dialect does not support non-UNICODE mode. +*/ +if (ses->unicode ==1 && server->vals->cap_unicode !=0 && + !(server->capabilities & server->vals->cap_unicode)) { +cifs_dbg (VFS ,"Server does not support mounting in UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 && server->vals->cap_unicode ==0 ) { +cifs_dbg (VFS ,"Server does not support mounting in non-UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 ) { +/* +* When UNICODE mode was explicitly disabled then +* do not announce client UNICODE capability. +*/ + ses->capabilities &= (~server->vals->cap_unicode); + } +if (ses->auth_key.response) {cifs_dbg (FYI ,"Free previous auth_key.response = %p\n" , ses->auth_key.response);
@@ -3992,8 +4013,12 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,cifs_dbg (FYI ,"Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d\n" , server->sec_mode, server->capabilities, server->timeAdj); -if (server->ops->sess_setup) - rc = server->ops->sess_setup (xid, ses, server, nls_info); +if (!rc) { +if (server->ops->sess_setup) + rc = server->ops->sess_setup (xid, ses, server, nls_info); +else + rc = -ENOSYS ; + }if (rc) {cifs_server_dbg (VFS ,"Send error in SessSetup = %d\n" , rc);
@@ -4063,6 +4088,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) ctx->seal = master_tcon->seal; ctx->witness = master_tcon->use_witness; ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; + ctx->unicode = master_tcon->ses->unicode; rc =cifs_set_vol_auth (ctx, master_tcon->ses);if (rc) {
fs/smb/client/fs_context.c +11 -0
@@ -127,6 +127,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {fsparam_flag ("rootfs" , Opt_rootfs),fsparam_flag ("compress" , Opt_compress),fsparam_flag ("witness" , Opt_witness), +fsparam_flag_no ("unicode" , Opt_unicode),/* Mount options which take uid or gid */ fsparam_uid("backupuid", Opt_backupuid),
@@ -930,6 +931,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,cifs_errorf (fc,"can not change iocharset during remount\n" );return -EINVAL ; } +if (new_ctx->unicode != old_ctx->unicode) { +cifs_errorf (fc,"can not change unicode during remount\n" ); +return -EINVAL ; + }return 0 ; }
@@ -1520,6 +1525,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->witness = true;pr_warn_once ("Witness protocol support is experimental\n" );break ; +case Opt_unicode: + ctx->unicode = !result.negated; +cifs_dbg (FYI ,"unicode set to %d\n" , ctx->unicode); +break ;case Opt_rootfs:#ifndef CONFIG_CIFS_ROOT cifs_dbg (VFS ,"rootfs support requires CONFIG_CIFS_ROOT config option\n" );
@@ -1816,6 +1825,8 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->symlink_type =CIFS_SYMLINK_TYPE_DEFAULT ; ctx->nonativesocket =0 ; + ctx->unicode =-1 ;/* autodetect, but prefer UNICODE mode */ +/* * short int override_uid = -1; * short int override_gid = -1;
fs/smb/client/fs_context.h +2 -0
@@ -127,6 +127,7 @@ enum cifs_param { Opt_multichannel, Opt_compress, Opt_witness, + Opt_unicode,/* Mount options which take numeric value */ Opt_backupuid,
@@ -296,6 +297,7 @@ struct smb3_fs_context {bool compress;/* enable SMB2 messages (READ/WRITE) de/compression */ bool rootfs:1; /* if it's a SMB root file system */ bool witness:1; /* use witness protocol */ +int unicode;char *leaf_fullpath;struct cifs_ses *dfs_root_ses; bool dfs_automount:1; /* set for dfs automount only */
fs/smb/client/sess.c +1 -0
@@ -529,6 +529,7 @@ cifs_ses_add_channel(struct cifs_ses *ses, ctx->password = ses->password; ctx->sectype = ses->sectype; ctx->sign = ses->sign; + ctx->unicode = ses->unicode;/* UNC and paths */ /* XXX: Use ses->server->hostname? */
fs/smb/client/smb1ops.c +1 -0
@@ -1189,6 +1189,7 @@ struct smb_version_values smb1_values = { .cap_unix = CAP_UNIX, .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND, .cap_large_files = CAP_LARGE_FILES, + .cap_unicode = CAP_UNICODE, .signing_enabled = SECMODE_SIGN_ENABLED, .signing_required = SECMODE_SIGN_REQUIRED, };
Signature · 1 line
2.20.1
Re: [PATCH 1/5] cifs: Add new mount option -o nounicode to disable SMB1 UNICODE mode
you can simply use iocharset=iso8859-1 mount option if you want to get legacy charsets on the client side to work. I don't think that it's a good idea to mess with the ancient non-unicode flag of SMB.
Björn
On 2024-10-28 at 12:03 +0100 Pali Rohár sent off:
Quoted 237 lines
SMB1 protocol supports non-UNICODE (8-bit OEM character set) and UNICODE (UTF-16) modes.
Linux SMB1 client implements both of them but currently does not allow to choose non-UNICODE mode when SMB1 server announce UNICODE mode support.
This change adds a new mount option -o nounicode to disable UNICODE mode and force usage of non-UNICODE (8-bit OEM character set) mode.
This allows to test non-UNICODE implementation of Linux SMB1 client against any SMB1 server, including modern and recent Windows SMB1 server.
Signed-off-by Pali Rohár <[email protected]>--- fs/smb/client/cifsfs.c | 4 ++++ fs/smb/client/cifsglob.h | 2 ++ fs/smb/client/cifssmb.c | 5 ++++- fs/smb/client/connect.c | 32 +++++++++++++++++++++++++++++--- fs/smb/client/fs_context.c | 11 +++++++++++ fs/smb/client/fs_context.h | 2 ++ fs/smb/client/sess.c | 1 + fs/smb/client/smb1ops.c | 1 + 8 files changed, 54 insertions(+), 4 deletions(-)fs/smb/client/cifsfs.c +4
-0@@ -611,6 +611,10 @@ cifs_show_options(struct seq_file *s, struct dentry *root) cifs_sb->ctx->dir_mode);if (cifs_sb->ctx->iocharset)seq_printf (s,",iocharset=%s" , cifs_sb->ctx->iocharset); +if (tcon->ses->unicode ==0 ) +seq_puts (s,",nounicode" ); +else if (tcon->ses->unicode ==1 ) +seq_puts (s,",unicode" );if (tcon->seal)seq_puts (s,",seal" );else if (tcon->ses->server->ignore_signature)fs/smb/client/cifsglob.h +2
-0@@ -651,6 +651,7 @@ struct smb_version_values {unsigned int cap_unix;unsigned int cap_nt_find;unsigned int cap_large_files; +unsigned int cap_unicode;__u16 signing_enabled;__u16 signing_required;size_t create_lease_size;@@ -1124,6 +1125,7 @@ struct cifs_ses {bool sign;/* is signing required? */ bool domainAuto:1;bool expired_pwd;/* track if access denied or expired pwd so can know if need to update */ +int unicode;unsigned int flags;__u16 session_flags;__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE ];fs/smb/client/cifssmb.c +4
-1@@ -423,7 +423,10 @@ CIFSSMBNegotiate(const unsigned int xid,return rc; pSMB->hdr.Mid =get_next_mid (server); - pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE |SMBFLG2_ERR_STATUS ); + pSMB->hdr.Flags2 |=SMBFLG2_ERR_STATUS ; + +if (ses->unicode !=0 ) + pSMB->hdr.Flags2 |=SMBFLG2_UNICODE ;if (should_set_ext_sec_flag (ses->sectype)) {cifs_dbg (FYI ,"Requesting extended security\n" );fs/smb/client/connect.c +29
-3@@ -2338,6 +2338,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) ses->cred_uid = ctx->cred_uid; ses->linux_uid = ctx->linux_uid; + ses->unicode = ctx->unicode; ses->sectype = ctx->sectype; ses->sign = ctx->sign; ses->local_nls =load_nls (ctx->local_nls->charset);@@ -3928,7 +3929,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,struct TCP_Server_Info *server, struct nls_table *nls_info) { - int rc = -ENOSYS; + int rc = 0;struct TCP_Server_Info *pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr;struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr;@@ -3980,6 +3981,26 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,if (!linuxExtEnabled) ses->capabilities &= (~server->vals->cap_unix); +/* +* Check if the server supports specified encoding mode. +* Zero value in vals->cap_unicode indidcates that chosen +* protocol dialect does not support non-UNICODE mode. +*/ +if (ses->unicode ==1 && server->vals->cap_unicode !=0 && + !(server->capabilities & server->vals->cap_unicode)) { +cifs_dbg (VFS ,"Server does not support mounting in UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 && server->vals->cap_unicode ==0 ) { +cifs_dbg (VFS ,"Server does not support mounting in non-UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 ) { +/* +* When UNICODE mode was explicitly disabled then +* do not announce client UNICODE capability. +*/ + ses->capabilities &= (~server->vals->cap_unicode); + } +if (ses->auth_key.response) {cifs_dbg (FYI ,"Free previous auth_key.response = %p\n" , ses->auth_key.response);@@ -3992,8 +4013,12 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,cifs_dbg (FYI ,"Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d\n" , server->sec_mode, server->capabilities, server->timeAdj); -if (server->ops->sess_setup) - rc = server->ops->sess_setup (xid, ses, server, nls_info); +if (!rc) { +if (server->ops->sess_setup) + rc = server->ops->sess_setup (xid, ses, server, nls_info); +else + rc = -ENOSYS ; + }if (rc) {cifs_server_dbg (VFS ,"Send error in SessSetup = %d\n" , rc);@@ -4063,6 +4088,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) ctx->seal = master_tcon->seal; ctx->witness = master_tcon->use_witness; ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; + ctx->unicode = master_tcon->ses->unicode; rc =cifs_set_vol_auth (ctx, master_tcon->ses);if (rc) {fs/smb/client/fs_context.c +11
-0@@ -127,6 +127,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {fsparam_flag ("rootfs" , Opt_rootfs),fsparam_flag ("compress" , Opt_compress),fsparam_flag ("witness" , Opt_witness), +fsparam_flag_no ("unicode" , Opt_unicode),/* Mount options which take uid or gid */ fsparam_uid("backupuid", Opt_backupuid),@@ -930,6 +931,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,cifs_errorf (fc,"can not change iocharset during remount\n" );return -EINVAL ; } +if (new_ctx->unicode != old_ctx->unicode) { +cifs_errorf (fc,"can not change unicode during remount\n" ); +return -EINVAL ; + }return 0 ; }@@ -1520,6 +1525,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->witness = true;pr_warn_once ("Witness protocol support is experimental\n" );break ; +case Opt_unicode: + ctx->unicode = !result.negated; +cifs_dbg (FYI ,"unicode set to %d\n" , ctx->unicode); +break ;case Opt_rootfs:#ifndef CONFIG_CIFS_ROOT cifs_dbg (VFS ,"rootfs support requires CONFIG_CIFS_ROOT config option\n" );@@ -1816,6 +1825,8 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->symlink_type =CIFS_SYMLINK_TYPE_DEFAULT ; ctx->nonativesocket =0 ; + ctx->unicode =-1 ;/* autodetect, but prefer UNICODE mode */ +/* * short int override_uid = -1; * short int override_gid = -1; fs/smb/client/fs_context.h +2
-0@@ -127,6 +127,7 @@ enum cifs_param { Opt_multichannel, Opt_compress, Opt_witness, + Opt_unicode,/* Mount options which take numeric value */ Opt_backupuid,@@ -296,6 +297,7 @@ struct smb3_fs_context {bool compress;/* enable SMB2 messages (READ/WRITE) de/compression */ bool rootfs:1; /* if it's a SMB root file system */ bool witness:1; /* use witness protocol */ +int unicode;char *leaf_fullpath;struct cifs_ses *dfs_root_ses; bool dfs_automount:1; /* set for dfs automount only */fs/smb/client/sess.c +1
-0@@ -529,6 +529,7 @@ cifs_ses_add_channel(struct cifs_ses *ses, ctx->password = ses->password; ctx->sectype = ses->sectype; ctx->sign = ses->sign; + ctx->unicode = ses->unicode;/* UNC and paths */ /* XXX: Use ses->server->hostname? */ fs/smb/client/smb1ops.c +1
-0@@ -1189,6 +1189,7 @@ struct smb_version_values smb1_values = { .cap_unix = CAP_UNIX, .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND, .cap_large_files = CAP_LARGE_FILES, + .cap_unicode = CAP_UNICODE, .signing_enabled = SECMODE_SIGN_ENABLED, .signing_required = SECMODE_SIGN_REQUIRED, };Signature · 1 line
2.20.1
Re: [PATCH 1/5] cifs: Add new mount option -o nounicode to disable SMB1 UNICODE mode
Hello Björn, I know about iocharset=iso8859-1 mount option, but change here is something different. As I wrote in the commit message it allows to easily test that "non-unicode flag of SMB" code path implementation in cifs.ko that works correctly. For example, thanks to this change I was able to find few bugs (including parsing of symlinks) in that code path and fixes for them are in this patch series.
Quoted 244 lines · On Friday 15 November 2024 14:26:19 Björn JACKE wrote:
you can simply use iocharset=iso8859-1 mount option if you want to get legacy charsets on the client side to work. I don't think that it's a good idea to mess with the ancient non-unicode flag of SMB.
Björn
On 2024-10-28 at 12:03 +0100 Pali Rohár sent off:
Quoted 237 lines
SMB1 protocol supports non-UNICODE (8-bit OEM character set) and UNICODE (UTF-16) modes.
Linux SMB1 client implements both of them but currently does not allow to choose non-UNICODE mode when SMB1 server announce UNICODE mode support.
This change adds a new mount option -o nounicode to disable UNICODE mode and force usage of non-UNICODE (8-bit OEM character set) mode.
This allows to test non-UNICODE implementation of Linux SMB1 client against any SMB1 server, including modern and recent Windows SMB1 server.
Signed-off-by Pali Rohár <[email protected]>--- fs/smb/client/cifsfs.c | 4 ++++ fs/smb/client/cifsglob.h | 2 ++ fs/smb/client/cifssmb.c | 5 ++++- fs/smb/client/connect.c | 32 +++++++++++++++++++++++++++++--- fs/smb/client/fs_context.c | 11 +++++++++++ fs/smb/client/fs_context.h | 2 ++ fs/smb/client/sess.c | 1 + fs/smb/client/smb1ops.c | 1 + 8 files changed, 54 insertions(+), 4 deletions(-)fs/smb/client/cifsfs.c +4
-0@@ -611,6 +611,10 @@ cifs_show_options(struct seq_file *s, struct dentry *root) cifs_sb->ctx->dir_mode);if (cifs_sb->ctx->iocharset)seq_printf (s,",iocharset=%s" , cifs_sb->ctx->iocharset); +if (tcon->ses->unicode ==0 ) +seq_puts (s,",nounicode" ); +else if (tcon->ses->unicode ==1 ) +seq_puts (s,",unicode" );if (tcon->seal)seq_puts (s,",seal" );else if (tcon->ses->server->ignore_signature)fs/smb/client/cifsglob.h +2
-0@@ -651,6 +651,7 @@ struct smb_version_values {unsigned int cap_unix;unsigned int cap_nt_find;unsigned int cap_large_files; +unsigned int cap_unicode;__u16 signing_enabled;__u16 signing_required;size_t create_lease_size;@@ -1124,6 +1125,7 @@ struct cifs_ses {bool sign;/* is signing required? */ bool domainAuto:1;bool expired_pwd;/* track if access denied or expired pwd so can know if need to update */ +int unicode;unsigned int flags;__u16 session_flags;__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE ];fs/smb/client/cifssmb.c +4
-1@@ -423,7 +423,10 @@ CIFSSMBNegotiate(const unsigned int xid,return rc; pSMB->hdr.Mid =get_next_mid (server); - pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE |SMBFLG2_ERR_STATUS ); + pSMB->hdr.Flags2 |=SMBFLG2_ERR_STATUS ; + +if (ses->unicode !=0 ) + pSMB->hdr.Flags2 |=SMBFLG2_UNICODE ;if (should_set_ext_sec_flag (ses->sectype)) {cifs_dbg (FYI ,"Requesting extended security\n" );fs/smb/client/connect.c +29
-3@@ -2338,6 +2338,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) ses->cred_uid = ctx->cred_uid; ses->linux_uid = ctx->linux_uid; + ses->unicode = ctx->unicode; ses->sectype = ctx->sectype; ses->sign = ctx->sign; ses->local_nls =load_nls (ctx->local_nls->charset);@@ -3928,7 +3929,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,struct TCP_Server_Info *server, struct nls_table *nls_info) { - int rc = -ENOSYS; + int rc = 0;struct TCP_Server_Info *pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr;struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr;@@ -3980,6 +3981,26 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,if (!linuxExtEnabled) ses->capabilities &= (~server->vals->cap_unix); +/* +* Check if the server supports specified encoding mode. +* Zero value in vals->cap_unicode indidcates that chosen +* protocol dialect does not support non-UNICODE mode. +*/ +if (ses->unicode ==1 && server->vals->cap_unicode !=0 && + !(server->capabilities & server->vals->cap_unicode)) { +cifs_dbg (VFS ,"Server does not support mounting in UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 && server->vals->cap_unicode ==0 ) { +cifs_dbg (VFS ,"Server does not support mounting in non-UNICODE mode\n" ); + rc = -EOPNOTSUPP ; + }else if (ses->unicode ==0 ) { +/* +* When UNICODE mode was explicitly disabled then +* do not announce client UNICODE capability. +*/ + ses->capabilities &= (~server->vals->cap_unicode); + } +if (ses->auth_key.response) {cifs_dbg (FYI ,"Free previous auth_key.response = %p\n" , ses->auth_key.response);@@ -3992,8 +4013,12 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,cifs_dbg (FYI ,"Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d\n" , server->sec_mode, server->capabilities, server->timeAdj); -if (server->ops->sess_setup) - rc = server->ops->sess_setup (xid, ses, server, nls_info); +if (!rc) { +if (server->ops->sess_setup) + rc = server->ops->sess_setup (xid, ses, server, nls_info); +else + rc = -ENOSYS ; + }if (rc) {cifs_server_dbg (VFS ,"Send error in SessSetup = %d\n" , rc);@@ -4063,6 +4088,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) ctx->seal = master_tcon->seal; ctx->witness = master_tcon->use_witness; ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses; + ctx->unicode = master_tcon->ses->unicode; rc =cifs_set_vol_auth (ctx, master_tcon->ses);if (rc) {fs/smb/client/fs_context.c +11
-0@@ -127,6 +127,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {fsparam_flag ("rootfs" , Opt_rootfs),fsparam_flag ("compress" , Opt_compress),fsparam_flag ("witness" , Opt_witness), +fsparam_flag_no ("unicode" , Opt_unicode),/* Mount options which take uid or gid */ fsparam_uid("backupuid", Opt_backupuid),@@ -930,6 +931,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,cifs_errorf (fc,"can not change iocharset during remount\n" );return -EINVAL ; } +if (new_ctx->unicode != old_ctx->unicode) { +cifs_errorf (fc,"can not change unicode during remount\n" ); +return -EINVAL ; + }return 0 ; }@@ -1520,6 +1525,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, ctx->witness = true;pr_warn_once ("Witness protocol support is experimental\n" );break ; +case Opt_unicode: + ctx->unicode = !result.negated; +cifs_dbg (FYI ,"unicode set to %d\n" , ctx->unicode); +break ;case Opt_rootfs:#ifndef CONFIG_CIFS_ROOT cifs_dbg (VFS ,"rootfs support requires CONFIG_CIFS_ROOT config option\n" );@@ -1816,6 +1825,8 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->symlink_type =CIFS_SYMLINK_TYPE_DEFAULT ; ctx->nonativesocket =0 ; + ctx->unicode =-1 ;/* autodetect, but prefer UNICODE mode */ +/* * short int override_uid = -1; * short int override_gid = -1; fs/smb/client/fs_context.h +2
-0@@ -127,6 +127,7 @@ enum cifs_param { Opt_multichannel, Opt_compress, Opt_witness, + Opt_unicode,/* Mount options which take numeric value */ Opt_backupuid,@@ -296,6 +297,7 @@ struct smb3_fs_context {bool compress;/* enable SMB2 messages (READ/WRITE) de/compression */ bool rootfs:1; /* if it's a SMB root file system */ bool witness:1; /* use witness protocol */ +int unicode;char *leaf_fullpath;struct cifs_ses *dfs_root_ses; bool dfs_automount:1; /* set for dfs automount only */fs/smb/client/sess.c +1
-0@@ -529,6 +529,7 @@ cifs_ses_add_channel(struct cifs_ses *ses, ctx->password = ses->password; ctx->sectype = ses->sectype; ctx->sign = ses->sign; + ctx->unicode = ses->unicode;/* UNC and paths */ /* XXX: Use ses->server->hostname? */ fs/smb/client/smb1ops.c +1
-0@@ -1189,6 +1189,7 @@ struct smb_version_values smb1_values = { .cap_unix = CAP_UNIX, .cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND, .cap_large_files = CAP_LARGE_FILES, + .cap_unicode = CAP_UNICODE, .signing_enabled = SECMODE_SIGN_ENABLED, .signing_required = SECMODE_SIGN_REQUIRED, };Signature · 1 line
2.20.1
PATCH 2/5 cifs: Fix encoding of SMB1 Session Setup Kerberos Request in non-UNICODE mode
In reply to Pali RohárLike in UNICODE mode, SMB1 Session Setup Kerberos Request contains oslm and domain strings.
Extract common code into ascii_oslm_strings() and ascii_domain_string() functions (similar to unicode variants) and use these functions in non-UNICODE code path in sess_auth_kerberos().
Decision if non-UNICODE or UNICODE mode is used is based on the SMBFLG2_UNICODE flag in Flags2 packed field, and not based on the capabilities of server. Fix this check too.
--- fs/smb/client/sess.c | 60 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-)
fs/smb/client/sess.c +40 -20
@@ -701,6 +701,22 @@ unicode_oslm_strings(char **pbcc_area, const struct nls_table *nls_cp) *pbcc_area = bcc_ptr; } +static void +ascii_oslm_strings (char **pbcc_area,const struct nls_table *nls_cp) +{ +char *bcc_ptr = *pbcc_area; + +strcpy (bcc_ptr,"Linux version " ); + bcc_ptr +=strlen ("Linux version " ); +strcpy (bcc_ptr,init_utsname ()->release); + bcc_ptr +=strlen (init_utsname ()->release) +1 ; + +strcpy (bcc_ptr,CIFS_NETWORK_OPSYS ); + bcc_ptr +=strlen (CIFS_NETWORK_OPSYS ) +1 ; + + *pbcc_area = bcc_ptr; +} +static void unicode_domain_string (char **pbcc_area,struct cifs_ses *ses,const struct nls_table *nls_cp) {
@@ -725,6 +741,25 @@ static void unicode_domain_string(char **pbcc_area, struct cifs_ses *ses, *pbcc_area = bcc_ptr; } +static void ascii_domain_string (char **pbcc_area,struct cifs_ses *ses, +const struct nls_table *nls_cp) +{ +char *bcc_ptr = *pbcc_area; +int len; + +/* copy domain */ +if (ses->domainName !=NULL ) { + len =strscpy (bcc_ptr, ses->domainName,CIFS_MAX_DOMAINNAME_LEN ); +if (WARN_ON_ONCE (len <0 )) + len =CIFS_MAX_DOMAINNAME_LEN -1 ; + bcc_ptr += len; + }/* else we send a null domain name so server will default to its own domain */ + *bcc_ptr =0 ; + bcc_ptr++; + + *pbcc_area = bcc_ptr; +} +static void unicode_ssetup_strings (char **pbcc_area,struct cifs_ses *ses,const struct nls_table *nls_cp) {
@@ -770,25 +805,10 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifs_ses *ses, *bcc_ptr =0 ; bcc_ptr++;/* account for null termination */ -/* copy domain */ -if (ses->domainName !=NULL ) { - len =strscpy (bcc_ptr, ses->domainName,CIFS_MAX_DOMAINNAME_LEN ); -if (WARN_ON_ONCE (len <0 )) - len =CIFS_MAX_DOMAINNAME_LEN -1 ; - bcc_ptr += len; - }/* else we send a null domain name so server will default to its own domain */ - *bcc_ptr =0 ; - bcc_ptr++; -/* BB check for overflow here */ -strcpy (bcc_ptr,"Linux version " ); - bcc_ptr +=strlen ("Linux version " ); -strcpy (bcc_ptr,init_utsname ()->release); - bcc_ptr +=strlen (init_utsname ()->release) +1 ; - -strcpy (bcc_ptr,CIFS_NETWORK_OPSYS ); - bcc_ptr +=strlen (CIFS_NETWORK_OPSYS ) +1 ; +ascii_domain_string (&bcc_ptr, ses, nls_cp); +ascii_oslm_strings (&bcc_ptr, nls_cp); *pbcc_area = bcc_ptr; }
@@ -1590,7 +1610,7 @@ sess_auth_kerberos(struct sess_data *sess_data) sess_data->iov[1 ].iov_len = msg->secblob_len; pSMB->req.SecurityBlobLength =cpu_to_le16 (sess_data->iov[1 ].iov_len); -if (ses->capabilities &CAP_UNICODE ) { +if (pSMB->req.hdr.Flags2 &SMBFLG2_UNICODE ) {/* unicode strings must be word aligned */ if (!IS_ALIGNED (sess_data->iov[0 ].iov_len + sess_data->iov[1 ].iov_len,2 )) { *bcc_ptr =0 ;
@@ -1599,8 +1619,8 @@ sess_auth_kerberos(struct sess_data *sess_data)unicode_oslm_strings (&bcc_ptr, sess_data->nls_cp);unicode_domain_string (&bcc_ptr, ses, sess_data->nls_cp); }else { -/* BB: is this right? */ -ascii_ssetup_strings (&bcc_ptr, ses, sess_data->nls_cp); +ascii_oslm_strings (&bcc_ptr, sess_data->nls_cp); +ascii_domain_string (&bcc_ptr, ses, sess_data->nls_cp); } sess_data->iov[2].iov_len = (long) bcc_ptr -
Signature · 1 line
2.20.1
PATCH 3/5 cifs: Add support for SMB1 Session Setup NTLMSSP Request in non-UNICODE mode
In reply to Pali RohárSMB1 Session Setup NTLMSSP Request in non-UNICODE mode is similar to UNICODE mode, just strings are encoded in ASCII and not in UTF-16.
With this change it is possible to setup SMB1 session with NTLM authentication in non-UNICODE mode with Windows SMB server.
--- fs/smb/client/sess.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/smb/client/sess.c +10 -10
@@ -1704,22 +1704,22 @@ _sess_auth_rawntlmssp_assemble_req(struct sess_data *sess_data) pSMB = (SESSION_SETUP_ANDX *)sess_data->iov[0 ].iov_base; capabilities =cifs_ssetup_hdr (ses, server, pSMB); -if ((pSMB->req.hdr.Flags2 &SMBFLG2_UNICODE ) ==0 ) { -cifs_dbg (VFS ,"NTLMSSP requires Unicode support\n" ); -return -ENOSYS ; - } - pSMB->req.hdr.Flags2 |=SMBFLG2_EXT_SEC ; capabilities |=CAP_EXTENDED_SECURITY ; pSMB->req.Capabilities |=cpu_to_le32 (capabilities); bcc_ptr = sess_data->iov[2 ].iov_base; -/* unicode strings must be word aligned */ -if (!IS_ALIGNED (sess_data->iov[0 ].iov_len + sess_data->iov[1 ].iov_len,2 )) { - *bcc_ptr =0 ; - bcc_ptr++; + +if (pSMB->req.hdr.Flags2 &SMBFLG2_UNICODE ) { +/* unicode strings must be word aligned */ +if (!IS_ALIGNED (sess_data->iov[0 ].iov_len + sess_data->iov[1 ].iov_len,2 )) { + *bcc_ptr =0 ; + bcc_ptr++; + } +unicode_oslm_strings (&bcc_ptr, sess_data->nls_cp); + }else { +ascii_oslm_strings (&bcc_ptr, sess_data->nls_cp); } -unicode_oslm_strings (&bcc_ptr, sess_data->nls_cp); sess_data->iov[2 ].iov_len = (long ) bcc_ptr - (long ) sess_data->iov[2 ].iov_base;
Signature · 1 line
2.20.1
PATCH 4/5 cifs: Fix parsing reparse point with native symlink in SMB1 non-UNICODE session
In reply to Pali RohárSMB1 NT_TRANSACT_IOCTL/FSCTL_GET_REPARSE_POINT even in non-UNICODE mode returns reparse buffer in UNICODE/UTF-16 format.
This is because FSCTL_GET_REPARSE_POINT is NT-based IOCTL which does not distinguish between 8-bit non-UNICODE and 16-bit UNICODE modes and its path buffers are always encoded in UTF-16.
This change fixes reading of native symlinks in SMB1 when UNICODE session is not active.
--- fs/smb/client/smb1ops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/smb/client/smb1ops.c +1 -2
@@ -1000,12 +1000,11 @@ static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb, {struct reparse_data_buffer *buf;TRANSACT_IOCTL_RSP *io = rsp_iov->iov_base; -bool unicode = !!(io->hdr.Flags2 &SMBFLG2_UNICODE );u32 plen =le16_to_cpu (io->ByteCount); buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +le32_to_cpu (io->DataOffset)); -return parse_reparse_point (buf, plen, cifs_sb, full_path, unicode, data); +return parse_reparse_point (buf, plen, cifs_sb, full_path, true, data); } static bool
Signature · 1 line
2.20.1
PATCH 5/5 cifs: Remove unicode parameter from parse_reparse_point() function
In reply to Pali RohárThis parameter is always true, so remove it and also remove dead code which is never called (for all false code paths).
--- fs/smb/client/cifsproto.h | 2 +- fs/smb/client/reparse.c | 25 +++++++++++-------------- fs/smb/client/smb1ops.c | 2 +- fs/smb/client/smb2file.c | 1 - fs/smb/client/smb2proto.h | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-)
fs/smb/client/cifsproto.h +1 -1
@@ -667,7 +667,7 @@ char *extract_sharename(const char *unc);int parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb,const char *full_path, -bool unicode,struct cifs_open_info_data *data); +struct cifs_open_info_data *data); int __cifs_sfu_make_node(unsigned int xid, struct inode *inode, struct dentry *dentry, struct cifs_tcon *tcon, const char *full_path, umode_t mode, dev_t dev,
fs/smb/client/reparse.c +11 -14
@@ -775,7 +775,7 @@ static int parse_reparse_posix(struct reparse_posix_data *buf, }int smb2_parse_native_symlink (char **target,const char *buf,unsigned int len, -bool unicode,bool relative, +bool relative,const char *full_path,struct cifs_sb_info *cifs_sb) {
@@ -789,26 +789,24 @@ int smb2_parse_native_symlink(char **target, const char *buf, unsigned int len,int rc;int i; -/* Check that length it valid for unicode/non-unicode mode */ -if (!len || (unicode && (len %2 ))) { +/* Check that length it valid */ +if (!len || (len %2 )) {cifs_dbg (VFS ,"srv returned malformed symlink buffer\n" ); rc = -EIO ; goto out; }/* -* Check that buffer does not contain UTF-16 null codepoint in unicode -* mode or null byte in non-unicode mode because Linux cannot process -* symlink with null byte. +* Check that buffer does not contain UTF-16 null codepoint +* because Linux cannot process symlink with null byte. */ -if ((unicode &&UniStrnlen ((wchar_t *)buf, len/2 ) != len/2 ) || - (!unicode &&strnlen (buf, len) != len)) { +if (UniStrnlen ((wchar_t *)buf, len/2 ) != len/2 ) {cifs_dbg (VFS ,"srv returned null byte in native symlink target location\n" ); rc = -EIO ; goto out; } - smb_target =cifs_strndup_from_utf16 (buf, len, unicode, cifs_sb->local_nls); + smb_target =cifs_strndup_from_utf16 (buf, len, true, cifs_sb->local_nls);if (!smb_target) { rc = -ENOMEM ; goto out;
@@ -985,7 +983,7 @@ int smb2_parse_native_symlink(char **target, const char *buf, unsigned int len, }static int parse_reparse_native_symlink (struct reparse_symlink_data_buffer *sym, -u32 plen,bool unicode, +u32 plen,struct cifs_sb_info *cifs_sb,const char *full_path,struct cifs_open_info_data *data)
@@ -1005,7 +1003,6 @@ static int parse_reparse_native_symlink(struct reparse_symlink_data_buffer *sym,return smb2_parse_native_symlink (&data->symlink_target, sym->PathBuffer + offs, len, - unicode,le32_to_cpu (sym->Flags) &SYMLINK_FLAG_RELATIVE , full_path, cifs_sb);
@@ -1060,7 +1057,7 @@ static int parse_reparse_wsl_symlink(struct reparse_wsl_symlink_data_buffer *bufint parse_reparse_point (struct reparse_data_buffer *buf,u32 plen,struct cifs_sb_info *cifs_sb,const char *full_path, -bool unicode,struct cifs_open_info_data *data) +struct cifs_open_info_data *data) {struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb);
@@ -1074,7 +1071,7 @@ int parse_reparse_point(struct reparse_data_buffer *buf,case IO_REPARSE_TAG_SYMLINK :return parse_reparse_native_symlink ( (struct reparse_symlink_data_buffer *)buf, - plen, unicode, cifs_sb, full_path, data); + plen, cifs_sb, full_path, data);case IO_REPARSE_TAG_LX_SYMLINK : return parse_reparse_wsl_symlink( (struct reparse_wsl_symlink_data_buffer *)buf,
@@ -1108,7 +1105,7 @@ int smb2_parse_reparse_point(struct cifs_sb_info *cifs_sb, buf = (struct reparse_data_buffer *)((u8 *)io +le32_to_cpu (io->OutputOffset)); -return parse_reparse_point (buf, plen, cifs_sb, full_path, true, data); +return parse_reparse_point (buf, plen, cifs_sb, full_path, data); } static void wsl_to_fattr(struct cifs_open_info_data *data,
fs/smb/client/smb1ops.c +1 -1
@@ -1004,7 +1004,7 @@ static int cifs_parse_reparse_point(struct cifs_sb_info *cifs_sb, buf = (struct reparse_data_buffer *)((__u8 *)&io->hdr.Protocol +le32_to_cpu (io->DataOffset)); -return parse_reparse_point (buf, plen, cifs_sb, full_path, true, data); +return parse_reparse_point (buf, plen, cifs_sb, full_path, data); } static bool
fs/smb/client/smb2file.c +0 -1
@@ -132,7 +132,6 @@ int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvecreturn smb2_parse_native_symlink (path, (char *)sym->PathBuffer + sub_offs, sub_len, - true,le32_to_cpu (sym->Flags) &SYMLINK_FLAG_RELATIVE , full_path, cifs_sb);
fs/smb/client/smb2proto.h +1 -1
@@ -115,7 +115,7 @@ extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, unsigned int *pbytes_read);int smb2_fix_symlink_target_type (char **target,bool directory,struct cifs_sb_info *cifs_sb);int smb2_parse_native_symlink (char **target,const char *buf,unsigned int len, -bool unicode,bool relative, +bool relative,const char *full_path,struct cifs_sb_info *cifs_sb); int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb,
Signature · 1 line
2.20.1