Skip to content

Commit 775e44d

Browse files
Paulo Alcantarasmfrench
authored andcommitted
cifs: fix race in assemble_neg_contexts()
Serialise access of TCP_Server_Info::hostname in assemble_neg_contexts() by holding the server's mutex otherwise it might end up accessing an already-freed hostname pointer from cifs_reconnect() or cifs_resolve_server(). Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Reviewed-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 9e6002c commit 775e44d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/cifs/smb2pdu.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,10 @@ static void
541541
assemble_neg_contexts(struct smb2_negotiate_req *req,
542542
struct TCP_Server_Info *server, unsigned int *total_len)
543543
{
544-
char *pneg_ctxt;
545-
char *hostname = NULL;
546544
unsigned int ctxt_len, neg_context_count;
545+
struct TCP_Server_Info *pserver;
546+
char *pneg_ctxt;
547+
char *hostname;
547548

548549
if (*total_len > 200) {
549550
/* In case length corrupted don't want to overrun smb buffer */
@@ -574,8 +575,9 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
574575
* secondary channels don't have the hostname field populated
575576
* use the hostname field in the primary channel instead
576577
*/
577-
hostname = CIFS_SERVER_IS_CHAN(server) ?
578-
server->primary_server->hostname : server->hostname;
578+
pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
579+
cifs_server_lock(pserver);
580+
hostname = pserver->hostname;
579581
if (hostname && (hostname[0] != 0)) {
580582
ctxt_len = build_netname_ctxt((struct smb2_netname_neg_context *)pneg_ctxt,
581583
hostname);
@@ -584,6 +586,7 @@ assemble_neg_contexts(struct smb2_negotiate_req *req,
584586
neg_context_count = 3;
585587
} else
586588
neg_context_count = 2;
589+
cifs_server_unlock(pserver);
587590

588591
build_posix_ctxt((struct smb2_posix_neg_context *)pneg_ctxt);
589592
*total_len += sizeof(struct smb2_posix_neg_context);

0 commit comments

Comments
 (0)