Skip to content

Commit

Permalink
ksmbd: fix racy issue under cocurrent smb2 tree disconnect
Browse files Browse the repository at this point in the history
commit 3021094 upstream.

There is UAF issue under cocurrent smb2 tree disconnect.
This patch introduce TREE_CONN_EXPIRE flags for tcon to avoid cocurrent
access.

Cc: stable@vger.kernel.org
Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-20592
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
namjaejeon authored and gregkh committed May 11, 2023
1 parent 2ec1fe2 commit 39366b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion fs/ksmbd/mgmt/tree_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess,
unsigned int id)
{
return xa_load(&sess->tree_conns, id);
struct ksmbd_tree_connect *tcon;

tcon = xa_load(&sess->tree_conns, id);
if (tcon) {
if (test_bit(TREE_CONN_EXPIRE, &tcon->status))
tcon = NULL;
}

return tcon;
}

struct ksmbd_share_config *ksmbd_tree_conn_share(struct ksmbd_session *sess,
Expand Down
3 changes: 3 additions & 0 deletions fs/ksmbd/mgmt/tree_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct ksmbd_share_config;
struct ksmbd_user;
struct ksmbd_conn;

#define TREE_CONN_EXPIRE 1

struct ksmbd_tree_connect {
int id;

Expand All @@ -25,6 +27,7 @@ struct ksmbd_tree_connect {

int maximal_access;
bool posix_extensions;
unsigned long status;
};

struct ksmbd_tree_conn_status {
Expand Down
3 changes: 2 additions & 1 deletion fs/ksmbd/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2048,11 +2048,12 @@ int smb2_tree_disconnect(struct ksmbd_work *work)

ksmbd_debug(SMB, "request\n");

if (!tcon) {
if (!tcon || test_and_set_bit(TREE_CONN_EXPIRE, &tcon->status)) {
struct smb2_tree_disconnect_req *req =
smb2_get_msg(work->request_buf);

ksmbd_debug(SMB, "Invalid tid %d\n", req->hdr.Id.SyncId.TreeId);

rsp->hdr.Status = STATUS_NETWORK_NAME_DELETED;
smb2_set_err_rsp(work);
return 0;
Expand Down

0 comments on commit 39366b4

Please sign in to comment.