From patchwork Sat Apr 8 19:37:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9671217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A0F9C60365 for ; Sat, 8 Apr 2017 19:39:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 922DC28417 for ; Sat, 8 Apr 2017 19:39:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86E582841E; Sat, 8 Apr 2017 19:39:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A51728417 for ; Sat, 8 Apr 2017 19:39:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752652AbdDHTjs (ORCPT ); Sat, 8 Apr 2017 15:39:48 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36191 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751144AbdDHTjQ (ORCPT ); Sat, 8 Apr 2017 15:39:16 -0400 Received: by mail-pf0-f195.google.com with SMTP id i5so1918981pfc.3; Sat, 08 Apr 2017 12:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=m4ScZKDLJaAVZx/3ycJY0Lrk5NjhYjlXVatA0RyB3iE=; b=Wgf2fq3GyV0J1ZbWvypTon87bC320YwhIx6mdFVhv5IiDmIMpDrCM774Ib5MlTqQO1 M4Fim51uZ2giQkaYAc5PM3P9TlwF6rFZMNgcRDmUfbF3Dxgs/cDkUDpnpLP9AEFMiHeK PWSkABHwRquzCXOz9dwt4vWaep7DhpB12mb4ckaQqDqSbfwIZOqvWG+g7Aocnuyo0N8W uq5IZKIfAADH1ouZyqfJgjRZ08VH3xX00f0k3iTo56aIn2y1BN8DHvqFnAUaqbutxVb+ zxFq20Z2mB4+MO/PpdNpVtGfZ/s1/nSeb+3o9no+DRLb4L9BzGi7RrPW30IMOATbQor2 Ow7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=m4ScZKDLJaAVZx/3ycJY0Lrk5NjhYjlXVatA0RyB3iE=; b=NfxeZWFlGAhphgLsOsKWeByq6eFNce35BENar11CD0TakhcUuwQ1yS8Pa/8tVmPOWR PQyfMzvhBVZN1xajHU6NXnFfp1QzTZ4EK3kRDaUqVc69iY/ucMJpquPxT4Du7cNm90xP l7rMnnozZqK7eaEqCq+yR4Ro7WcPoqLunG+fAZO+BoSl/t1WmFXNznP74AxUkHUA6LcZ Cc3BLu1i3CpJT7RBDn7F4wrQl+gt3eGZV+T4p1JFAsM5YdXYZIkYaNzZG/c4wVZt97YQ DbrO9Hkp0JJAX0XY8vJGlsKn2kfCATybQd9j2MEoMrMyZ8v0y8MDNIGIt7duxI1RQdtK wJJA== X-Gm-Message-State: AFeK/H0OOjr3MRkh9spLrWYQCK5Yc6LD1LUuWMOJMgXKSr7L+i53K9t6Lc6zCQaC+Ry2wQ== X-Received: by 10.98.148.2 with SMTP id m2mr15642054pfe.194.1491680355982; Sat, 08 Apr 2017 12:39:15 -0700 (PDT) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:b9e0:ac:e01a:86f8]) by smtp.gmail.com with ESMTPSA id t12sm16328627pfg.14.2017.04.08.12.39.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Apr 2017 12:39:15 -0700 (PDT) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, tglx@linutronix.de, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v5 5/5] utimes: Clamp the timestamps before update Date: Sat, 8 Apr 2017 12:37:47 -0700 Message-Id: <1491680267-11171-6-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491680267-11171-1-git-send-email-deepa.kernel@gmail.com> References: <1491680267-11171-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; } /*