[PATCH v3 05/12] nfsd: set ctime when a SETATTR with delegated times changes other attributes

From: Jeff Layton

Date: Tue Nov 24 2026 - 14:49:28 EST


__nfsd_setattr() adds ATTR_CTIME only when ATTR_DELEG is clear, to keep
a delegated atime-only update from moving ctime. But ATTR_DELEG is set
for the whole iattr, so a holder's chmod or chown sent along with a
delegated atime changes the mode or owner without updating ctime.

Add ATTR_CTIME unless the request is a delegated atime-only update. A
delegated mtime whose ctime fails vetting now moves ctime to the current
time instead of leaving ctime alone. Since ctime moves, set dl_setattr
whenever the delegated mtime is applied. Otherwise DELEGRETURN of a
written file restamps the vetted mtime and atime to the current time.

Fixes: f9a348e0de19 ("nfsd: don't set the ctime on delegated atime updates")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfsd/nfs4proc.c | 6 +++---
fs/nfsd/vfs.c | 8 +++++---
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index b76320c265e1..f8473d0923b8 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1378,10 +1378,10 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)

if (setattr->sa_bmval[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) {
if (nfsd4_vet_deleg_time(&iattr->ia_mtime, &dp->dl_mtime, &now)) {
+ /* ctime moves too, so DELEGRETURN needn't restamp */
+ dp->dl_setattr = true;
iattr->ia_ctime = iattr->ia_mtime;
- if (nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now))
- dp->dl_setattr = true;
- else
+ if (!nfsd4_vet_deleg_time(&iattr->ia_ctime, &dp->dl_ctime, &now))
iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET);
} else {
iattr->ia_valid &= ~(ATTR_CTIME | ATTR_CTIME_SET |
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 4a5674e583cc..7bc251d55c3c 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -513,10 +513,12 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
/*
* If ATTR_DELEG is set, then this is an update from a client that
* holds a delegation. If this is an update for only the atime, the
- * ctime should not be changed. If the update contains the mtime
- * too, then ATTR_CTIME should already be set.
+ * ctime should not be changed. Any other attribute change, such as
+ * a mode or owner change sent along with a delegated atime, must
+ * update the ctime.
*/
- if (!(iap->ia_valid & ATTR_DELEG))
+ if (!(iap->ia_valid & ATTR_DELEG) ||
+ (iap->ia_valid & ~(ATTR_DELEG | ATTR_ATIME | ATTR_ATIME_SET)))
iap->ia_valid |= ATTR_CTIME;

return notify_change(&nop_mnt_idmap, dentry, iap, NULL);

--
2.56.1