From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 693C52D0C92 for ; Thu, 16 Jul 2026 11:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784202755; cv=none; b=lBKbGfxo+QhFW51RyQXFmihv2OyS5xTrLWm4dJWfr9p5pIWgY8snIVHm+EAqtFO4eEc2kJ5ymXot2ca49qOXLQ0xj2Saf2RnRvZqs+blGZqMG+oXdh7b5fm312zIBHz5aLE8OaSnFLL/QtYSlK/uNMUifk+/Mxm5Efl4e73OVRw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784202755; c=relaxed/simple; bh=8HE3lsf5skg0O2TKiQ/Y2vk1EZwA7w/bgbZdjYtqS98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=obb8CtvrfZAeK65Uqok4GG1/Hg6LDH/UuMpjQ/zuZ9yjxue/xxGU9O6neESo8WhS0soBEbjpr71KToH4z/ehyINUky+G0qCT5gPXTOcWbyLdXC+e09mpwHZYlF6v44wQPU9dMV4Ld9QA4HdBcYUKRW1V2hAUB7Xhr40sRgPkC8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fJ8ECrxJ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fJ8ECrxJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD90A1F00A3D; Thu, 16 Jul 2026 11:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784202754; bh=XxU4byAqPUy8muXSusHOd3RepXmzYmBnD1hrrHDYx0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fJ8ECrxJinwRNFg9EMtZ94LDq5SAnanq4EddtpcnpE5VeZGGBKCORWYqZZ1aSa7mE osGciCoqLDl58WPBLO0zubKo6UziaNqddp9rJECN55diihxONz4zRWZwKUtuovBetw UYfwKM0CXsGglFHMKkWspCwC21eya9rMWgQUBSmlTQSmbxHp09xs2dxW3SUVDYzlIW ViiAnBJoXu8QSMf0Oejy2mvjTDfifyzVIw8BwLjZr8TO8MHC2FkG1dzdSpQwl/+dT9 Mq62qsf6SpSFliXc89VTjLJ5BpvLwrFykU4nnEFdqb926WJ2ZJCjUqU1rMmjFlkcIS +F7AE7cYEbaoA== From: Sasha Levin To: stable@vger.kernel.org Cc: Namjae Jeon , Musaab Khan , Steve French , Sasha Levin Subject: [PATCH 6.12.y 2/2] ksmbd: track the connection owning a byte-range lock Date: Thu, 16 Jul 2026 07:52:31 -0400 Message-ID: <20260716115231.1785404-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260716115231.1785404-1-sashal@kernel.org> References: <2026071413-detection-unexposed-321e@gregkh> <20260716115231.1785404-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Namjae Jeon [ Upstream commit c1016dd1d8b2bcd1158bbaabe94a31bb7e7431fb ] SMB2_LOCK adds each granted byte-range lock to both the file lock list and the lock list of the connection which handled the request. The final close and durable handle paths, however, remove the connection list entry while holding fp->conn->llist_lock. With SMB3 multichannel, the connection handling the LOCK request can be different from the connection which opened the file. The entry can therefore be removed under a different spinlock from the one protecting the list it belongs to. A concurrent traversal can then access freed struct ksmbd_lock and struct file_lock objects. Record the connection owning each lock's clist entry and hold a reference to it while the entry is linked. Use that connection and its llist_lock for unlock, rollback, close, and durable preserve. Durable reconnect assigns the new connection as the owner when publishing the locks again. Fixes: f5a544e3bab7 ("ksmbd: add support for SMB3 multichannel") Cc: stable@vger.kernel.org Reported-by: Musaab Khan Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/server/smb2pdu.c | 10 ++++++++-- fs/smb/server/vfs_cache.c | 23 +++++++++++++++++------ fs/smb/server/vfs_cache.h | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 162bcd46100e74..e4d32671b5bcbf 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -7571,9 +7571,11 @@ int smb2_lock(struct ksmbd_work *work) nolock = 0; list_del(&cmp_lock->flist); list_del(&cmp_lock->clist); + cmp_lock->conn = NULL; spin_unlock(&conn->llist_lock); up_read(&conn_list_lock); + ksmbd_conn_put(conn); locks_free_lock(cmp_lock->fl); kfree(cmp_lock); goto out_check_cl; @@ -7710,6 +7712,7 @@ int smb2_lock(struct ksmbd_work *work) goto retry; } else if (!rc) { list_add(&smb_lock->llist, &rollback_list); + smb_lock->conn = ksmbd_conn_get(work->conn); spin_lock(&work->conn->llist_lock); list_add_tail(&smb_lock->clist, &work->conn->lock_list); @@ -7764,11 +7767,14 @@ int smb2_lock(struct ksmbd_work *work) } list_del(&smb_lock->llist); - spin_lock(&work->conn->llist_lock); + conn = smb_lock->conn; + spin_lock(&conn->llist_lock); if (!list_empty(&smb_lock->flist)) list_del(&smb_lock->flist); list_del(&smb_lock->clist); - spin_unlock(&work->conn->llist_lock); + smb_lock->conn = NULL; + spin_unlock(&conn->llist_lock); + ksmbd_conn_put(conn); locks_free_lock(smb_lock->fl); if (rlock) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index ef81b033d33e2c..8d275787fd98d0 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -387,10 +387,14 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp) * there are not accesses to fp->lock_list. */ list_for_each_entry_safe(smb_lock, tmp_lock, &fp->lock_list, flist) { - if (!list_empty(&smb_lock->clist) && fp->conn) { - spin_lock(&fp->conn->llist_lock); - list_del(&smb_lock->clist); - spin_unlock(&fp->conn->llist_lock); + struct ksmbd_conn *conn = smb_lock->conn; + + if (conn) { + spin_lock(&conn->llist_lock); + list_del_init(&smb_lock->clist); + smb_lock->conn = NULL; + spin_unlock(&conn->llist_lock); + ksmbd_conn_put(conn); } list_del(&smb_lock->flist); @@ -1070,9 +1074,15 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon, up_write(&ci->m_lock); list_for_each_entry_safe(smb_lock, tmp_lock, &fp->lock_list, flist) { - spin_lock(&conn->llist_lock); + struct ksmbd_conn *lock_conn = smb_lock->conn; + + if (!lock_conn) + continue; + spin_lock(&lock_conn->llist_lock); list_del_init(&smb_lock->clist); - spin_unlock(&conn->llist_lock); + smb_lock->conn = NULL; + spin_unlock(&lock_conn->llist_lock); + ksmbd_conn_put(lock_conn); } fp->conn = NULL; @@ -1193,6 +1203,7 @@ int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp) } list_for_each_entry(smb_lock, &fp->lock_list, flist) { + smb_lock->conn = ksmbd_conn_get(conn); spin_lock(&conn->llist_lock); list_add_tail(&smb_lock->clist, &conn->lock_list); spin_unlock(&conn->llist_lock); diff --git a/fs/smb/server/vfs_cache.h b/fs/smb/server/vfs_cache.h index 1b2a947490ca5e..a11ba286983932 100644 --- a/fs/smb/server/vfs_cache.h +++ b/fs/smb/server/vfs_cache.h @@ -31,6 +31,7 @@ struct ksmbd_session; struct ksmbd_lock { struct file_lock *fl; + struct ksmbd_conn *conn; struct list_head clist; struct list_head flist; struct list_head llist; -- 2.53.0