diff options
author | Rabin Vincent <rabin.vincent@axis.com> | 2015-12-23 01:32:41 -0500 |
---|---|---|
committer | Steve French <sfrench@localhost.localdomain> | 2016-01-14 15:35:58 -0500 |
commit | 820962dc700598ffe8cd21b967e30e7520c34748 (patch) | |
tree | 21cfcb56a523a372e1518d7fce1ed9e7cccb0df5 /fs | |
parent | 373512ec5c105ed09e3738196dcb257dfab65cba (diff) |
cifs: fix race between call_async() and reconnect()
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/cifs/connect.c | 2 | ||||
-rw-r--r-- | fs/cifs/transport.c | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 6ab9e83b899e..4fbd92d2e113 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -370,7 +370,6 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
370 | server->session_key.response = NULL; | 370 | server->session_key.response = NULL; |
371 | server->session_key.len = 0; | 371 | server->session_key.len = 0; |
372 | server->lstrp = jiffies; | 372 | server->lstrp = jiffies; |
373 | mutex_unlock(&server->srv_mutex); | ||
374 | 373 | ||
375 | /* mark submitted MIDs for retry and issue callback */ | 374 | /* mark submitted MIDs for retry and issue callback */ |
376 | INIT_LIST_HEAD(&retry_list); | 375 | INIT_LIST_HEAD(&retry_list); |
@@ -383,6 +382,7 @@ cifs_reconnect(struct TCP_Server_Info *server) | |||
383 | list_move(&mid_entry->qhead, &retry_list); | 382 | list_move(&mid_entry->qhead, &retry_list); |
384 | } | 383 | } |
385 | spin_unlock(&GlobalMid_Lock); | 384 | spin_unlock(&GlobalMid_Lock); |
385 | mutex_unlock(&server->srv_mutex); | ||
386 | 386 | ||
387 | cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__); | 387 | cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__); |
388 | list_for_each_safe(tmp, tmp2, &retry_list) { | 388 | list_for_each_safe(tmp, tmp2, &retry_list) { |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 2a24c524fb9a..87abe8ed074c 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -576,14 +576,16 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, | |||
576 | cifs_in_send_dec(server); | 576 | cifs_in_send_dec(server); |
577 | cifs_save_when_sent(mid); | 577 | cifs_save_when_sent(mid); |
578 | 578 | ||
579 | if (rc < 0) | 579 | if (rc < 0) { |
580 | server->sequence_number -= 2; | 580 | server->sequence_number -= 2; |
581 | cifs_delete_mid(mid); | ||
582 | } | ||
583 | |||
581 | mutex_unlock(&server->srv_mutex); | 584 | mutex_unlock(&server->srv_mutex); |
582 | 585 | ||
583 | if (rc == 0) | 586 | if (rc == 0) |
584 | return 0; | 587 | return 0; |
585 | 588 | ||
586 | cifs_delete_mid(mid); | ||
587 | add_credits_and_wake_if(server, credits, optype); | 589 | add_credits_and_wake_if(server, credits, optype); |
588 | return rc; | 590 | return rc; |
589 | } | 591 | } |