Skip to content

Commit b623390

Browse files
daimngoAnna Schumaker
authored andcommitted
NFS: Fix LTP test failures when timestamps are delegated
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: e12912d ("NFSv4: Add support for delegated atime and mtime attributes") Signed-off-by: Dai Ngo <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 1f214e9 commit b623390

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

fs/nfs/inode.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
718718
struct nfs_fattr *fattr;
719719
loff_t oldsize = i_size_read(inode);
720720
int error = 0;
721+
kuid_t task_uid = current_fsuid();
722+
kuid_t owner_uid = inode->i_uid;
721723

722724
nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
723725

@@ -739,9 +741,11 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
739741
if (nfs_have_delegated_mtime(inode) && attr->ia_valid & ATTR_MTIME) {
740742
spin_lock(&inode->i_lock);
741743
if (attr->ia_valid & ATTR_MTIME_SET) {
742-
nfs_set_timestamps_to_ts(inode, attr);
743-
attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
744+
if (uid_eq(task_uid, owner_uid)) {
745+
nfs_set_timestamps_to_ts(inode, attr);
746+
attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
744747
ATTR_ATIME|ATTR_ATIME_SET);
748+
}
745749
} else {
746750
nfs_update_timestamps(inode, attr->ia_valid);
747751
attr->ia_valid &= ~(ATTR_MTIME|ATTR_ATIME);
@@ -751,10 +755,12 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
751755
attr->ia_valid & ATTR_ATIME &&
752756
!(attr->ia_valid & ATTR_MTIME)) {
753757
if (attr->ia_valid & ATTR_ATIME_SET) {
754-
spin_lock(&inode->i_lock);
755-
nfs_set_timestamps_to_ts(inode, attr);
756-
spin_unlock(&inode->i_lock);
757-
attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
758+
if (uid_eq(task_uid, owner_uid)) {
759+
spin_lock(&inode->i_lock);
760+
nfs_set_timestamps_to_ts(inode, attr);
761+
spin_unlock(&inode->i_lock);
762+
attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
763+
}
758764
} else {
759765
nfs_update_delegated_atime(inode);
760766
attr->ia_valid &= ~ATTR_ATIME;

0 commit comments

Comments
 (0)