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 560C73B6BE5; Tue, 21 Jul 2026 22:27:52 +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=1784672874; cv=none; b=rGt9AXjmmiFa+RRMfvKGL2AZwwW9wXYFVn3lSn5tMkppY/rLua0f/h2h8Ie+aco7eJJaSdEsm2VZ8VTSMgBQLJERdDx/U+iJV3y4W1G2USGcPt7zZ3U+Ta0Jf/9rkNbcwS2QD41qhkDOT6FC73QoBIrWeWSAPRRHBuDWwWBMmNY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784672874; c=relaxed/simple; bh=vweWJ3JqFYCi5kzgw3gLRsNo6H6EpmKY4oVRy3Icy4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C+YbpMrFzml6vJUsd2a3LA/KFQ1ZkGHn/P9VhBdpTVGFVQq9/EexQwtBzN2JAsjE17HOGalyRqzChF+YxGS/ROzJUXIb/jMMmsCdrRndJg1bu5+pF2QDGKbIsFwMo2MJgk8YlS6Y3J0NBAX5lWXPfp14dKiSbBpGqJhb73WWSh4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1mu8o08Z; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1mu8o08Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49A1B1F000E9; Tue, 21 Jul 2026 22:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784672872; bh=gpIqbq37SfdQP2M/WKxKfW7uaz6T7LNoGkmwVvZHehk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1mu8o08ZQGIkSEIFy3O/entUFsNexIkSpH1X9dd3Kh1hQGx+Vvu3jmUAfJO/i2XKo //2zIZcM8ByN3FTMDKO2sc3NpM7cYEg8G8egiwzx+IunfNXiJqngEsghV9+A9y426N YzLSJGKOLMsjsEE0al4dhc+5IinATRzQahoR/fk0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Musaab Khan , Namjae Jeon , Steve French , Sasha Levin Subject: [PATCH 5.15 789/843] ksmbd: track the connection owning a byte-range lock Date: Tue, 21 Jul 2026 17:27:04 +0200 Message-ID: <20260721152423.810650329@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- fs/ksmbd/smb2pdu.c | 10 ++++++++-- fs/ksmbd/vfs_cache.c | 12 ++++++++---- fs/ksmbd/vfs_cache.h | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -7074,9 +7074,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; @@ -7212,6 +7214,7 @@ skip: 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); @@ -7259,11 +7262,14 @@ out: pr_err("rollback unlock fail : %d\n", rc); 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); locks_free_lock(rlock); --- a/fs/ksmbd/vfs_cache.c +++ b/fs/ksmbd/vfs_cache.c @@ -317,10 +317,14 @@ static void __ksmbd_close_fd(struct ksmb * 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); --- a/fs/ksmbd/vfs_cache.h +++ b/fs/ksmbd/vfs_cache.h @@ -30,6 +30,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;