From patchwork Fri Jul 28 18:52:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9869257 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 CC66D60382 for ; Fri, 28 Jul 2017 18:53:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F690288D2 for ; Fri, 28 Jul 2017 18:53:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94427288E6; Fri, 28 Jul 2017 18:53:12 +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 3A6C2288D2 for ; Fri, 28 Jul 2017 18:53:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741AbdG1Sw7 (ORCPT ); Fri, 28 Jul 2017 14:52:59 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35990 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752734AbdG1Sw5 (ORCPT ); Fri, 28 Jul 2017 14:52:57 -0400 Received: by mail-pf0-f194.google.com with SMTP id r63so298476pfb.3; Fri, 28 Jul 2017 11:52:57 -0700 (PDT) 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=h6sZLjMD7iW8n8aJq+yfXgjd4Fk5BR3A3SE01Sr53FA=; b=ddRNgYL+7As+rBnuwIdtu//JKomDLJQ/2tlsZXvfMSgTlNZlm96jXqkm7UxwBeldYK yPwCS6KUFw5gSJDqJXOerTvNZn9whchXmZbguiyKRnIYarCHHmfYxdopqJgiT/kRBTZ9 lmKEG8mGQonOYnrUij8ooFJkXwz8N5PIj9zKscqeyTWXehGu7bOk1r8qIy0s9rRj9Y+B iQqBfJBx5Z0K/iCSCdg0Ip/v1NWjPaYG4OCaNaTzBB7Wb13AY8pbItWN84IqpFJxBS3B 8DgJyNBcBmky6+IBO55yQjnOQKbYvdo/3uVzNeB5BlfgHSvMojIujpw/AnW/ICrdUugB E7rg== 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=h6sZLjMD7iW8n8aJq+yfXgjd4Fk5BR3A3SE01Sr53FA=; b=cty75J6Q1qppWoWdQ4oV/DmWqj25JWyMg+AvvPtuYEr1b9lqJItmrUiOCG1wjsrXDY TlhYdUQogHAwnObl7uxL4yGlNedeTCdp8amd6/31PJzUAZ/2DuzFBD0IQ5Y3U4TxPluM RBeFiLasnNPNRJPNtbOx4RIFh4gIywn7T0wsS4WBBZoWrG8YAlRfXqJWv1OeW4ObmbB4 mprQ5V4uxsYowWkaT/wsGCbVdLggdmMDuMvic4fujBWk+UjbQVt66Ojqh49g4p4iN7so owjp5zebCsaqS0f/dTlXvLZlYeOedlHi5xVgB60aHyKclcBzIX4GqMeVnGq2Ebjy4NpP OOjA== X-Gm-Message-State: AIVw112vhL7mMDSxnuxazDtGlAoCwm4xNWbnS7iPb+N39Vn+UOkrKSZ2 prctG7coUlmeSA== X-Received: by 10.98.68.76 with SMTP id r73mr8315800pfa.152.1501267977176; Fri, 28 Jul 2017 11:52:57 -0700 (PDT) Received: from localhost.localdomain ([2601:647:5000:6620:39fd:1b9c:c45:e526]) by smtp.gmail.com with ESMTPSA id x5sm38485095pgq.18.2017.07.28.11.52.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jul 2017 11:52:56 -0700 (PDT) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [RESEND PATCH 6/6] utimes: Make utimes y2038 safe Date: Fri, 28 Jul 2017 11:52:07 -0700 Message-Id: <20170728185207.12480-7-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170728185207.12480-1-deepa.kernel@gmail.com> References: <20170728185207.12480-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 struct timespec is not y2038 safe on 32 bit machines. Replace timespec with y2038 safe struct timespec64. Note that the patch only changes the internals without modifying the syscall interfaces. This will be part of a separate series. Signed-off-by: Deepa Dinamani --- fs/utimes.c | 23 ++++++++++++----------- include/linux/time.h | 2 +- init/initramfs.c | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/utimes.c b/fs/utimes.c index 6571d8c848a0..51edb9f9507c 100644 --- a/fs/utimes.c +++ b/fs/utimes.c @@ -22,7 +22,7 @@ */ SYSCALL_DEFINE2(utime, char __user *, filename, struct utimbuf __user *, times) { - struct timespec tv[2]; + struct timespec64 tv[2]; if (times) { if (get_user(tv[0].tv_sec, ×->actime) || @@ -44,7 +44,7 @@ static bool nsec_valid(long nsec) return nsec >= 0 && nsec <= 999999999; } -static int utimes_common(const struct path *path, struct timespec *times) +static int utimes_common(const struct path *path, struct timespec64 *times) { int error; struct iattr newattrs; @@ -115,7 +115,7 @@ static int utimes_common(const struct path *path, struct timespec *times) * must be owner or have write permission. * Else, update from *times, must be owner or super user. */ -long do_utimes(int dfd, const char __user *filename, struct timespec *times, +long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, int flags) { int error = -EINVAL; @@ -167,10 +167,11 @@ long do_utimes(int dfd, const char __user *filename, struct timespec *times, SYSCALL_DEFINE4(utimensat, int, dfd, const char __user *, filename, struct timespec __user *, utimes, int, flags) { - struct timespec tstimes[2]; + struct timespec64 tstimes[2]; if (utimes) { - if (copy_from_user(&tstimes, utimes, sizeof(tstimes))) + if ((get_timespec64(&tstimes[0], &utimes[0]) || + get_timespec64(&tstimes[1], &utimes[1]))) return -EFAULT; /* Nothing to do, we must not even check the path. */ @@ -186,7 +187,7 @@ SYSCALL_DEFINE3(futimesat, int, dfd, const char __user *, filename, struct timeval __user *, utimes) { struct timeval times[2]; - struct timespec tstimes[2]; + struct timespec64 tstimes[2]; if (utimes) { if (copy_from_user(×, utimes, sizeof(times))) @@ -224,7 +225,7 @@ SYSCALL_DEFINE2(utimes, char __user *, filename, COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, struct compat_utimbuf __user *, t) { - struct timespec tv[2]; + struct timespec64 tv[2]; if (t) { if (get_user(tv[0].tv_sec, &t->actime) || @@ -238,11 +239,11 @@ COMPAT_SYSCALL_DEFINE2(utime, const char __user *, filename, COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filename, struct compat_timespec __user *, t, int, flags) { - struct timespec tv[2]; + struct timespec64 tv[2]; if (t) { - if (compat_get_timespec(&tv[0], &t[0]) || - compat_get_timespec(&tv[1], &t[1])) + if (compat_get_timespec64(&tv[0], &t[0]) || + compat_get_timespec64(&tv[1], &t[1])) return -EFAULT; if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT) @@ -253,7 +254,7 @@ COMPAT_SYSCALL_DEFINE4(utimensat, unsigned int, dfd, const char __user *, filena COMPAT_SYSCALL_DEFINE3(futimesat, unsigned int, dfd, const char __user *, filename, struct compat_timeval __user *, t) { - struct timespec tv[2]; + struct timespec64 tv[2]; if (t) { if (get_user(tv[0].tv_sec, &t[0].tv_sec) || diff --git a/include/linux/time.h b/include/linux/time.h index 4abb32d4c6b8..3d0cd017f0d7 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -178,7 +178,7 @@ extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue); extern int do_getitimer(int which, struct itimerval *value); -extern long do_utimes(int dfd, const char __user *filename, struct timespec *times, int flags); +extern long do_utimes(int dfd, const char __user *filename, struct timespec64 *times, int flags); /* * Similar to the struct tm in userspace , but it needs to be here so diff --git a/init/initramfs.c b/init/initramfs.c index 8a532050043f..e64bf7b4c1ca 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -110,7 +110,7 @@ static void __init free_hash(void) static long __init do_utime(char *filename, time_t mtime) { - struct timespec t[2]; + struct timespec64 t[2]; t[0].tv_sec = mtime; t[0].tv_nsec = 0;