]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFS: Fix LTP test failures when timestamps are delegated
authorDai Ngo <dai.ngo@oracle.com>
Sun, 9 Nov 2025 17:05:08 +0000 (09:05 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 09:35:55 +0000 (10:35 +0100)
[ Upstream commit b623390045a81fc559decb9bfeb79319721d3dfb ]

The utimes01 and utime06 tests fail when delegated timestamps are
enabled, specifically in subtests that modify the atime and mtime
fields using the 'nobody' user ID.

The problem can be reproduced as follow:

# echo "/media *(rw,no_root_squash,sync)" >> /etc/exports
# export -ra
# mount -o rw,nfsvers=4.2 127.0.0.1:/media /tmpdir
# cd /opt/ltp
# ./runltp -d /tmpdir -s utimes01
# ./runltp -d /tmpdir -s utime06

This issue occurs because nfs_setattr does not verify the inode's
UID against the caller's fsuid when delegated timestamps are
permitted for the inode.

This patch adds the UID check and if it does not match then the
request is sent to the server for permission checking.

Fixes: e12912d94137 ("NFSv4: Add support for delegated atime and mtime attributes")
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfs/inode.c

index 5bf5fb5ddd34c0327d63f4f4f0ed42996bced814..5bab9db5417c20f9043076bc4804c61a310bc057 100644 (file)
@@ -711,6 +711,8 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
        struct inode *inode = d_inode(dentry);
        struct nfs_fattr *fattr;
        int error = 0;
+       kuid_t task_uid = current_fsuid();
+       kuid_t owner_uid = inode->i_uid;
 
        nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
 
@@ -732,9 +734,11 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
        if (nfs_have_delegated_mtime(inode) && attr->ia_valid & ATTR_MTIME) {
                spin_lock(&inode->i_lock);
                if (attr->ia_valid & ATTR_MTIME_SET) {
-                       nfs_set_timestamps_to_ts(inode, attr);
-                       attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
+                       if (uid_eq(task_uid, owner_uid)) {
+                               nfs_set_timestamps_to_ts(inode, attr);
+                               attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
                                                ATTR_ATIME|ATTR_ATIME_SET);
+                       }
                } else {
                        nfs_update_timestamps(inode, attr->ia_valid);
                        attr->ia_valid &= ~(ATTR_MTIME|ATTR_ATIME);
@@ -744,10 +748,12 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
                   attr->ia_valid & ATTR_ATIME &&
                   !(attr->ia_valid & ATTR_MTIME)) {
                if (attr->ia_valid & ATTR_ATIME_SET) {
-                       spin_lock(&inode->i_lock);
-                       nfs_set_timestamps_to_ts(inode, attr);
-                       spin_unlock(&inode->i_lock);
-                       attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
+                       if (uid_eq(task_uid, owner_uid)) {
+                               spin_lock(&inode->i_lock);
+                               nfs_set_timestamps_to_ts(inode, attr);
+                               spin_unlock(&inode->i_lock);
+                               attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
+                       }
                } else {
                        nfs_update_delegated_atime(inode);
                        attr->ia_valid &= ~ATTR_ATIME;