Skip to content

Commit 7ca9da7

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix race condition from parallel smb2 logoff requests
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 <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c698134 commit 7ca9da7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,17 +2164,17 @@ int smb2_session_logoff(struct ksmbd_work *work)
21642164

21652165
ksmbd_debug(SMB, "request\n");
21662166

2167-
sess_id = le64_to_cpu(req->hdr.SessionId);
2168-
2169-
rsp->StructureSize = cpu_to_le16(4);
2170-
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
2171-
if (err) {
2172-
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
2167+
ksmbd_conn_lock(conn);
2168+
if (!ksmbd_conn_good(conn)) {
2169+
ksmbd_conn_unlock(conn);
2170+
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
21732171
smb2_set_err_rsp(work);
2174-
return err;
2172+
return -ENOENT;
21752173
}
2176-
2174+
sess_id = le64_to_cpu(req->hdr.SessionId);
21772175
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_RECONNECT);
2176+
ksmbd_conn_unlock(conn);
2177+
21782178
ksmbd_close_session_fds(work);
21792179
ksmbd_conn_wait_idle(conn, sess_id);
21802180

@@ -2196,6 +2196,14 @@ int smb2_session_logoff(struct ksmbd_work *work)
21962196
ksmbd_free_user(sess->user);
21972197
sess->user = NULL;
21982198
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_NEGOTIATE);
2199+
2200+
rsp->StructureSize = cpu_to_le16(4);
2201+
err = ksmbd_iov_pin_rsp(work, rsp, sizeof(struct smb2_logoff_rsp));
2202+
if (err) {
2203+
rsp->hdr.Status = STATUS_INSUFFICIENT_RESOURCES;
2204+
smb2_set_err_rsp(work);
2205+
return err;
2206+
}
21992207
return 0;
22002208
}
22012209

0 commit comments

Comments
 (0)