Skip to content

Commit e14b642

Browse files
paliSteve French
authored andcommitted
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. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent be786e5 commit e14b642

File tree

8 files changed

+54
-4
lines changed

8 files changed

+54
-4
lines changed

fs/smb/client/cifsfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
637637
cifs_sb->ctx->dir_mode);
638638
if (cifs_sb->ctx->iocharset)
639639
seq_printf(s, ",iocharset=%s", cifs_sb->ctx->iocharset);
640+
if (tcon->ses->unicode == 0)
641+
seq_puts(s, ",nounicode");
642+
else if (tcon->ses->unicode == 1)
643+
seq_puts(s, ",unicode");
640644
if (tcon->seal)
641645
seq_puts(s, ",seal");
642646
else if (tcon->ses->server->ignore_signature)

fs/smb/client/cifsglob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ struct smb_version_values {
653653
unsigned int cap_unix;
654654
unsigned int cap_nt_find;
655655
unsigned int cap_large_files;
656+
unsigned int cap_unicode;
656657
__u16 signing_enabled;
657658
__u16 signing_required;
658659
size_t create_lease_size;
@@ -1120,6 +1121,7 @@ struct cifs_ses {
11201121
bool sign; /* is signing required? */
11211122
bool domainAuto:1;
11221123
bool expired_pwd; /* track if access denied or expired pwd so can know if need to update */
1124+
int unicode;
11231125
unsigned int flags;
11241126
__u16 session_flags;
11251127
__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];

fs/smb/client/cifssmb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,10 @@ CIFSSMBNegotiate(const unsigned int xid,
437437
return rc;
438438

439439
pSMB->hdr.Mid = get_next_mid(server);
440-
pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS);
440+
pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS;
441+
442+
if (ses->unicode != 0)
443+
pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
441444

442445
if (should_set_ext_sec_flag(ses->sectype)) {
443446
cifs_dbg(FYI, "Requesting extended security\n");

fs/smb/client/connect.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx)
23512351
ses->cred_uid = ctx->cred_uid;
23522352
ses->linux_uid = ctx->linux_uid;
23532353

2354+
ses->unicode = ctx->unicode;
23542355
ses->sectype = ctx->sectype;
23552356
ses->sign = ctx->sign;
23562357

@@ -4123,7 +4124,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
41234124
struct TCP_Server_Info *server,
41244125
struct nls_table *nls_info)
41254126
{
4126-
int rc = -ENOSYS;
4127+
int rc = 0;
41274128
struct TCP_Server_Info *pserver = SERVER_IS_CHAN(server) ? server->primary_server : server;
41284129
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&pserver->dstaddr;
41294130
struct sockaddr_in *addr = (struct sockaddr_in *)&pserver->dstaddr;
@@ -4175,6 +4176,26 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
41754176
if (!linuxExtEnabled)
41764177
ses->capabilities &= (~server->vals->cap_unix);
41774178

4179+
/*
4180+
* Check if the server supports specified encoding mode.
4181+
* Zero value in vals->cap_unicode indidcates that chosen
4182+
* protocol dialect does not support non-UNICODE mode.
4183+
*/
4184+
if (ses->unicode == 1 && server->vals->cap_unicode != 0 &&
4185+
!(server->capabilities & server->vals->cap_unicode)) {
4186+
cifs_dbg(VFS, "Server does not support mounting in UNICODE mode\n");
4187+
rc = -EOPNOTSUPP;
4188+
} else if (ses->unicode == 0 && server->vals->cap_unicode == 0) {
4189+
cifs_dbg(VFS, "Server does not support mounting in non-UNICODE mode\n");
4190+
rc = -EOPNOTSUPP;
4191+
} else if (ses->unicode == 0) {
4192+
/*
4193+
* When UNICODE mode was explicitly disabled then
4194+
* do not announce client UNICODE capability.
4195+
*/
4196+
ses->capabilities &= (~server->vals->cap_unicode);
4197+
}
4198+
41784199
if (ses->auth_key.response) {
41794200
cifs_dbg(FYI, "Free previous auth_key.response = %p\n",
41804201
ses->auth_key.response);
@@ -4187,8 +4208,12 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
41874208
cifs_dbg(FYI, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d\n",
41884209
server->sec_mode, server->capabilities, server->timeAdj);
41894210

4190-
if (server->ops->sess_setup)
4191-
rc = server->ops->sess_setup(xid, ses, server, nls_info);
4211+
if (!rc) {
4212+
if (server->ops->sess_setup)
4213+
rc = server->ops->sess_setup(xid, ses, server, nls_info);
4214+
else
4215+
rc = -ENOSYS;
4216+
}
41924217

41934218
if (rc) {
41944219
cifs_server_dbg(VFS, "Send error in SessSetup = %d\n", rc);
@@ -4258,6 +4283,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
42584283
ctx->seal = master_tcon->seal;
42594284
ctx->witness = master_tcon->use_witness;
42604285
ctx->dfs_root_ses = master_tcon->ses->dfs_root_ses;
4286+
ctx->unicode = master_tcon->ses->unicode;
42614287

42624288
rc = cifs_set_vol_auth(ctx, master_tcon->ses);
42634289
if (rc) {

fs/smb/client/fs_context.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {
134134
fsparam_flag("compress", Opt_compress),
135135
fsparam_flag("witness", Opt_witness),
136136
fsparam_flag_no("nativesocket", Opt_nativesocket),
137+
fsparam_flag_no("unicode", Opt_unicode),
137138

138139
/* Mount options which take uid or gid */
139140
fsparam_uid("backupuid", Opt_backupuid),
@@ -963,6 +964,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
963964
cifs_errorf(fc, "can not change iocharset during remount\n");
964965
return -EINVAL;
965966
}
967+
if (new_ctx->unicode != old_ctx->unicode) {
968+
cifs_errorf(fc, "can not change unicode during remount\n");
969+
return -EINVAL;
970+
}
966971

967972
return 0;
968973
}
@@ -1638,6 +1643,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
16381643
ctx->witness = true;
16391644
pr_warn_once("Witness protocol support is experimental\n");
16401645
break;
1646+
case Opt_unicode:
1647+
ctx->unicode = !result.negated;
1648+
cifs_dbg(FYI, "unicode set to %d\n", ctx->unicode);
1649+
break;
16411650
case Opt_rootfs:
16421651
#ifndef CONFIG_CIFS_ROOT
16431652
cifs_dbg(VFS, "rootfs support requires CONFIG_CIFS_ROOT config option\n");
@@ -1939,6 +1948,8 @@ int smb3_init_fs_context(struct fs_context *fc)
19391948
ctx->symlink_type = CIFS_SYMLINK_TYPE_DEFAULT;
19401949
ctx->nonativesocket = 0;
19411950

1951+
ctx->unicode = -1; /* autodetect, but prefer UNICODE mode */
1952+
19421953
/*
19431954
* short int override_uid = -1;
19441955
* short int override_gid = -1;

fs/smb/client/fs_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum cifs_param {
135135
Opt_witness,
136136
Opt_is_upcall_target_mount,
137137
Opt_is_upcall_target_application,
138+
Opt_unicode,
138139

139140
/* Mount options which take numeric value */
140141
Opt_backupuid,
@@ -306,6 +307,7 @@ struct smb3_fs_context {
306307
bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */
307308
bool rootfs:1; /* if it's a SMB root file system */
308309
bool witness:1; /* use witness protocol */
310+
int unicode;
309311
char *leaf_fullpath;
310312
struct cifs_ses *dfs_root_ses;
311313
bool dfs_automount:1; /* set for dfs automount only */

fs/smb/client/sess.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ cifs_ses_add_channel(struct cifs_ses *ses,
501501
ctx->password = ses->password;
502502
ctx->sectype = ses->sectype;
503503
ctx->sign = ses->sign;
504+
ctx->unicode = ses->unicode;
504505

505506
/* UNC and paths */
506507
/* XXX: Use ses->server->hostname? */

fs/smb/client/smb1ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ struct smb_version_values smb1_values = {
11701170
.cap_unix = CAP_UNIX,
11711171
.cap_nt_find = CAP_NT_SMBS | CAP_NT_FIND,
11721172
.cap_large_files = CAP_LARGE_FILES,
1173+
.cap_unicode = CAP_UNICODE,
11731174
.signing_enabled = SECMODE_SIGN_ENABLED,
11741175
.signing_required = SECMODE_SIGN_REQUIRED,
11751176
};

0 commit comments

Comments
 (0)