Linux Kernel: cifs: release auth_key.response for reconnect

This change "cifs: release auth_key.response for reconnect." (commit f5c4ba8) in Linux kernel is authored by Shu Wang <shuwang [at] redhat.com> on Fri Sep 8 18:48:33 2017 +0800.

Description of "cifs: release auth_key.response for reconnect."

The change "cifs: release auth_key.response for reconnect." introduces changes as follows.

cifs: release auth_key.response for reconnect.

There is a race that cause cifs reconnect in cifs_mount,
- cifs_mount
  - cifs_get_tcp_session
    - [ start thread cifs_demultiplex_thread
      - cifs_read_from_socket: -ECONNABORTED
        - DELAY_WORK smb2_reconnect_server ]
  - cifs_setup_session
  - [ smb2_reconnect_server ]

auth_key.response was allocated in cifs_setup_session, and
will release when the session destoried. So when session re-
connect, auth_key.response should be check and released.

Tested with my system:
CIFS VFS: Free previous auth_key.response = ffff8800320bbf80

A simple auth_key.response allocation call trace:
- cifs_setup_session
- SMB2_sess_setup
- SMB2_sess_auth_rawntlmssp_authenticate
- build_ntlmssp_auth_blob
- setup_ntlmv2_rsp

Signed-off-by: Shu Wang <shuwang@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
CC: Stable <stable@vger.kernel.org>
Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>

Linux kernel code changes from "cifs: release auth_key.response for reconnect."

There are 8 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/cifs/connect.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 8d38b22afb2b..0bfc2280436d 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -4154,6 +4154,14 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
    cifs_dbg(FYI, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %dn",
         server->sec_mode, server->capabilities, server->timeAdj);

+   if (ses->auth_key.response) {
+       cifs_dbg(VFS, "Free previous auth_key.response = %pn",
+            ses->auth_key.response);
+       kfree(ses->auth_key.response);
+       ses->auth_key.response = NULL;
+       ses->auth_key.len = 0;
+   }
+
    if (server->ops->sess_setup)
        rc = server->ops->sess_setup(xid, ses, nls_info);

The commit for this change in Linux stable tree is f5c4ba8 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *