Skip to content

Commit 7d14dd6

Browse files
paliSteve French
authored andcommitted
cifs: Allow to disable or force initialization of NetBIOS session
Currently SMB client always tries to initialize NetBIOS session when the server port is 139. This is useful for default cases, but nowadays when using non-standard routing or testing between VMs, it is common that servers are listening on non-standard ports. So add a new mount option -o nbsessinit and -o nonbsessinit which either forces initialization or disables initialization regardless of server port number. This allows Linux SMB client to connect to older SMB1 server listening on non-standard port, which requires initialization of NetBIOS session, by using additional mount options -o port= and -o nbsessinit. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent b1a37df commit 7d14dd6

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ struct TCP_Server_Info {
714714
spinlock_t srv_lock; /* protect anything here that is not protected */
715715
__u64 conn_id; /* connection identifier (useful for debugging) */
716716
int srv_count; /* reference counter */
717+
int rfc1001_sessinit; /* whether to estasblish netbios session */
717718
/* 15 character server name + 0x20 16th byte indicating type = srv */
718719
char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
719720
struct smb_version_operations *ops;

fs/smb/client/connect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
17011701
ctx->source_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);
17021702
memcpy(tcp_ses->server_RFC1001_name,
17031703
ctx->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);
1704+
tcp_ses->rfc1001_sessinit = ctx->rfc1001_sessinit;
17041705
tcp_ses->session_estab = false;
17051706
tcp_ses->sequence_number = 0;
17061707
tcp_ses->channel_sequence_num = 0; /* only tracked for primary channel */
@@ -3328,7 +3329,15 @@ generic_ip_connect(struct TCP_Server_Info *server)
33283329
return rc;
33293330
}
33303331
trace_smb3_connect_done(server->hostname, server->conn_id, &server->dstaddr);
3331-
if (sport == htons(RFC1001_PORT))
3332+
3333+
/*
3334+
* Establish RFC1001 NetBIOS session when it was explicitly requested
3335+
* by mount option -o nbsessinit, or when connecting to default RFC1001
3336+
* server port (139) and it was not explicitly disabled by mount option
3337+
* -o nonbsessinit.
3338+
*/
3339+
if (server->rfc1001_sessinit == 1 ||
3340+
(server->rfc1001_sessinit == -1 && sport == htons(RFC1001_PORT)))
33323341
rc = ip_rfc1001_connect(server);
33333342

33343343
return rc;

fs/smb/client/fs_context.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = {
135135
fsparam_flag("witness", Opt_witness),
136136
fsparam_flag_no("nativesocket", Opt_nativesocket),
137137
fsparam_flag_no("unicode", Opt_unicode),
138+
fsparam_flag_no("nbsessinit", Opt_nbsessinit),
138139

139140
/* Mount options which take uid or gid */
140141
fsparam_uid("backupuid", Opt_backupuid),
@@ -968,6 +969,10 @@ static int smb3_verify_reconfigure_ctx(struct fs_context *fc,
968969
cifs_errorf(fc, "can not change unicode during remount\n");
969970
return -EINVAL;
970971
}
972+
if (new_ctx->rfc1001_sessinit != old_ctx->rfc1001_sessinit) {
973+
cifs_errorf(fc, "can not change nbsessinit during remount\n");
974+
return -EINVAL;
975+
}
971976

972977
return 0;
973978
}
@@ -1609,6 +1614,10 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
16091614
if (i == RFC1001_NAME_LEN && param->string[i] != 0)
16101615
pr_warn("server netbiosname longer than 15 truncated\n");
16111616
break;
1617+
case Opt_nbsessinit:
1618+
ctx->rfc1001_sessinit = !result.negated;
1619+
cifs_dbg(FYI, "rfc1001_sessinit set to %d\n", ctx->rfc1001_sessinit);
1620+
break;
16121621
case Opt_ver:
16131622
/* version of mount userspace tools, not dialect */
16141623
/* If interface changes in mount.cifs bump to new ver */
@@ -1896,13 +1905,16 @@ int smb3_init_fs_context(struct fs_context *fc)
18961905
memset(ctx->source_rfc1001_name, 0x20, RFC1001_NAME_LEN);
18971906
for (i = 0; i < strnlen(nodename, RFC1001_NAME_LEN); i++)
18981907
ctx->source_rfc1001_name[i] = toupper(nodename[i]);
1899-
19001908
ctx->source_rfc1001_name[RFC1001_NAME_LEN] = 0;
1909+
19011910
/*
19021911
* null target name indicates to use *SMBSERVR default called name
19031912
* if we end up sending RFC1001 session initialize
19041913
*/
19051914
ctx->target_rfc1001_name[0] = 0;
1915+
1916+
ctx->rfc1001_sessinit = -1; /* autodetect based on port number */
1917+
19061918
ctx->cred_uid = current_uid();
19071919
ctx->linux_uid = current_uid();
19081920
ctx->linux_gid = current_gid();

fs/smb/client/fs_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ enum cifs_param {
174174
Opt_iocharset,
175175
Opt_netbiosname,
176176
Opt_servern,
177+
Opt_nbsessinit,
177178
Opt_ver,
178179
Opt_vers,
179180
Opt_sec,
@@ -216,6 +217,7 @@ struct smb3_fs_context {
216217
char *iocharset; /* local code page for mapping to and from Unicode */
217218
char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
218219
char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
220+
int rfc1001_sessinit;
219221
kuid_t cred_uid;
220222
kuid_t linux_uid;
221223
kgid_t linux_gid;

0 commit comments

Comments
 (0)