From: Deepa Dinamani <deepa.kernel@gmail.com>
To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca,
linux-ext4@vger.kernel.org
Cc: arnd@arndb.de, y2038@lists.linaro.org,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
tglx@linutronix.de, torvalds@linux-foundation.org
Subject: [PATCH v5 5/5] utimes: Clamp the timestamps before update
Date: Sat, 8 Apr 2017 12:37:47 -0700 [thread overview]
Message-ID: <1491680267-11171-6-git-send-email-deepa.kernel@gmail.com> (raw)
In-Reply-To: <1491680267-11171-1-git-send-email-deepa.kernel@gmail.com>
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@gmail.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
_______________________________________________
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038
prev parent reply other threads:[~2017-04-08 19:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-08 19:37 [PATCH v5 0/5] vfs: Add timestamp range check support Deepa Dinamani
2017-04-08 19:37 ` [PATCH v5 1/5] vfs: Add file timestamp range support Deepa Dinamani
2017-04-08 19:37 ` [PATCH v5 2/5] vfs: Add checks for filesystem timestamp limits Deepa Dinamani
2017-04-08 20:04 ` Linus Torvalds
2017-04-09 2:58 ` Deepa Dinamani
2017-04-25 19:47 ` Arnd Bergmann
2017-04-25 20:02 ` Linus Torvalds
2017-04-25 20:31 ` Arnd Bergmann
2017-04-25 20:35 ` Linus Torvalds
2017-04-25 21:23 ` Arnd Bergmann
2017-04-08 19:37 ` [PATCH v5 3/5] ext4: Initialize timestamps limits Deepa Dinamani
2017-04-08 19:37 ` [PATCH v5 4/5] vfs: Add timestamp_truncate() api Deepa Dinamani
2017-04-08 19:37 ` Deepa Dinamani [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1491680267-11171-6-git-send-email-deepa.kernel@gmail.com \
--to=deepa.kernel@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=arnd@arndb.de \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=y2038@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).