Skip to content

Commit 99b79b1

Browse files
vwaxsashalevin
authored andcommitted
cifs: fix race between call_async() and reconnect()
[ Upstream commit 820962d ] 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 <[email protected]> Acked-by: Shirish Pargaonkar <[email protected]> CC: Stable <[email protected]> Signed-off-by: Steve French <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ca7342a commit 99b79b1

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

fs/cifs/connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ cifs_reconnect(struct TCP_Server_Info *server)
357357
server->session_key.response = NULL;
358358
server->session_key.len = 0;
359359
server->lstrp = jiffies;
360-
mutex_unlock(&server->srv_mutex);
361360

362361
/* mark submitted MIDs for retry and issue callback */
363362
INIT_LIST_HEAD(&retry_list);
@@ -370,6 +369,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
370369
list_move(&mid_entry->qhead, &retry_list);
371370
}
372371
spin_unlock(&GlobalMid_Lock);
372+
mutex_unlock(&server->srv_mutex);
373373

374374
cifs_dbg(FYI, "%s: issuing mid callbacks\n", __func__);
375375
list_for_each_safe(tmp, tmp2, &retry_list) {

fs/cifs/transport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,16 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
576576
cifs_in_send_dec(server);
577577
cifs_save_when_sent(mid);
578578

579-
if (rc < 0)
579+
if (rc < 0) {
580580
server->sequence_number -= 2;
581+
cifs_delete_mid(mid);
582+
}
583+
581584
mutex_unlock(&server->srv_mutex);
582585

583586
if (rc == 0)
584587
return 0;
585588

586-
cifs_delete_mid(mid);
587589
add_credits_and_wake_if(server, credits, optype);
588590
return rc;
589591
}

0 commit comments

Comments
 (0)