Skip to content

Commit 75ac9a3

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix race condition from parallel smb2 lock requests
There is a race condition issue between parallel smb2 lock request. Time + Thread A | Thread A smb2_lock | smb2_lock | insert smb_lock to lock_list | spin_unlock(&work->conn->llist_lock) | | | spin_lock(&conn->llist_lock); | kfree(cmp_lock); | // UAF! | list_add(&smb_lock->llist, &rollback_list) + This patch swaps the line for adding the smb lock to the rollback list and adding the lock list of connection to fix the race issue. Reported-by: luosili <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 7ca9da7 commit 75ac9a3

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7038,10 +7038,6 @@ int smb2_lock(struct ksmbd_work *work)
70387038

70397039
ksmbd_debug(SMB,
70407040
"would have to wait for getting lock\n");
7041-
spin_lock(&work->conn->llist_lock);
7042-
list_add_tail(&smb_lock->clist,
7043-
&work->conn->lock_list);
7044-
spin_unlock(&work->conn->llist_lock);
70457041
list_add(&smb_lock->llist, &rollback_list);
70467042

70477043
argv = kmalloc(sizeof(void *), GFP_KERNEL);
@@ -7072,9 +7068,6 @@ int smb2_lock(struct ksmbd_work *work)
70727068

70737069
if (work->state != KSMBD_WORK_ACTIVE) {
70747070
list_del(&smb_lock->llist);
7075-
spin_lock(&work->conn->llist_lock);
7076-
list_del(&smb_lock->clist);
7077-
spin_unlock(&work->conn->llist_lock);
70787071
locks_free_lock(flock);
70797072

70807073
if (work->state == KSMBD_WORK_CANCELLED) {
@@ -7094,19 +7087,16 @@ int smb2_lock(struct ksmbd_work *work)
70947087
}
70957088

70967089
list_del(&smb_lock->llist);
7097-
spin_lock(&work->conn->llist_lock);
7098-
list_del(&smb_lock->clist);
7099-
spin_unlock(&work->conn->llist_lock);
71007090
release_async_work(work);
71017091
goto retry;
71027092
} else if (!rc) {
7093+
list_add(&smb_lock->llist, &rollback_list);
71037094
spin_lock(&work->conn->llist_lock);
71047095
list_add_tail(&smb_lock->clist,
71057096
&work->conn->lock_list);
71067097
list_add_tail(&smb_lock->flist,
71077098
&fp->lock_list);
71087099
spin_unlock(&work->conn->llist_lock);
7109-
list_add(&smb_lock->llist, &rollback_list);
71107100
ksmbd_debug(SMB, "successful in taking lock\n");
71117101
} else {
71127102
goto out;

0 commit comments

Comments
 (0)