7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Namjae Jeon commit add8d7fb04efe564193df73581889c62fc0016f1 upstream. ksmbd_session_unregister() removes a session from the global and per- connection tables before dropping the table reference. A concurrent reference holder can keep the session and its channel list alive after those removals. Connection cleanup can no longer find the unpublished session to remove its channels. Since a channel only stores a raw conn pointer, the connection can be freed while another session reference holder is still accessing it, for example during SMB3.1.1 binding or a procfs read. Take a connection reference when registering a channel and release it on insertion failure, channel removal, or final session destruction. Keep the channels and signing keys until the session is destroyed so a response can still be signed after the session has been unregistered. Fixes: d7fd1f98607f ("ksmbd: follow SMB2 session expiration semantics") Cc: stable@vger.kernel.org Reported-by: Abdifatah Suruur Signed-off-by: Namjae Jeon Signed-off-by: Greg Kroah-Hartman --- fs/smb/server/mgmt/user_session.c | 2 ++ fs/smb/server/smb2pdu.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) --- a/fs/smb/server/mgmt/user_session.c +++ b/fs/smb/server/mgmt/user_session.c @@ -273,6 +273,7 @@ static void free_channel_list(struct ksm down_write(&sess->chann_lock); xa_for_each(&sess->ksmbd_chann_list, index, chann) { xa_erase(&sess->ksmbd_chann_list, index); + ksmbd_conn_put(chann->conn); kfree_sensitive(chann); } @@ -601,6 +602,7 @@ static int ksmbd_chann_del(struct ksmbd_ if (!chann) return -ENOENT; + ksmbd_conn_put(chann->conn); kfree_sensitive(chann); return 0; } --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -116,11 +116,12 @@ static int register_session_channel(stru goto out; } - chann->conn = conn; + chann->conn = ksmbd_conn_get(conn); memcpy(chann->sess_key, sess_key, sizeof(chann->sess_key)); old = xa_store(&sess->ksmbd_chann_list, (long)conn, chann, KSMBD_DEFAULT_GFP); if (xa_is_err(old)) { + ksmbd_conn_put(chann->conn); kfree_sensitive(chann); rc = xa_err(old); }