From patchwork Thu Nov 24 00:47:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9444583 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 A108F600BA for ; Thu, 24 Nov 2016 00:49:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E433279D1 for ; Thu, 24 Nov 2016 00:49:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD1A27E3E; Thu, 24 Nov 2016 00:49:37 +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=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 219CA27D8D for ; Thu, 24 Nov 2016 00:49:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936254AbcKXAte (ORCPT ); Wed, 23 Nov 2016 19:49:34 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33884 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935215AbcKXAsj (ORCPT ); Wed, 23 Nov 2016 19:48:39 -0500 Received: by mail-pg0-f67.google.com with SMTP id e9so2145428pgc.1; Wed, 23 Nov 2016 16:48:14 -0800 (PST) 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=N/zQjc2hZKlGzDhpzxB9b6raYF44TRuQmOcZRqeIRDA=; b=KB6BSYlGhmhwPCCBanop0KWpp68aBJZYdrT4zT68WJX5Qk8DPC03lde0I8S0CAV/uE h5RQbXwGRLOlUfPzDrRTeiuGtzoUFn5m7KWjh4+ciTPQDq57l1XNQOrLpx+5H4+UVx02 gBFh5/8g3WpHU7H+CfzOVCQs8riXagr/OPk2apHFjKo322AnRoIWjLmfJtoK3Jw+lx2s eM2OG+Dks5UCdMl15uiZchM6opRQA3chi0rEGCZIsdfbvT10v1Ng3yis4ps+YOvhYF4a VEjfDqAjPvJfwqHT6s9OKRW8ua0kPORpHDOdKzlBNQmBDL+bf/RhHDKgAUfC5bPP8Um1 I0jA== 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=N/zQjc2hZKlGzDhpzxB9b6raYF44TRuQmOcZRqeIRDA=; b=Fuok8PI5NvIODmjkl3KJJPJjEtku2Mbki9GLeve+PTc8K7OfbSZ6hzNNshApg+bieG 9C5R2rr268f2PS001PrPYeyY9dHdXfE2NuqCrP4hnnzRwGWkHI93Sp1oaJTKqXjwxXS7 kzcF+2NgsJ5VxHWLx0RwrJ9LSDMVmwoaJf9glTMKocweoC0sb4cttMuksc3T5KqPjkHj /M43IpYf0dX67FhltdwcN53S0eiRHrbYc3rkMK1Q8oJZVa3Ln3H0KkBnBIUQ5ci1drjT SWsemqj1Q5TvEoJO8MIfLSQkv1ooD/d5zXNrfNKSYA74uYsPrrwtKjtgz4oNlm8KZkoj j2UA== X-Gm-Message-State: AKaTC03VmlOzFxZxYnThtKxQNRRq9ix/iTJ/3BtS0uMnGwMdCrVwweFDZzReTPSZhlo+3A== X-Received: by 10.84.137.169 with SMTP id 38mr12523448pln.128.1479948493637; Wed, 23 Nov 2016 16:48:13 -0800 (PST) Received: from localhost.localdomain (c-24-6-102-171.hsd1.ca.comcast.net. [24.6.102.171]) by smtp.gmail.com with ESMTPSA id i11sm37364702pgn.17.2016.11.23.16.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Nov 2016 16:48:13 -0800 (PST) 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, 23 Nov 2016 16:47:50 -0800 Message-Id: <1479948470-2397-7-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479948470-2397-1-git-send-email-deepa.kernel@gmail.com> References: <1479948470-2397-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..4378378 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_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; } /*