FAILED: patch "[PATCH] cifs: fix time_last_write stamp placement in setattr/truncate" failed to apply to 6.18-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x ecababf08905958ba8c125979c4e39fc2f1a8a05
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026101323-delta-nappy-a3a1@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ecababf08905958ba8c125979c4e39fc2f1a8a05 Mon Sep 17 00:00:00 2001
From: Frank Sorenson <[email protected]>
Date: Fri, 24 Jul 2026 11:30:36 -0500
Subject: [PATCH] cifs: fix time_last_write stamp placement in setattr/truncate
paths
cifs_file_set_size() calls cifs_setsize() on success, which calls i_size_write(), updating i_size to the new value. The subsequent check attrs->ia_size != i_size_read() in both cifs_setattr_unix() and cifs_setattr_nounix() therefore always evaluates false after a successful cifs_file_set_size(), making the smp_store_release() of time_last_write dead code. The truncate path was unprotected against stale readdir size updates.
Move the stamp to before the cifs_file_set_size() RPC call, guarded by attrs->ia_size != i_size_read() to exclude no-op same-size ftruncate(2) calls from stamping time_last_write unnecessarily.
On the error path the stamp remains rather than being restored:
restoring a stale snapshot (prev_tlw) could silently erase a concurrent _cifsFileInfo_put() close stamp if that close arrived between the READ_ONCE and the smp_store_release. readdir is suppressed until the stamp expires, which extends beyond one acregmax if the caller retries failed truncations. stat() is unaffected: the cifs_revalidate_dentry_attr() path calls cifs_fattr_to_inode() with from_readdir=false, which bypasses the time_last_write check in is_size_safe_to_change() entirely and always writes the authoritative QUERY_INFO result to i_size.
Remove the now-unreachable stamp from the dead block in both functions.
fs/smb/client/inode.c +22 -4
@@ -3190,6 +3190,17 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) rc =0 ;if (attrs->ia_valid &ATTR_SIZE ) { +if (attrs->ia_size !=i_size_read (inode)) { +/* Stamp before RPC. On failure the stamp remains: restoring a +* stale snapshot could silently erase a concurrent +* _cifsFileInfo_put() close stamp. readdir is suppressed +* until the stamp expires; stat() bypasses this via the +* from_readdir=false path in is_size_safe_to_change() and +* always returns an authoritative QUERY_INFO result. +* Pairs with smp_load_acquire() in is_size_safe_to_change(). +*/ +smp_store_release (&cifsInode->time_last_write, jiffies); + } rc =cifs_file_set_size (xid, direntry, full_path, open_file, attrs->ia_size);if (rc !=0 )
@@ -3279,8 +3290,6 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)if ((attrs->ia_valid &ATTR_SIZE ) && attrs->ia_size !=i_size_read (inode)) { -/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ -smp_store_release (&cifsInode->time_last_write, jiffies);truncate_setsize (inode, attrs->ia_size);netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true);fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size);
@@ -3370,6 +3379,17 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) }if (attrs->ia_valid &ATTR_SIZE ) { +if (attrs->ia_size !=i_size_read (inode)) { +/* Stamp before RPC. On failure the stamp remains: restoring a +* stale snapshot could silently erase a concurrent +* _cifsFileInfo_put() close stamp. readdir is suppressed +* until the stamp expires; stat() bypasses this via the +* from_readdir=false path in is_size_safe_to_change() and +* always returns an authoritative QUERY_INFO result. +* Pairs with smp_load_acquire() in is_size_safe_to_change(). +*/ +smp_store_release (&cifsInode->time_last_write, jiffies); + } rc =cifs_file_set_size (xid, direntry, full_path, cfile, attrs->ia_size);if (rc !=0 )
@@ -3482,8 +3502,6 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)if ((attrs->ia_valid &ATTR_SIZE ) && attrs->ia_size !=i_size_read (inode)) { -/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ -smp_store_release (&cifsInode->time_last_write, jiffies);truncate_setsize (inode, attrs->ia_size);netfs_resize_file (&cifsInode->netfs, attrs->ia_size, true);fscache_resize_cookie (cifs_inode_cookie (inode), attrs->ia_size);
Sasha Levin
maintainerPATCH 1/1 cifs: fix time_last_write stamp placement in setattr/truncate paths
From: Frank Sorenson <[email protected]>
[ Upstream commit ecababf08905958ba8c125979c4e39fc2f1a8a05 ]
cifs_file_set_size() calls cifs_setsize() on success, which calls i_size_write(), updating i_size to the new value. The subsequent check attrs->ia_size != i_size_read() in both cifs_setattr_unix() and cifs_setattr_nounix() therefore always evaluates false after a successful cifs_file_set_size(), making the smp_store_release() of time_last_write dead code. The truncate path was unprotected against stale readdir size updates.
Move the stamp to before the cifs_file_set_size() RPC call, guarded by attrs->ia_size != i_size_read() to exclude no-op same-size ftruncate(2) calls from stamping time_last_write unnecessarily.
On the error path the stamp remains rather than being restored:
restoring a stale snapshot (prev_tlw) could silently erase a concurrent _cifsFileInfo_put() close stamp if that close arrived between the READ_ONCE and the smp_store_release. readdir is suppressed until the stamp expires, which extends beyond one acregmax if the caller retries failed truncations. stat() is unaffected: the cifs_revalidate_dentry_attr() path calls cifs_fattr_to_inode() with from_readdir=false, which bypasses the time_last_write check in is_size_safe_to_change() entirely and always writes the authoritative QUERY_INFO result to i_size.
Remove the now-unreachable stamp from the dead block in both functions.
--- fs/smb/client/inode.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
fs/smb/client/inode.c +23 -4
@@ -3135,11 +3135,8 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,cifs_put_tlink (tlink); set_size_out: -if (rc ==0 ) { -/* Pairs with smp_load_acquire() in is_size_safe_to_change(). */ -smp_store_release (&cifsInode->time_last_write, jiffies); +if (rc ==0 )cifs_resize_file_locked (inode, size); - }return rc; }
@@ -3202,6 +3199,17 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) rc =0 ;if (attrs->ia_valid &ATTR_SIZE ) { +if (attrs->ia_size !=i_size_read (inode)) { +/* Stamp before RPC. On failure the stamp remains: restoring a +* stale snapshot could silently erase a concurrent +* _cifsFileInfo_put() close stamp. readdir is suppressed +* until the stamp expires; stat() bypasses this via the +* from_readdir=false path in is_size_safe_to_change() and +* always returns an authoritative QUERY_INFO result. +* Pairs with smp_load_acquire() in is_size_safe_to_change(). +*/ +smp_store_release (&cifsInode->time_last_write, jiffies); + } rc =cifs_file_set_size (xid, direntry, full_path, open_file, attrs->ia_size);if (rc !=0 )
@@ -3378,6 +3386,17 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) }if (attrs->ia_valid &ATTR_SIZE ) { +if (attrs->ia_size !=i_size_read (inode)) { +/* Stamp before RPC. On failure the stamp remains: restoring a +* stale snapshot could silently erase a concurrent +* _cifsFileInfo_put() close stamp. readdir is suppressed +* until the stamp expires; stat() bypasses this via the +* from_readdir=false path in is_size_safe_to_change() and +* always returns an authoritative QUERY_INFO result. +* Pairs with smp_load_acquire() in is_size_safe_to_change(). +*/ +smp_store_release (&cifsInode->time_last_write, jiffies); + } rc =cifs_file_set_size (xid, direntry, full_path, cfile, attrs->ia_size);if (rc !=0 )
Signature · 1 line
2.53.0