From patchwork Sat Feb 25 01:41:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9591435 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 17F6B60471 for ; Sat, 25 Feb 2017 01:43:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07C7F275A2 for ; Sat, 25 Feb 2017 01:43:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0D6B286AC; Sat, 25 Feb 2017 01:43:22 +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=unavailable 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 AA16B275A2 for ; Sat, 25 Feb 2017 01:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbdBYBmV (ORCPT ); Fri, 24 Feb 2017 20:42:21 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35760 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751588AbdBYBmA (ORCPT ); Fri, 24 Feb 2017 20:42:00 -0500 Received: by mail-pg0-f66.google.com with SMTP id 1so4989108pgz.2; Fri, 24 Feb 2017 17:41:23 -0800 (PST) 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=dSEabyTa6gRKEZ/H4hm+Uk97TLFfavcW7k4XzP362qF2rN6t7Nx9UF0EMOrIFBxECU x2OCOCHpk7XGR2zFuykGJTW44xStydGsBpWiOB+D+uLM2xcASb/dYhlhCzbj3APMYwcO tCcosm4gSpHVt7JxKvXiTkyH/nWYvl18BTF2pJHMObddrdNSG2YzHrPb9ISfuUhRd9bV rdA0qvuWRMPT3EGBYZYGKPpNCWFf6l6DhgPuKkh4LeFSX8DYIy6/t8nFV0cxlhmLkxAJ zUjJscbO8rQqTg+hEktt1ug+G8j99U51PVhUXmF5AG/OeMTvu1Ywuwl29BbX8pgZRLFG Fjjw== 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=Ao2C4a6q6FKHDvqpSD5aMCBWUoRYBHJ7vmGZCr47IXy9kJ6f975DmJaE8/rkUwW6wj tsKOeqCZ+S9XU2SlaZZt+7cwVRb/0PJJcqm/EIphtWXoCjt0et7AkK8RNHhpLlMSr6H9 /o2dQCuXTtt1QOPaEGTH2m7d2n65fsKx/F6Yiz3+EeVu+8sMdmAGdZt78tGfjoE/hnBP ybZgHF5YuiEBxAwBq/RsJhXAIMlIiW8ywavn+Z6S5xHf9sZd/PApjVHYtheuCafhRwbZ YBDvcoo/GkfV5a4Kh5G8R4BxI+o6Z7MCl6QtWXFqTtaLk3KBoAJqnrZKlUuU1KEqAi9B 3Ydg== X-Gm-Message-State: AMke39mPi/msiLTgDX2ccUIqfPmAg/vqzld3fDe6cXRrAZo93e4eVEyP4QuDsFBhWmMOyw== X-Received: by 10.84.164.106 with SMTP id m39mr8172779plg.9.1487986882816; Fri, 24 Feb 2017 17:41:22 -0800 (PST) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:d459:bd54:9ed4:a3f5]) by smtp.gmail.com with ESMTPSA id o24sm17175001pfj.78.2017.02.24.17.41.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Feb 2017 17:41:22 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v4 5/5] utimes: Clamp the timestamps before update Date: Fri, 24 Feb 2017 17:41:03 -0800 Message-Id: <1487986863-6005-6-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487986863-6005-1-git-send-email-deepa.kernel@gmail.com> References: <1487986863-6005-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; } /*