[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1491680267-11171-6-git-send-email-deepa.kernel@gmail.com>
Date: Sat, 8 Apr 2017 12:37:47 -0700
From: Deepa Dinamani <deepa.kernel@...il.com>
To: viro@...iv.linux.org.uk, tytso@....edu, adilger.kernel@...ger.ca,
linux-ext4@...r.kernel.org
Cc: torvalds@...ux-foundation.org, tglx@...utronix.de,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
arnd@...db.de, y2038@...ts.linaro.org
Subject: [PATCH v5 5/5] utimes: Clamp the timestamps before update
POSIX.1 section for futimens, utimensat and utimes says:
The file's relevant timestamp shall be set to the
greatest value supported by the file system that is
not greater than the specified time.
Clamp the timestamps accordingly before assignment.
Note that the clamp_t macro is used for clamping here as vfs
is not yet using struct timespec64 internally. This is
required for compilation purposes.
Also note that clamp won't do the right thing for timestamps
beyond 2038 on 32-bit machines until the vfs uses timespec64.
After the vfs is transitioned to use timespec64 for timestamps,
clamp_t() can be replaced by clamp().
Signed-off-by: Deepa Dinamani <deepa.kernel@...il.com>
---
fs/utimes.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/utimes.c b/fs/utimes.c
index 32b15b3..052fe5d 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -53,6 +53,7 @@ static int utimes_common(const struct path *path, struct timespec *times)
int error;
struct iattr newattrs;
struct inode *inode = path->dentry->d_inode;
+ struct super_block *sb = inode->i_sb;
struct inode *delegated_inode = NULL;
error = mnt_want_write(path->mnt);
@@ -68,16 +69,24 @@ static int utimes_common(const struct path *path, struct timespec *times)
if (times[0].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_ATIME;
else if (times[0].tv_nsec != UTIME_NOW) {
- newattrs.ia_atime.tv_sec = times[0].tv_sec;
- newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
+ newattrs.ia_atime.tv_sec =
+ clamp_t(time64_t, times[0].tv_sec, sb->s_time_min, sb->s_time_max);
+ if (times[0].tv_sec >= sb->s_time_max)
+ newattrs.ia_atime.tv_nsec = 0;
+ else
+ newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
newattrs.ia_valid |= ATTR_ATIME_SET;
}
if (times[1].tv_nsec == UTIME_OMIT)
newattrs.ia_valid &= ~ATTR_MTIME;
else if (times[1].tv_nsec != UTIME_NOW) {
- newattrs.ia_mtime.tv_sec = times[1].tv_sec;
- newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
+ newattrs.ia_mtime.tv_sec =
+ clamp_t(time64_t, times[1].tv_sec, sb->s_time_min, sb->s_time_max);
+ if (times[1].tv_sec >= sb->s_time_max)
+ newattrs.ia_mtime.tv_nsec = 0;
+ else
+ newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
newattrs.ia_valid |= ATTR_MTIME_SET;
}
/*
--
2.7.4
Powered by blists - more mailing lists