Skip to content

Commit

Permalink
ksmbd: update tree disconnect race update 2
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Oct 3, 2023
1 parent 11d3bf6 commit 97a934a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
18 changes: 11 additions & 7 deletions mgmt/tree_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
int ret;

write_lock(&sess->tree_conns_lock);
if (tree_conn->t_state == TREE_DISCONNECTED) {
write_unlock(&sess->tree_conns_lock);
return -ENOENT;
}

tree_conn->t_state = TREE_DISCONNECTED;
xa_erase(&sess->tree_conns, tree_conn->id);
write_unlock(&sess->tree_conns_lock);

Expand Down Expand Up @@ -156,8 +150,18 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)
if (!sess)
return -EINVAL;

xa_for_each(&sess->tree_conns, id, tc)
xa_for_each(&sess->tree_conns, id, tc) {
write_lock(&sess->tree_conns_lock);
if (tc->t_state == TREE_DISCONNECTED) {
write_unlock(&sess->tree_conns_lock);
ret = -ENOENT;
continue;
}
tc->t_state = TREE_DISCONNECTED;
write_unlock(&sess->tree_conns_lock);

ret |= ksmbd_tree_conn_disconnect(sess, tc);
}
xa_destroy(&sess->tree_conns);
return ret;
}
15 changes: 13 additions & 2 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2146,13 +2146,24 @@ int smb2_tree_disconnect(struct ksmbd_work *work)
ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);

rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
smb2_set_err_rsp(work);
err = -ENOENT;
goto err_out;
}

ksmbd_close_tree_conn_fds(work);
atomic_dec(&tcon->refcount);

write_lock(&sess->tree_conns_lock);
if (tcon->t_state == TREE_DISCONNECTED) {
write_unlock(&sess->tree_conns_lock);
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
err = -ENOENT;
goto err_out;
}

BUG_ON(atomic_dec_and_test(&tcon->refcount));
tcon->t_state = TREE_DISCONNECTED;
write_unlock(&sess->tree_conns_lock);

err = ksmbd_tree_conn_disconnect(sess, tcon);
if (err) {
rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
Expand Down

0 comments on commit 97a934a

Please sign in to comment.