This is a note to let you know that I've just added the patch titled ksmbd: fix racy issue under cocurrent smb2 tree disconnect to the 6.3-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ksmbd-fix-racy-issue-under-cocurrent-smb2-tree-disconnect.patch and it can be found in the queue-6.3 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 30210947a343b6b3ca13adc9bfc88e1543e16dd5 Mon Sep 17 00:00:00 2001 From: Namjae Jeon <linkinjeon@xxxxxxxxxx> Date: Wed, 3 May 2023 08:51:12 +0900 Subject: ksmbd: fix racy issue under cocurrent smb2 tree disconnect From: Namjae Jeon <linkinjeon@xxxxxxxxxx> commit 30210947a343b6b3ca13adc9bfc88e1543e16dd5 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@xxxxxxxxxxxxxxx Reported-by: zdi-disclosures@xxxxxxxxxxxxxx # ZDI-CAN-20592 Signed-off-by: Namjae Jeon <linkinjeon@xxxxxxxxxx> Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/ksmbd/mgmt/tree_connect.c | 10 +++++++++- fs/ksmbd/mgmt/tree_connect.h | 3 +++ fs/ksmbd/smb2pdu.c | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) --- a/fs/ksmbd/mgmt/tree_connect.c +++ b/fs/ksmbd/mgmt/tree_connect.c @@ -109,7 +109,15 @@ int ksmbd_tree_conn_disconnect(struct ks 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, --- a/fs/ksmbd/mgmt/tree_connect.h +++ b/fs/ksmbd/mgmt/tree_connect.h @@ -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; @@ -25,6 +27,7 @@ struct ksmbd_tree_connect { int maximal_access; bool posix_extensions; + unsigned long status; }; struct ksmbd_tree_conn_status { --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -2048,11 +2048,12 @@ int smb2_tree_disconnect(struct ksmbd_wo 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; Patches currently in stable-queue which might be from linkinjeon@xxxxxxxxxx are queue-6.3/ksmbd-block-asynchronous-requests-when-making-a-delay-on-session-setup.patch queue-6.3/ksmbd-not-allow-guest-user-on-multichannel.patch queue-6.3/ksmbd-fix-racy-issue-from-smb2-close-and-logoff-with-multichannel.patch queue-6.3/ksmbd-fix-memleak-in-session-setup.patch queue-6.3/ksmbd-fix-null-pointer-dereference-in-smb2_get_info_filesystem.patch queue-6.3/ksmbd-fix-racy-issue-from-session-setup-and-logoff.patch queue-6.3/ksmbd-fix-racy-issue-under-cocurrent-smb2-tree-disconnect.patch queue-6.3/ksmbd-fix-deadlock-in-ksmbd_find_crypto_ctx.patch queue-6.3/ksmbd-destroy-expired-sessions.patch queue-6.3/ksmbd-call-rcu_barrier-in-ksmbd_server_exit.patch