Skip to content

Commit 61d5614

Browse files
sprasad-microsoftpopcornmix
authored andcommitted
cifs: serialize other channels when query server interfaces is pending
commit b5e3e6e upstream. Today, during smb2_reconnect, session_mutex is released as soon as the tcon is reconnected and is in a good state. However, in case multichannel is enabled, there is also a query of server interfaces that follows. We've seen that this query can race with reconnects of other channels, causing them to step on each other with reconnects. This change extends the hold of session_mutex till after the query of server interfaces is complete. In order to avoid recursive smb2_reconnect checks during query ioctl, this change also introduces a session flag for sessions where such a query is in progress. Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3dac422 commit 61d5614

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ struct cifs_chan {
10581058
};
10591059

10601060
#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1)
1061+
#define CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES (0x2)
10611062

10621063
/*
10631064
* Session structure. One of these for each uid session with a particular host

fs/smb/client/smb2pdu.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,19 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
428428
if (!rc &&
429429
(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL) &&
430430
server->ops->query_server_interfaces) {
431-
mutex_unlock(&ses->session_mutex);
432-
433431
/*
434-
* query server network interfaces, in case they change
432+
* query server network interfaces, in case they change.
433+
* Also mark the session as pending this update while the query
434+
* is in progress. This will be used to avoid calling
435+
* smb2_reconnect recursively.
435436
*/
437+
ses->flags |= CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
436438
xid = get_xid();
437439
rc = server->ops->query_server_interfaces(xid, tcon, false);
438440
free_xid(xid);
441+
ses->flags &= ~CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES;
442+
443+
mutex_unlock(&ses->session_mutex);
439444

440445
if (rc == -EOPNOTSUPP && ses->chan_count > 1) {
441446
/*
@@ -577,11 +582,18 @@ static int smb2_ioctl_req_init(u32 opcode, struct cifs_tcon *tcon,
577582
struct TCP_Server_Info *server,
578583
void **request_buf, unsigned int *total_len)
579584
{
580-
/* Skip reconnect only for FSCTL_VALIDATE_NEGOTIATE_INFO IOCTLs */
581-
if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO) {
585+
/*
586+
* Skip reconnect in one of the following cases:
587+
* 1. For FSCTL_VALIDATE_NEGOTIATE_INFO IOCTLs
588+
* 2. For FSCTL_QUERY_NETWORK_INTERFACE_INFO IOCTL when called from
589+
* smb2_reconnect (indicated by CIFS_SES_FLAG_SCALE_CHANNELS ses flag)
590+
*/
591+
if (opcode == FSCTL_VALIDATE_NEGOTIATE_INFO ||
592+
(opcode == FSCTL_QUERY_NETWORK_INTERFACE_INFO &&
593+
(tcon->ses->flags & CIFS_SES_FLAGS_PENDING_QUERY_INTERFACES)))
582594
return __smb2_plain_req_init(SMB2_IOCTL, tcon, server,
583595
request_buf, total_len);
584-
}
596+
585597
return smb2_plain_req_init(SMB2_IOCTL, tcon, server,
586598
request_buf, total_len);
587599
}

0 commit comments

Comments
 (0)