]> www.infradead.org Git - users/jedix/linux-maple.git/commit
cifs: fix race between call_async() and reconnect()
authorRabin Vincent <rabin.vincent@axis.com>
Wed, 23 Dec 2015 06:32:41 +0000 (07:32 +0100)
committerChuck Anderson <chuck.anderson@oracle.com>
Thu, 26 May 2016 22:44:15 +0000 (15:44 -0700)
commit5fc4796919f9ceac4a82663c9fb46bfdcb7bf9bb
treedb66fa1d6013afdcd8fbedbe39bfbba39674eee3
parent091c04c846a45405691000a6fcb81521c97ba0c7
cifs: fix race between call_async() and reconnect()

Orabug: 23330631

[ Upstream commit 820962dc700598ffe8cd21b967e30e7520c34748 ]

cifs_call_async() queues the MID to the pending list and calls
smb_send_rqst().  If smb_send_rqst() performs a partial send, it sets
the tcpStatus to CifsNeedReconnect and returns an error code to
cifs_call_async().  In this case, cifs_call_async() removes the MID
from the list and returns to the caller.

However, cifs_call_async() releases the server mutex _before_ removing
the MID.  This means that a cifs_reconnect() can race with this function
and manage to remove the MID from the list and delete the entry before
cifs_call_async() calls cifs_delete_mid().  This leads to various
crashes due to the use after free in cifs_delete_mid().

Task1 Task2

cifs_call_async():
 - rc = -EAGAIN
 - mutex_unlock(srv_mutex)

cifs_reconnect():
 - mutex_lock(srv_mutex)
 - mutex_unlock(srv_mutex)
 - list_delete(mid)
 - mid->callback()
  cifs_writev_callback():
  - mutex_lock(srv_mutex)
- delete(mid)
  - mutex_unlock(srv_mutex)

 - cifs_delete_mid(mid) <---- use after free

Fix this by removing the MID in cifs_call_async() before releasing the
srv_mutex.  Also hold the srv_mutex in cifs_reconnect() until the MIDs
are moved out of the pending list.

Signed-off-by: Rabin Vincent <rabin.vincent@axis.com>
Acked-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com>
CC: Stable <stable@vger.kernel.org>
Signed-off-by: Steve French <sfrench@localhost.localdomain>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
(cherry picked from commit 99b79b15df4ed1a6293cff487b46efc86bd20ae5)

Signed-off-by: Dan Duval <dan.duval@oracle.com>
fs/cifs/connect.c
fs/cifs/transport.c