From patchwork Sat Feb 18 23:30:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9581399 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 4B5756049F for ; Sat, 18 Feb 2017 23:32:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 428E0287B9 for ; Sat, 18 Feb 2017 23:32:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3754D287BC; Sat, 18 Feb 2017 23:32:31 +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 E3D86287B9 for ; Sat, 18 Feb 2017 23:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbdBRXbg (ORCPT ); Sat, 18 Feb 2017 18:31:36 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35404 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750827AbdBRXbJ (ORCPT ); Sat, 18 Feb 2017 18:31:09 -0500 Received: by mail-pf0-f194.google.com with SMTP id 68so6862407pfx.2; Sat, 18 Feb 2017 15:30:47 -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=YZ4R2cgJ6CdxxxHBO1Qw1pG/LS/Yp+6G0IRTHWg/B2Vwb+GNRkzFnE3RdKamREBCBv ZVmPxL3DxgI6sc/rIJB1AuJg8TqijTXH+InjGgQCml3ojf48BeGM69F5E2OFWLhiizfc 6rK8+P8cv0xp5N/IB/5nxNKXphxloSyuA2LuVmqUO9bygsPUzdAmq7BQAbHZrakVFp3y 2Usmj+MQiJ0fgyCucONTALNB0ARcjvJS0Y5rgLY+8SU2XiUqMIP+EuKpYfzEb+gS4ANe sdM68by+Wlw3Unj1Wt4y1oFLnk151NThANQGQmwxJ/l6Fb6Kb1nPEzewk/qO0q9tNxk6 bFEw== 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=HaNr0yG5r3t++aUh3G8BhAInaLDONDnMz/Dqm5eI+U/GmGPXgGvZcVL016ZR/T/2ow xrFHOlm6oca97Q7jrSz+FvzqEXjIKeLS8nVi8SUdkONoyPuAENp76BX5SGVgXUHI9AC5 1857vqLvsDzUJduWLoN1jiRNhFcHrf6oVpvJD913q81uoLDPffO2FnqxjSrxcJYAwKXn sEF8FFb5dNBOq8p55QC//dv+ojtL20IM6gPSQo6e7j9neOgQLkYBFjFaftS3eLtBHiEL oupQm3ET6cBnhsZ8+i/wgcNvYRgB/nCsO6Jec3WL6HreYbke6PIgN0tPtQQ5K6pO4pMJ wnqA== X-Gm-Message-State: AMke39kzxitKzBAiZY/VxTKxS0JVRLDEO5O0ViSmCQDM6m7Wb6wi3jfyhye+0A09vQygFw== X-Received: by 10.99.168.2 with SMTP id o2mr18335181pgf.159.1487460646520; Sat, 18 Feb 2017 15:30:46 -0800 (PST) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:e8a1:d9de:f814:c176]) by smtp.gmail.com with ESMTPSA id s24sm27278030pgo.25.2017.02.18.15.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Feb 2017 15:30:46 -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 v3 5/5] utimes: Clamp the timestamps before update Date: Sat, 18 Feb 2017 15:30:08 -0800 Message-Id: <1487460608-15697-6-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487460608-15697-1-git-send-email-deepa.kernel@gmail.com> References: <1487460608-15697-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; } /*