ksmbd: fix race condition from parallel smb2 logoff requests
[ Upstream commit 7ca9da7d873ee8024e9548d3366101c2b6843eab ] If parallel smb2 logoff requests come in before closing door, running request count becomes more than 1 even though connection status is set to KSMBD_SESS_NEED_RECONNECT. It can't get condition true, and sleep forever. This patch fix race condition problem by returning error if connection status was already set to KSMBD_SESS_NEED_RECONNECT. Reported-by: luosili <rootlab@huawei.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
b3a843caed
commit
6584ca894f
@ -2164,17 +2164,17 @@ int smb2_session_logoff(struct ksmbd_work *work)
|
||||
|
||||
ksmbd_debug(SMB, "request\n");
|
||||
|
||||
sess_id = le64_to_cpu(req->hdr.SessionId);
|
||||
|
||||
rsp->StructureSize = cpu_to_le16(4);
|
||||
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
|
||||
if (err) {
|
||||
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
ksmbd_conn_lock(conn);
|
||||
if (!ksmbd_conn_good(conn)) {
|
||||
ksmbd_conn_unlock(conn);
|
||||
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
|
||||
smb2_set_err_rsp(work);
|
||||
return err;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
sess_id = le64_to_cpu(req->hdr.SessionId);
|
||||
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_RECONNECT);
|
||||
ksmbd_conn_unlock(conn);
|
||||
|
||||
ksmbd_close_session_fds(work);
|
||||
ksmbd_conn_wait_idle(conn, sess_id);
|
||||
|
||||
@ -2196,6 +2196,14 @@ int smb2_session_logoff(struct ksmbd_work *work)
|
||||
ksmbd_free_user(sess->user);
|
||||
sess->user = NULL;
|
||||
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_NEGOTIATE);
|
||||
|
||||
rsp->StructureSize = cpu_to_le16(4);
|
||||
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
|
||||
if (err) {
|
||||
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
smb2_set_err_rsp(work);
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user