Skip to content

Commit 7be3248

Browse files
sprasad-microsoftSteve French
authored and
Steve French
committed
cifs: To match file servers, make sure the server hostname matches
We generally rely on a bunch of factors to differentiate between servers. For example, IP address, port etc. For certain server types (like Azure), it is important to make sure that the server hostname matches too, even if the both hostnames currently resolve to the same IP address. Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3906fe9 commit 7be3248

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

fs/cifs/connect.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
794794
*/
795795
}
796796

797-
kfree(server->hostname);
798797
kfree(server);
799798

800799
length = atomic_dec_return(&tcpSesAllocCount);
@@ -1235,6 +1234,9 @@ static int match_server(struct TCP_Server_Info *server, struct smb3_fs_context *
12351234
if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
12361235
return 0;
12371236

1237+
if (strcasecmp(server->hostname, ctx->server_hostname))
1238+
return 0;
1239+
12381240
if (!match_address(server, addr,
12391241
(struct sockaddr *)&ctx->srcaddr))
12401242
return 0;
@@ -1336,6 +1338,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
13361338
kfree(server->session_key.response);
13371339
server->session_key.response = NULL;
13381340
server->session_key.len = 0;
1341+
kfree(server->hostname);
13391342

13401343
task = xchg(&server->tsk, NULL);
13411344
if (task)
@@ -1361,14 +1364,15 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx)
13611364
goto out_err;
13621365
}
13631366

1367+
tcp_ses->hostname = kstrdup(ctx->server_hostname, GFP_KERNEL);
1368+
if (!tcp_ses->hostname) {
1369+
rc = -ENOMEM;
1370+
goto out_err;
1371+
}
1372+
13641373
tcp_ses->ops = ctx->ops;
13651374
tcp_ses->vals = ctx->vals;
13661375
cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
1367-
tcp_ses->hostname = extract_hostname(ctx->UNC);
1368-
if (IS_ERR(tcp_ses->hostname)) {
1369-
rc = PTR_ERR(tcp_ses->hostname);
1370-
goto out_err_crypto_release;
1371-
}
13721376

13731377
tcp_ses->conn_id = atomic_inc_return(&tcpSesNextId);
13741378
tcp_ses->noblockcnt = ctx->rootfs;
@@ -1497,8 +1501,7 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx)
14971501

14981502
out_err:
14991503
if (tcp_ses) {
1500-
if (!IS_ERR(tcp_ses->hostname))
1501-
kfree(tcp_ses->hostname);
1504+
kfree(tcp_ses->hostname);
15021505
if (tcp_ses->ssocket)
15031506
sock_release(tcp_ses->ssocket);
15041507
kfree(tcp_ses);

fs/cifs/fs_context.c

+8
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx
318318
DUP_CTX_STR(mount_options);
319319
DUP_CTX_STR(username);
320320
DUP_CTX_STR(password);
321+
DUP_CTX_STR(server_hostname);
321322
DUP_CTX_STR(UNC);
322323
DUP_CTX_STR(source);
323324
DUP_CTX_STR(domainname);
@@ -456,6 +457,11 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
456457
if (!pos)
457458
return -EINVAL;
458459

460+
/* record the server hostname */
461+
ctx->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL);
462+
if (!ctx->server_hostname)
463+
return -ENOMEM;
464+
459465
/* skip past delimiter */
460466
++pos;
461467

@@ -1496,6 +1502,8 @@ smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx)
14961502
ctx->username = NULL;
14971503
kfree_sensitive(ctx->password);
14981504
ctx->password = NULL;
1505+
kfree(ctx->server_hostname);
1506+
ctx->server_hostname = NULL;
14991507
kfree(ctx->UNC);
15001508
ctx->UNC = NULL;
15011509
kfree(ctx->source);

fs/cifs/fs_context.h

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct smb3_fs_context {
166166
char *password;
167167
char *domainname;
168168
char *source;
169+
char *server_hostname;
169170
char *UNC;
170171
char *nodename;
171172
char *iocharset; /* local code page for mapping to and from Unicode */

0 commit comments

Comments
 (0)