From patchwork Mon Jan 22 02:04:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 10177195 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 CB0DA601D5 for ; Mon, 22 Jan 2018 02:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B956328390 for ; Mon, 22 Jan 2018 02:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADFB228399; Mon, 22 Jan 2018 02: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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 6415B28390 for ; Mon, 22 Jan 2018 02:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751296AbeAVCFf (ORCPT ); Sun, 21 Jan 2018 21:05:35 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38032 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751069AbeAVCFb (ORCPT ); Sun, 21 Jan 2018 21:05:31 -0500 Received: by mail-pf0-f195.google.com with SMTP id k19so5919170pfj.5; Sun, 21 Jan 2018 18:05:31 -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=fDhRECMcNsvujjmxvp2XlvDKoTYS4VHgBf8JF6zt7wU=; b=aW3DFcACT3maGhsmYvOH3TAKCFs97XvPgecgBLVyzecZaFHgR/RadK6Wqi6r5sQt+v w6uyUw397aAUnd67/iSiHmFhchTEmfBId8a44BgTl9Rl9baoHI7tBxpA8GcQsI2c6z1Y YxCB7TNbLhYOCyBMxGeN/K3LUUuI3Z26C0RhmSzpvl9xyn8iuQLh3y1XA+HMgV42fnkG h13lbjGIXzm8DcqeGoaz2bYMj/7f08/bewMneNy3bY4ZVcaRh9GkEIKzuA3EAPHWY1vf hAsVuydpzEstzUrgCUWdvNlIfWg2mlzvKbvGT6+PoJeTpXbYYymMmP4BlGCETI7LjRNK uGeg== 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=fDhRECMcNsvujjmxvp2XlvDKoTYS4VHgBf8JF6zt7wU=; b=q8VzCoIut51S1BTMMs9F7ubi/eZpaDmbOGe7g/wHSQBybQosAnd+/08AoKeOZ9IUZ2 HMeY+QrCVnSmBjufsbEuqKgZtAFB6DsO6aLvgfonHlYc/RQFdaxJVbL57hwAXcI8rdmq VK8cQ1j92rAXdG+GoTLLmJpQd9i647olad2KvENBLINVn2H0i5Q0t06JJ+ift0SjjaTN d+h9RoL8CiSDHYjfJbPmFnHPpQtW7zWu2ygmvXyX3X+T3w8Cut7cyib/xw3TG/2daedn UnJXiCx/IjfWSrDrAIlPIB6yHcWkkaXPkMpku/AmckVeHY/XpmhdeMlCdxIeh9fryh0b Y2vw== X-Gm-Message-State: AKwxytdBewKMEIgQX0V+xT9NQgkOxZWZSkPbb+vLFemuRo30fW3jHcEp md8E+tCWoWLtbRWQoj/PUgM= X-Google-Smtp-Source: AH8x226xxnObq0wgC7T67pgYCBbzFNaYAm9oTvQPldmfvKL+ZbB/dPjSPAvDwvKn8ufyQ5IFmOM18Q== X-Received: by 10.98.103.83 with SMTP id b80mr6747721pfc.223.1516586731175; Sun, 21 Jan 2018 18:05:31 -0800 (PST) Received: from deepa-ubuntu.lan (c-67-170-212-194.hsd1.ca.comcast.net. [67.170.212.194]) by smtp.gmail.com with ESMTPSA id y79sm27168472pfb.177.2018.01.21.18.05.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:30 -0800 (PST) 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, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 4/4] utimes: Clamp the timestamps before update Date: Sun, 21 Jan 2018 18:04:26 -0800 Message-Id: <20180122020426.2988-5-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-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 e4b3d7c2c9f5..82fdcc3284b9 100644 --- a/fs/utimes.c +++ b/fs/utimes.c @@ -50,6 +50,7 @@ static int utimes_common(const struct path *path, struct timespec64 *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); @@ -65,16 +66,24 @@ static int utimes_common(const struct path *path, struct timespec64 *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; } /*