From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755995AbcKBPFe (ORCPT ); Wed, 2 Nov 2016 11:05:34 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:34038 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753761AbcKBPFR (ORCPT ); Wed, 2 Nov 2016 11:05:17 -0400 From: Deepa Dinamani To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, tglx@linutronix.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, tytso@mit.edu, viro@zeniv.linux.org.uk, y2038@lists.linaro.org Subject: [RFC 6/6] utimes: Clamp the timestamps before update Date: Wed, 2 Nov 2016 08:04:56 -0700 Message-Id: <1478099096-25637-7-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478099096-25637-1-git-send-email-deepa.kernel@gmail.com> References: <1478099096-25637-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 clamp_t macro is used for clamping here as vfs is not yet using struct timespec64 internally. This is for compilation purposes only. The actual patch can only be merged only after vfs is transitioned to use timespec64 for correct operation of clamp macro. At which point, clamp_t() will be replaced by clamp(). Signed-off-by: Deepa Dinamani --- fs/utimes.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/utimes.c b/fs/utimes.c index 22307cd..186e12b 100644 --- a/fs/utimes.c +++ b/fs/utimes.c @@ -53,6 +53,7 @@ static int utimes_common(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(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_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_mtime.tv_nsec = times[1].tv_nsec; newattrs.ia_valid |= ATTR_MTIME_SET; } /* -- 2.7.4