From patchwork Wed Nov 2 15:04:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9409333 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 8B6E76022E for ; Wed, 2 Nov 2016 15:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C97B2A2F3 for ; Wed, 2 Nov 2016 15:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 703B92A2F5; Wed, 2 Nov 2016 15:05:49 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 2554A2A2F3 for ; Wed, 2 Nov 2016 15:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755977AbcKBPFe (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 Received: by mail-yw0-f194.google.com with SMTP id l124so615194ywb.1; Wed, 02 Nov 2016 08:05:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ujppsiY9+iv5Df5krY9om09VLgwWz7Ck9UCPjGWCKlY=; b=0+subl7GWVbUlQaj0TIObuGUpZygeu+Vg7+c7/Jpp5XQLEON6k6F2Ne7kNRvsgJak8 AVpA60oQI1E8On3ZAJO8ZE4iwJYPT/Kozudq5baYr8M6OL0t7Cs5uegEskWrZYoRGJ5L MtslRfnc/Z/wY4HlgRXyZbqpfX8XKJf8xL5lveme6Qp2RRpm0WBbjXrHwPPpE8sl8kvm XhixslyqL0Sl3Xud1XfQIuDo9r+LHFAbzx5QN0cjCtUx83c9mqGNT2wc/ME1qv5q6no4 iYb5YAS3bIOqIJ6XbRWEQpEOb3N9lQLM8k+hMWElII330Jq2ln1NfLS1y30Ce1k+Hgr3 2GYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ujppsiY9+iv5Df5krY9om09VLgwWz7Ck9UCPjGWCKlY=; b=B79aX8v7uXcY1x5CzHGSkbfIKtqAujRveBooYhg/NiaLGQWsfZfXxjv3WKDJvhdI0W YoHqeTacok5rlQJBg4u6XqTojm8D61+o2gQXjaw4tD7DT1m2SVDThvN4haz/4JVaoYiy jDyYHuXDHqNLp1hkqEst09hJk23h7XiONZYJZyY0kZw8PrID7Q0lxYadnR2ycf++UYps c5A3yRDWsTMwtJPZxkqoR1+xCEnD6fg544xLy4pajdRzF9b5HuB4g+ZXRG/yicY9c1Q3 AjpRv3sxyaPvPv+PaPsFE1ki2wx9J548ZCiiUId39eZmuetTdhFKZ/LMgBF/cD3ufmlV VSPg== X-Gm-Message-State: ABUngvfSd6g5iHjhPeKTS06aJ03hUCuwa0N7ZB4zsBu9rEa4CAa+rT6vZL+cB9II4afguw== X-Received: by 10.129.38.69 with SMTP id m66mr2736095ywm.34.1478099116846; Wed, 02 Nov 2016 08:05:16 -0700 (PDT) Received: from deepa-ubuntu.hil-sfecghh.abq.wayport.net (ip-64-134-56-224.public.wayport.net. [64.134.56.224]) by smtp.gmail.com with ESMTPSA id m126sm723358ywf.14.2016.11.02.08.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Nov 2016 08:05:16 -0700 (PDT) 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-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 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; } /*