CIFS: Reconnect expired SMB sessions
authorPavel Shilovsky <pshilov@microsoft.com>
Sat, 8 Jul 2017 21:32:00 +0000 (14:32 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Oct 2017 07:35:37 +0000 (09:35 +0200)
commit 511c54a2f69195b28afb9dd119f03787b1625bb4 upstream.

According to the MS-SMB2 spec (3.2.5.1.6) once the client receives
STATUS_NETWORK_SESSION_EXPIRED error code from a server it should
reconnect the current SMB session. Currently the client doesn't do
that. This can result in subsequent client requests failing by
the server. The patch adds an additional logic to the demultiplex
thread to identify expired sessions and reconnect them.

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/cifs/cifsglob.h
fs/cifs/cifssmb.c
fs/cifs/connect.c
fs/cifs/smb2ops.c

index 48ef401c3c61c04d37a0ad37ab98aea39bcab7a2..7b496a4e650e16eb643a1f387f201d3ef661aa04 100644 (file)
@@ -365,6 +365,8 @@ struct smb_version_operations {
        unsigned int (*calc_smb_size)(void *);
        /* check for STATUS_PENDING and process it in a positive case */
        bool (*is_status_pending)(char *, struct TCP_Server_Info *, int);
+       /* check for STATUS_NETWORK_SESSION_EXPIRED */
+       bool (*is_session_expired)(char *);
        /* send oplock break response */
        int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *,
                               struct cifsInodeInfo *);
index 1f91c9dadd5b94e37b5f361b57e44d2a8aaa85ff..cc420d6b71f78313a8651fa7b56937400da45f47 100644 (file)
@@ -1457,6 +1457,13 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
                return length;
        server->total_read += length;
 
+       if (server->ops->is_session_expired &&
+           server->ops->is_session_expired(buf)) {
+               cifs_reconnect(server);
+               wake_up(&server->response_q);
+               return -1;
+       }
+
        if (server->ops->is_status_pending &&
            server->ops->is_status_pending(buf, server, 0)) {
                discard_remaining_data(server);
index f6712b6128d8d20d59b64029a1223eaac2816162..580b3a4ca53ac48c1e2948aed4c588a3a39a9dd5 100644 (file)
@@ -796,6 +796,13 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
                cifs_dump_mem("Bad SMB: ", buf,
                        min_t(unsigned int, server->total_read, 48));
 
+       if (server->ops->is_session_expired &&
+           server->ops->is_session_expired(buf)) {
+               cifs_reconnect(server);
+               wake_up(&server->response_q);
+               return -1;
+       }
+
        if (server->ops->is_status_pending &&
            server->ops->is_status_pending(buf, server, length))
                return -1;
index b6968241c26f4f064c44a29ecb79aff04402fe27..812e4884c392565d9d9b2100e779be2ea0d729d4 100644 (file)
@@ -1018,6 +1018,18 @@ smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
        return true;
 }
 
+static bool
+smb2_is_session_expired(char *buf)
+{
+       struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
+
+       if (hdr->Status != STATUS_NETWORK_SESSION_EXPIRED)
+               return false;
+
+       cifs_dbg(FYI, "Session expired\n");
+       return true;
+}
+
 static int
 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
                     struct cifsInodeInfo *cinode)
@@ -1609,6 +1621,7 @@ struct smb_version_operations smb20_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -1690,6 +1703,7 @@ struct smb_version_operations smb21_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -1773,6 +1787,7 @@ struct smb_version_operations smb30_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,
@@ -1862,6 +1877,7 @@ struct smb_version_operations smb311_operations = {
        .close_dir = smb2_close_dir,
        .calc_smb_size = smb2_calc_size,
        .is_status_pending = smb2_is_status_pending,
+       .is_session_expired = smb2_is_session_expired,
        .oplock_response = smb2_oplock_response,
        .queryfs = smb2_queryfs,
        .mand_lock = smb2_mand_lock,