From: Ian Bridges <icb@fastmail.org>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Tom Talpey <tom@talpey.com>,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>,
linux-cifs@vger.kernel.org, Ian Bridges <icb@fastmail.org>,
stable@vger.kernel.org
Subject: [PATCH v3 1/2] ksmbd: use wrap-safe durable handle deadlines
Date: Fri, 4 Dec 2026 00:04:41 -0600 [thread overview]
Message-ID: <20261204060442.30849-2-icb@fastmail.org> (raw)
In-Reply-To: <20261204060442.30849-1-icb@fastmail.org>
Durable handle deadlines are stored as 32-bit millisecond counts
and compared with ordinary integer comparisons. If a timeout crosses
the counter wrap, the handle appears expired immediately. Reconnect
then fails with STATUS_OBJECT_NAME_NOT_FOUND, and the scavenger can
close the handle before its timeout expires.
With HZ of 100, 250 or 1000, the millisecond count first wraps five
minutes after boot because of the initial jiffies value, and then
every 49.7 days.
Keep the deadline in 64-bit jiffies and compare it with the 64-bit time
helpers. A 64-bit value does not wrap. A 32-bit jiffies deadline would
wrap again on a 32-bit system, and a handle that the scavenger skipped
can stay in the table that long. Zero is a valid jiffies deadline, so
timed handles are told apart by durable_timeout.
A reconnect could also read the handle while a disconnect changed it,
and see the connection already cleared but the deadline of an earlier
disconnect. Check the connection and the deadline under global_ft.lock
in the reconnect lookup, and change them under it in
ksmbd_invalidate_durable_fd(), as session_fd_check() already does. This
also keeps a 32-bit system from reading half of the deadline.
Fixes: 520da3c488c5 ("ksmbd: avoid reclaiming expired durable opens by the client")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
fs/smb/server/vfs_cache.c | 48 +++++++++++++++++++++++++++++----------
fs/smb/server/vfs_cache.h | 2 +-
2 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c
index 1f6991b5bc2e..6bb35d95d495 100644
--- a/fs/smb/server/vfs_cache.c
+++ b/fs/smb/server/vfs_cache.c
@@ -1229,17 +1229,31 @@ struct ksmbd_file *ksmbd_lookup_global_fd(unsigned long long id)
struct ksmbd_file *ksmbd_lookup_durable_fd(unsigned long long id)
{
- struct ksmbd_file *fp;
+ struct ksmbd_file *fp, *stale = NULL;
- fp = __ksmbd_lookup_fd(&global_ft, id);
+ if (!has_file_id(id))
+ return NULL;
+
+ /*
+ * session_fd_check() clears fp->conn and sets the deadline under
+ * global_ft.lock, so check both under the same lock.
+ */
+ read_lock(&global_ft.lock);
+ fp = idr_find(global_ft.idr, id);
+ if (fp)
+ fp = ksmbd_fp_get(fp);
if (fp && (fp->durable_reconnect_disabled ||
fp->conn ||
- (fp->durable_scavenger_timeout &&
- (fp->durable_scavenger_timeout <
- jiffies_to_msecs(jiffies))))) {
- ksmbd_put_durable_fd(fp);
+ (fp->durable_timeout &&
+ time_after64(get_jiffies_64(),
+ fp->durable_scavenger_timeout)))) {
+ stale = fp;
fp = NULL;
}
+ read_unlock(&global_ft.lock);
+
+ if (stale)
+ ksmbd_put_durable_fd(stale);
return fp;
}
@@ -1400,15 +1414,23 @@ int ksmbd_invalidate_durable_fd(unsigned long long id)
if (!fp)
return -ENOENT;
+ /*
+ * The reconnect lookup and the scavenger read these fields under
+ * global_ft.lock. A 64-bit deadline is not written in one store on
+ * 32-bit systems.
+ */
+ write_lock(&global_ft.lock);
fp->durable_reconnect_disabled = true;
if (fp->conn) {
+ write_unlock(&global_ft.lock);
ksmbd_put_durable_fd(fp);
return -ENOENT;
}
fp->durable_timeout = 1;
- fp->durable_scavenger_timeout = jiffies_to_msecs(jiffies);
+ fp->durable_scavenger_timeout = get_jiffies_64();
+ write_unlock(&global_ft.lock);
ksmbd_put_durable_fd(fp);
if (waitqueue_active(&dh_wq))
wake_up(&dh_wq);
@@ -1907,6 +1929,7 @@ static int ksmbd_durable_scavenger(void *dummy)
write_lock(&global_ft.lock);
idr_for_each_entry(global_ft.idr, fp, id) {
unsigned long durable_timeout;
+ u64 now;
if (!fp->durable_timeout)
continue;
@@ -1916,8 +1939,9 @@ static int ksmbd_durable_scavenger(void *dummy)
continue;
found_fp_timeout = true;
- if (fp->durable_scavenger_timeout <=
- jiffies_to_msecs(jiffies)) {
+ now = get_jiffies_64();
+ if (time_after_eq64(now,
+ fp->durable_scavenger_timeout)) {
__ksmbd_remove_durable_fd(fp);
/*
* Take a transient reference so fp
@@ -1934,8 +1958,8 @@ static int ksmbd_durable_scavenger(void *dummy)
}
durable_timeout =
- fp->durable_scavenger_timeout -
- jiffies_to_msecs(jiffies);
+ jiffies64_to_msecs(fp->durable_scavenger_timeout -
+ now);
if (min_timeout > durable_timeout)
min_timeout = durable_timeout;
@@ -2113,7 +2137,7 @@ static bool session_fd_check(struct ksmbd_tree_connect *tcon,
if (fp->durable_timeout)
fp->durable_scavenger_timeout =
- jiffies_to_msecs(jiffies) + fp->durable_timeout;
+ get_jiffies_64() + msecs_to_jiffies(fp->durable_timeout);
atomic_dec(&conn->stats.open_files_count);
write_unlock(&global_ft.lock);
up_write(&ci->m_lock);
diff --git a/fs/smb/server/vfs_cache.h b/fs/smb/server/vfs_cache.h
index bc1955b87855..7498167c6734 100644
--- a/fs/smb/server/vfs_cache.h
+++ b/fs/smb/server/vfs_cache.h
@@ -152,7 +152,7 @@ struct ksmbd_file {
bool stream_del_pending;
unsigned int durable_timeout;
- unsigned int durable_scavenger_timeout;
+ u64 durable_scavenger_timeout;
/* CREATE action returned when this durable handle was established. */
__le32 create_action;
base-commit: 43dc36660aff09d415b2949d3498c94763798b21
--
2.47.3
next parent reply other threads:[~2026-12-04 6:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261204060442.30849-1-icb@fastmail.org>
2026-12-04 6:04 ` Ian Bridges [this message]
2026-12-04 6:04 ` [PATCH v3 2/2] ksmbd: keep the durable scavenger until disconnected handles are removed Ian Bridges
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204060442.30849-2-icb@fastmail.org \
--to=icb@fastmail.org \
--cc=chenxiaosong@chenxiaosong.com \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=stable@vger.kernel.org \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox