CIFS: Fix a possible double locking of mutex during reconnect
authorPavel Shilovsky <pshilov@microsoft.com>
Tue, 29 Nov 2016 19:31:23 +0000 (11:31 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Jan 2017 09:40:16 +0000 (10:40 +0100)
commit46890ffba1d62550c45f4412378daca9586ba51b
tree84e3b2292524717456f1a3f9887c4e8779a06a15
parent69d13b69e79cb76413b49a66e43a2be39f14aefe
CIFS: Fix a possible double locking of mutex during reconnect

commit 96a988ffeb90dba33a71c3826086fe67c897a183 upstream.

With the current code it is possible to lock a mutex twice when
a subsequent reconnects are triggered. On the 1st reconnect we
reconnect sessions and tcons and then persistent file handles.
If the 2nd reconnect happens during the reconnecting of persistent
file handles then the following sequence of calls is observed:

cifs_reopen_file -> SMB2_open -> small_smb2_init -> smb2_reconnect
-> cifs_reopen_persistent_file_handles -> cifs_reopen_file (again!).

So, we are trying to acquire the same cfile->fh_mutex twice which
is wrong. Fix this by moving reconnecting of persistent handles to
the delayed work (smb2_reconnect_server) and submitting this work
every time we reconnect tcon in SMB2 commands handling codepath.

This can also lead to corruption of a temporary file list in
cifs_reopen_persistent_file_handles() because we can recursively
call this function twice.

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/cifs/cifsglob.h
fs/cifs/file.c
fs/cifs/smb2pdu.c
fs/cifs/smb2pdu.h