Skip to content

Commit b2e4cda

Browse files
daimngogregkh
authored andcommitted
NFS: Fix LTP test failures when timestamps are delegated
[ Upstream commit b623390 ] 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 <dai.ngo@oracle.com> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 35517f6 commit b2e4cda

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
@@ -711,6 +711,8 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
711711
struct inode *inode = d_inode(dentry);
712712
struct nfs_fattr *fattr;
713713
int error = 0;
714+
kuid_t task_uid = current_fsuid();
715+
kuid_t owner_uid = inode->i_uid;
714716

715717
nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
716718

@@ -732,9 +734,11 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
732734
if (nfs_have_delegated_mtime(inode) && attr->ia_valid & ATTR_MTIME) {
733735
spin_lock(&inode->i_lock);
734736
if (attr->ia_valid & ATTR_MTIME_SET) {
735-
nfs_set_timestamps_to_ts(inode, attr);
736-
attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
737+
if (uid_eq(task_uid, owner_uid)) {
738+
nfs_set_timestamps_to_ts(inode, attr);
739+
attr->ia_valid &= ~(ATTR_MTIME|ATTR_MTIME_SET|
737740
ATTR_ATIME|ATTR_ATIME_SET);
741+
}
738742
} else {
739743
nfs_update_timestamps(inode, attr->ia_valid);
740744
attr->ia_valid &= ~(ATTR_MTIME|ATTR_ATIME);
@@ -744,10 +748,12 @@ nfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
744748
attr->ia_valid & ATTR_ATIME &&
745749
!(attr->ia_valid & ATTR_MTIME)) {
746750
if (attr->ia_valid & ATTR_ATIME_SET) {
747-
spin_lock(&inode->i_lock);
748-
nfs_set_timestamps_to_ts(inode, attr);
749-
spin_unlock(&inode->i_lock);
750-
attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
751+
if (uid_eq(task_uid, owner_uid)) {
752+
spin_lock(&inode->i_lock);
753+
nfs_set_timestamps_to_ts(inode, attr);
754+
spin_unlock(&inode->i_lock);
755+
attr->ia_valid &= ~(ATTR_ATIME|ATTR_ATIME_SET);
756+
}
751757
} else {
752758
nfs_update_delegated_atime(inode);
753759
attr->ia_valid &= ~ATTR_ATIME;

0 commit comments

Comments
 (0)