Skip to content

cifs: follow-on fixes to time_last_write mechanism

Frank Sorenson linux-cifs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2cifs: consolidate time_last_write stamp into _cifsFileInfo_put()fs/smb/client/file.c fs/smb/client/misc.c+22 -660 replies
2/2cifs: fix time_last_write stamp placement in setattr/truncate pathsfs/smb/client/inode.c+22 -40 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchPaulo Alcantara (Red Hat)
SeriesR-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] cifs: follow-on fixes to time_last_write mechanism

This series addresses two correctness issues in commit e8a8d54c2d50 ("cifs: prevent readdir from changing file size due to stale directory metadata"), which introduced the time_last_write field to protect cached file sizes from stale Windows Server directory enumeration metadata.

Patch 1 consolidates the time_last_write stamp into _cifsFileInfo_put(). The original commit scattered the stamp across cifs_close(), smb2_deferred_work_close(), and three deferred-close drain functions in misc.c. This missed the case where background I/O holds the final file reference after userspace close() returns -- the stamp was anchored to the earlier userspace-close time rather than the actual server close, allowing the protection window to expire before the handle was removed from openFileList. Moving the stamp into _cifsFileInfo_put() under open_file_lock provides a single canonical location that covers all close paths and uses the spinlock's store-release/load-acquire pairing with is_inode_writable() for correct memory ordering.

Patch 2 fixes the stamp placement in the setattr/truncate paths. cifs_file_set_size() calls cifs_setsize() on success, which calls i_size_write() and updates i_size. The subsequent check attrs->ia_size != i_size_read() therefore always evaluates false after a successful cifs_file_set_size(), making the stamp dead code -- the truncate path was completely unprotected. The fix moves the stamp to before the RPC call, guarded by attrs->ia_size != i_size_read() to exclude no-op same-size ftruncate(2) calls. On failure the stamp is left in place rather than 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; stat() is unaffected because cifs_revalidate_dentry_attr() uses from_readdir=false, bypassing the time_last_write check entirely and always returning an authoritative QUERY_INFO result.

Frank Sorenson (2):
cifs: consolidate time_last_write stamp into _cifsFileInfo_put()
cifs: fix time_last_write stamp placement in setattr/truncate paths

 fs/smb/client/file.c  | 37 ++++++++++++++++---------------------
 fs/smb/client/inode.c | 26 ++++++++++++++++++++++----
 fs/smb/client/misc.c  | 51 ++++++---------------------------------------------
 3 files changed, 44 insertions(+), 70 deletions(-)

--
2.55.0