From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.144 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796364299; b=KW4rrLb+StyvkFFaaH3B4wGelJXRiAflVIhnloSEi6XCOouWR5A5jC0Up1jNdYrSBdHq eBijf7btic2SICM4H1mYgbj66Ke6CVVY6fvfgBkxmLlZkzXTsDp3gu8qNNW6iJ0opm35g LkTLeo2v3ybudz1OZbN4ah4rSvNxnPZ7PQ3Q2t86rSHx6ISph85N/gPG4AHDon+DbUGrj s1UQ+insYXr3cGBEMFC4l1SyNRcdtRXIHly9tCbXFLfWi0wvtXjZ5qK9l/PiHLydHlazC zIwavGKMV0cX7i5N/YBLNg7BSS5jOmJKRf2Go7FxuV99NFqCZsP3Ah7fSivgmOffS9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364299; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=1u1Bs1+mFyWc8OrWXFE3jNWEghpucby8UhLNXV2G608=; b=hGYhN2F5e0lNKgaEzNL7a26povmWf/+JJutfCytzS6f5JNMJJY2yeHdPM5lxKJhy/NFx 64BZBwehTUI9EJvIy+Yb5jTkD8khlbLj224PJWnXWeoqVjcWhFzDHu9d+0jsP5OeA5w/d dsL0gdSUDdtpW7biJNKC1tbWkuf0PdIp5Kb9pb6S4L3dcazUApu7gLOmhZmH43Rprd8an Xg9qbvhIbJORAOvY+VCHSrdEfgvLBCGcEQu8fDAVHoD3nkcllt4VPejwkNQBsn4Jh4gxW /dWfWLALEQcHaqf5eSaLDnkIwvy/4Vlos9Un+Srp9vBhwxbBK8LodtZmXC52j8C8r4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.org; spf=pass smtp.mailfrom=fastmail.org; dkim=pass header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=LCvVsLEq; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=2Uk0ondi; arc=none smtp.remote-ip=103.168.172.144 Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3473C606A333 for ; Fri, 4 Dec 2026 06:04:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3473C606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=LCvVsLEq; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=2Uk0ondi Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 6473DEC0333 for ; Fri, 4 Dec 2026 01:04:58 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 04 Dec 2026 01:04:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796364298; x= 1796450698; bh=1u1Bs1+mFyWc8OrWXFE3jNWEghpucby8UhLNXV2G608=; b=L CvVsLEqflbh7/1wZRX8pyQlbRbTn3Pq5DaoGxyBUq4pmRBRWjykg1MPmxPR9CzJq 2aLhWyfWvfAwYLmNMJpODbTIIqtLO0/UzlcLTkuTYiYF+ueqPueujAwGXhO9eUE3 EaNwOaLZ8ysdxqU/gKXy34v3+hDxNvsemypywEE1iXfJH6pd59jsLqNRjcNZ1dFS UN/BFIN8EW4H0TIfqLgiVuLQwuE/qdNvRZFEDqEiUvyu8nD8ii/3/oWdOOCXGdYV hC1wFRuNpxTE+j5q0kI4+5MX+r3W91d538hyk3TVtYpG/H4fwu2PRxvfO+PjxTe5 hrhnxmmwJ4iQLYQZ7ducw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796364298; x=1796450698; bh=1 u1Bs1+mFyWc8OrWXFE3jNWEghpucby8UhLNXV2G608=; b=2Uk0ondiGQbx2Umb4 jhW/kC5nmo3hVDxTtKdmJEM/a30dJJYLX7UHuPukTm+uEKv0ZeoZOUpRffHm4WUV V1IKIzznkPCXVPnJ1HhJorgSDgDwF0+yCRkutq7rZDix69fQDP0a/8Q2JXW5+VAu 6fJotB4kMpxrbrrTrRTWqdb/e1vpFlCFK5adLm/tKQZPltrmE0codzV2mLc37JEy 4HYKTimqQ3RMp4yTN6UbCIl84XsArKYZzN+kmKccg8HC/5lqtW/H//NoJtsF1VSF VwlEGes62acLtKHY8P5BGhW0icO5zdTTJFzAzpxARI8twyv8HHGZiaAohDJAmDIE 7Arcg== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796364298; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PHN0YWJsZUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:F3NAPhLH7n3i/xjD8SLEanjgdskb7MugW0aMva2N8r/PYH0 FIDD64ohGAkLXtbB5Jh3dEuhenZ/kEySawBniI0k+O0rShx/pJ11C0hQNY/sX4in iRIK7c/OIuTuzB9nWojGO7t8GFwOSnMc6tZgNx0bANwqZStkmLnjCcdji8qnnUww BkJ3E3vZ6Y2ZO+OBzk2b/6rfov5aLp1KHofnukV1X6unyprsGTDI5BXOF9QogT66 4u+MPsAU9oiGTxbCysC7AboaSUusAxSHlE38u89+NGnW1VVrY08GxnVlBwjBOh6k P++6+6eGrNZDxtXVU/wzpD7Hc/2F9aL0EoLdQNw==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:qgLeGYkjoUsqFGvTnZ8wi4Inp5BXUUarHcmc13kLTkM=:CowHh/BNesPm6W/G5nSei6wqE2j30Zb68bRjmIQAQaA=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFlCsGO6jxvOwwF3fsrxiGFDZ7FrPaJbDt+I48pBJP8wOAYBEyg2utthLlzYptJTC cnTqxE6FFd0y5fwStbV/GcU46WXf1C/4Qd6anh+w0rHDNoEDrQ6/ML9Z20HFKvRpE3raDI MTbsjp/WOFeXBT1MSiMsShi3J++2z/ZPGVR2BGVf/Ecz6Dd4HIlCSKHLV9sKH2VcYYu9OI CEUV2ErAqtFQ+c02gXl/EHugaNuYGfFmH/XJzJVqQJY9zv4xlGwwPgwvqPgWyZNAmeuKH7 QVchT1yDTpIC+KnJYx0GcMRm+IjD6Syo4dmGCc1lSXshqfBT6ScYPTkF2ygh+Tmq7CzrGd zpuBoH6F29vgLL7PA0d/u92mlk14DkodQ5IhOIsirE1t4GD6/kxQQbV3QMG0cnOPeFMuO9 rndA4GXGG2IVVsIRiYKlK8dJvQm8m4Wyau/RHN3uqaXh8Lox+8xHXtKnwMbwhDPRyhfUCF 0feROjzzpFiCN+9T6HuZ7bi/pCZruzLXn7SYMEoA0BuNiDJNZTmN4BqNmHcngbLiGcc/KP 2UjAewiCzcDqONIkipfGG++0T+a5GregZHLUTqr6FdY1QiauTWRzX50FvOfWBUgT0aT6lE +S485GJ1Sl5JKqrT2apBkX86v86Sn6dN5OCGJNbnusdXSewSGjzYUO09IJnA X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Dec 2026 01:04:57 -0500 (EST) From: Ian Bridges To: Namjae Jeon Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-cifs@vger.kernel.org, Ian Bridges , 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 Message-ID: <20261204060442.30849-2-icb@fastmail.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261204060442.30849-1-icb@fastmail.org> References: <20261204060442.30849-1-icb@fastmail.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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