Skip to content

Commit eb31e2f

Browse files
amir73ilAl Viro
authored andcommitted
utimes: Clamp the timestamps in notify_change()
Push clamping timestamps into notify_change(), so in-kernel callers like nfsd and overlayfs will get similar timestamp set behavior as utimes. AV: get rid of clamping in ->setattr() instances; we don't need to bother with that there, with notify_change() doing normalization in all cases now (it already did for implicit case, since current_time() clamps). Suggested-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: 42e729b ("utimes: Clamp the timestamps before update") Cc: stable@vger.kernel.org # v5.4 Cc: Deepa Dinamani <deepa.kernel@gmail.com> Cc: Jeff Layton <jlayton@kernel.org> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e42617b commit eb31e2f

6 files changed

Lines changed: 34 additions & 56 deletions

File tree

‎fs/attr.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,12 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)
183183
inode->i_uid = attr->ia_uid;
184184
if (ia_valid & ATTR_GID)
185185
inode->i_gid = attr->ia_gid;
186-
if (ia_valid & ATTR_ATIME) {
187-
inode->i_atime = timestamp_truncate(attr->ia_atime,
188-
inode);
189-
}
190-
if (ia_valid & ATTR_MTIME) {
191-
inode->i_mtime = timestamp_truncate(attr->ia_mtime,
192-
inode);
193-
}
194-
if (ia_valid & ATTR_CTIME) {
195-
inode->i_ctime = timestamp_truncate(attr->ia_ctime,
196-
inode);
197-
}
186+
if (ia_valid & ATTR_ATIME)
187+
inode->i_atime = attr->ia_atime;
188+
if (ia_valid & ATTR_MTIME)
189+
inode->i_mtime = attr->ia_mtime;
190+
if (ia_valid & ATTR_CTIME)
191+
inode->i_ctime = attr->ia_ctime;
198192
if (ia_valid & ATTR_MODE) {
199193
umode_t mode = attr->ia_mode;
200194

@@ -268,8 +262,13 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de
268262
attr->ia_ctime = now;
269263
if (!(ia_valid & ATTR_ATIME_SET))
270264
attr->ia_atime = now;
265+
else
266+
attr->ia_atime = timestamp_truncate(attr->ia_atime, inode);
271267
if (!(ia_valid & ATTR_MTIME_SET))
272268
attr->ia_mtime = now;
269+
else
270+
attr->ia_mtime = timestamp_truncate(attr->ia_mtime, inode);
271+
273272
if (ia_valid & ATTR_KILL_PRIV) {
274273
error = security_inode_need_killpriv(dentry);
275274
if (error < 0)

‎fs/configfs/inode.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@ int configfs_setattr(struct dentry * dentry, struct iattr * iattr)
7676
if (ia_valid & ATTR_GID)
7777
sd_iattr->ia_gid = iattr->ia_gid;
7878
if (ia_valid & ATTR_ATIME)
79-
sd_iattr->ia_atime = timestamp_truncate(iattr->ia_atime,
80-
inode);
79+
sd_iattr->ia_atime = iattr->ia_atime;
8180
if (ia_valid & ATTR_MTIME)
82-
sd_iattr->ia_mtime = timestamp_truncate(iattr->ia_mtime,
83-
inode);
81+
sd_iattr->ia_mtime = iattr->ia_mtime;
8482
if (ia_valid & ATTR_CTIME)
85-
sd_iattr->ia_ctime = timestamp_truncate(iattr->ia_ctime,
86-
inode);
83+
sd_iattr->ia_ctime = iattr->ia_ctime;
8784
if (ia_valid & ATTR_MODE) {
8885
umode_t mode = iattr->ia_mode;
8986

‎fs/f2fs/file.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -754,18 +754,12 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr)
754754
inode->i_uid = attr->ia_uid;
755755
if (ia_valid & ATTR_GID)
756756
inode->i_gid = attr->ia_gid;
757-
if (ia_valid & ATTR_ATIME) {
758-
inode->i_atime = timestamp_truncate(attr->ia_atime,
759-
inode);
760-
}
761-
if (ia_valid & ATTR_MTIME) {
762-
inode->i_mtime = timestamp_truncate(attr->ia_mtime,
763-
inode);
764-
}
765-
if (ia_valid & ATTR_CTIME) {
766-
inode->i_ctime = timestamp_truncate(attr->ia_ctime,
767-
inode);
768-
}
757+
if (ia_valid & ATTR_ATIME)
758+
inode->i_atime = attr->ia_atime;
759+
if (ia_valid & ATTR_MTIME)
760+
inode->i_mtime = attr->ia_mtime;
761+
if (ia_valid & ATTR_CTIME)
762+
inode->i_ctime = attr->ia_ctime;
769763
if (ia_valid & ATTR_MODE) {
770764
umode_t mode = attr->ia_mode;
771765

‎fs/ntfs/inode.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,18 +2899,12 @@ int ntfs_setattr(struct dentry *dentry, struct iattr *attr)
28992899
ia_valid |= ATTR_MTIME | ATTR_CTIME;
29002900
}
29012901
}
2902-
if (ia_valid & ATTR_ATIME) {
2903-
vi->i_atime = timestamp_truncate(attr->ia_atime,
2904-
vi);
2905-
}
2906-
if (ia_valid & ATTR_MTIME) {
2907-
vi->i_mtime = timestamp_truncate(attr->ia_mtime,
2908-
vi);
2909-
}
2910-
if (ia_valid & ATTR_CTIME) {
2911-
vi->i_ctime = timestamp_truncate(attr->ia_ctime,
2912-
vi);
2913-
}
2902+
if (ia_valid & ATTR_ATIME)
2903+
vi->i_atime = attr->ia_atime;
2904+
if (ia_valid & ATTR_MTIME)
2905+
vi->i_mtime = attr->ia_mtime;
2906+
if (ia_valid & ATTR_CTIME)
2907+
vi->i_ctime = attr->ia_ctime;
29142908
mark_inode_dirty(vi);
29152909
out:
29162910
return err;

‎fs/ubifs/file.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,18 +1078,12 @@ static void do_attr_changes(struct inode *inode, const struct iattr *attr)
10781078
inode->i_uid = attr->ia_uid;
10791079
if (attr->ia_valid & ATTR_GID)
10801080
inode->i_gid = attr->ia_gid;
1081-
if (attr->ia_valid & ATTR_ATIME) {
1082-
inode->i_atime = timestamp_truncate(attr->ia_atime,
1083-
inode);
1084-
}
1085-
if (attr->ia_valid & ATTR_MTIME) {
1086-
inode->i_mtime = timestamp_truncate(attr->ia_mtime,
1087-
inode);
1088-
}
1089-
if (attr->ia_valid & ATTR_CTIME) {
1090-
inode->i_ctime = timestamp_truncate(attr->ia_ctime,
1091-
inode);
1092-
}
1081+
if (attr->ia_valid & ATTR_ATIME)
1082+
inode->i_atime = attr->ia_atime;
1083+
if (attr->ia_valid & ATTR_MTIME)
1084+
inode->i_mtime = attr->ia_mtime;
1085+
if (attr->ia_valid & ATTR_CTIME)
1086+
inode->i_ctime = attr->ia_ctime;
10931087
if (attr->ia_valid & ATTR_MODE) {
10941088
umode_t mode = attr->ia_mode;
10951089

‎fs/utimes.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ static int utimes_common(const struct path *path, struct timespec64 *times)
3636
if (times[0].tv_nsec == UTIME_OMIT)
3737
newattrs.ia_valid &= ~ATTR_ATIME;
3838
else if (times[0].tv_nsec != UTIME_NOW) {
39-
newattrs.ia_atime = timestamp_truncate(times[0], inode);
39+
newattrs.ia_atime = times[0];
4040
newattrs.ia_valid |= ATTR_ATIME_SET;
4141
}
4242

4343
if (times[1].tv_nsec == UTIME_OMIT)
4444
newattrs.ia_valid &= ~ATTR_MTIME;
4545
else if (times[1].tv_nsec != UTIME_NOW) {
46-
newattrs.ia_mtime = timestamp_truncate(times[1], inode);
46+
newattrs.ia_mtime = times[1];
4747
newattrs.ia_valid |= ATTR_MTIME_SET;
4848
}
4949
/*

0 commit comments

Comments
 (0)