[PATCH v3 8/8] nfsd: raise delegated time floors after a size-changing SETATTR

From: Jeff Layton

Date: Mon Nov 09 2026 - 15:42:53 EST


A size-changing SETATTR stamps c/mtime on the server
(__nfsd_setattr(), RFC 8881 section 18.30.4), but dl_mtime and dl_ctime
stay at their earlier values. A holder mtime from before the truncate
still passes vetting and moves mtime back past the truncate. The Linux
client can send one: if a delegation return starts while
nfs_vmtruncate() has i_lock dropped, DELEGRETURN carries the
pre-truncate mtime.

When the SETATTR uses a timestamp delegation's stateid, have
nfsd_setattr() record the c/mtime the size change set in dl_mtime and
dl_ctime. A holder time at or before the server's own stamp is stale.

Fixes: 6ae30d6eb26b ("nfsd: add support for delegated timestamps")
Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
fs/nfsd/nfs4proc.c | 4 ++++
fs/nfsd/nfs4state.c | 10 +++++++---
fs/nfsd/vfs.h | 2 +-
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index a65e13f0f77a..7fef904c3366 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1379,6 +1379,10 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
status = nfs_ok;
}
}
+ } else if (st && (st->sc_type & SC_TYPE_DELEG) &&
+ deleg_attrs_deleg(delegstateid(st)->dl_type)) {
+ /* Have nfsd_setattr() record the c/mtime the size change sets */
+ attrs.na_deleg = delegstateid(st);
}
if (status)
goto out_err;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 03e694f635db..606c4b469728 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -10812,8 +10812,9 @@ void nfsd4_vet_deleg_attrs(struct iattr *iattr, struct nfs4_delegation *dp,
* @iattr: vetted attributes, not the copy notify_change() altered
* @dp: timestamp delegation whose holder supplied the times
*
- * Set dl_*time to the times applied, so a stale holder time can't move
- * them backward and a repeated CB_GETATTR reply isn't reapplied.
+ * Set dl_*time to the times applied, or to the c/mtime a size change
+ * stamped, so a stale holder time can't move them backward and a repeated
+ * CB_GETATTR reply isn't reapplied.
*
* Context: Caller holds the inode_lock.
*/
@@ -10830,9 +10831,12 @@ void nfsd4_record_deleg_attrs(const struct iattr *iattr,
dp->dl_mtime = iattr->ia_mtime;
/* Don't let DELEGRETURN stamp over the holder's mtime */
dp->dl_setattr = true;
+ } else if (iattr->ia_valid & ATTR_SIZE) {
+ /* RFC 8881 section 18.30.4: a size change sets mtime */
+ dp->dl_mtime = inode_get_mtime(inode);
}
/* Ctime may be "now", or inode_set_ctime_deleg() kept a later one */
- if (iattr->ia_valid & ATTR_CTIME)
+ if (iattr->ia_valid & (ATTR_CTIME | ATTR_SIZE))
dp->dl_ctime = inode_get_ctime(inode);
}

diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
index 78cfa0dcaf5c..34ec8293e7b8 100644
--- a/fs/nfsd/vfs.h
+++ b/fs/nfsd/vfs.h
@@ -103,7 +103,7 @@ struct nfsd_attrs {
struct posix_acl *na_pacl; /* input */
struct posix_acl *na_dpacl; /* input */

- /* input: vet and record these FATTR4_WORD2_TIME_DELEG_* times */
+ /* input: timestamp delegation to vet and record times against */
struct nfs4_delegation *na_deleg;
u32 na_deleg_attrs;


--
2.56.0