From patchwork Mon Jun 19 06:45: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: 9795249 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 294C06020B for ; Mon, 19 Jun 2017 06:46:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A3520572 for ; Mon, 19 Jun 2017 06:46:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 051E125EA6; Mon, 19 Jun 2017 06:46:01 +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=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 79F0A20572 for ; Mon, 19 Jun 2017 06:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753751AbdFSGp4 (ORCPT ); Mon, 19 Jun 2017 02:45:56 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34995 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751438AbdFSGpx (ORCPT ); Mon, 19 Jun 2017 02:45:53 -0400 Received: by mail-pg0-f67.google.com with SMTP id f127so14284525pgc.2; Sun, 18 Jun 2017 23:45:47 -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=AgIOHphjkrsVW8hVX6wMGAAdrbb/bV/Da7W5jKml9So=; b=GVDl5/Sp25bye3rv4baY7NmO0Rg3YTRhDDCeULONqqXS0a7WtFPRZJRtM+fdZ7eDBs MArH1EalxeaDr8wB0z5oZKumRQ7KdFaL1w9N58aV9J2MoOyMMIZCshZ5BxRNpFSMqF2g BsHkThJZg4Iy22xFb63oi+4utdBNYHHgW0FcdAED/V/UnOyBxE8XzgOOj0TgiempYEUr gFtvI3DFWBPpJyYyRjgXjstAWCtaxviqyciNGfalxOo2vXyvKVSFJaV+BAW3ENK+1Rr7 5PzSjvFBDFBKI8MSTpScYotIhQah/MCG29VSDug0hj9I0XrV13o+AAlAa3laLuXKs/kr hr9Q== 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=AgIOHphjkrsVW8hVX6wMGAAdrbb/bV/Da7W5jKml9So=; b=huodUY4fiQCrRJNZ1MzYxWV4Qtz0XL7Ocq5owhcibwIlrHUFpWofCgjrBG+rjS8sew W8p2PL9G9zB6pelyGoxfS+zNwUyc5DQbqdYx/oHMjrzRQmPaoWbBH+adJZ4xpGxY+xcO MCZIhscxDageaK3UaAfknZjE7bPR5745tKHF35VMym5xUTvAioxGsDybLJsx+vuSaBuF uL2ikoUEWqy8gjKycNnVtLYVTv8PyKrh7EiXrQyXN7OnwqJ0xJi4S7X1fd/0eDLSM7A1 AFRcOnYEOHMlhNz4UZ5j66zge7LgNpRLN+fRM4MXmvYX4pqF5UXj4oihXuu7EWqrBXSI Avng== X-Gm-Message-State: AKS2vOyOFZnjEIVh1F0QK/F96kYw3HrjjXYy60KEWll3m9MscG5KgUOB piyTzuV+ZTsRpA== X-Received: by 10.98.138.143 with SMTP id o15mr23479885pfk.125.1497854742407; Sun, 18 Jun 2017 23:45:42 -0700 (PDT) Received: from localhost.localdomain ([2601:647:5000:6620:ecf7:aabb:b31b:424d]) by smtp.gmail.com with ESMTPSA id o66sm19620318pga.64.2017.06.18.23.45.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 23:45:41 -0700 (PDT) From: Deepa Dinamani To: tglx@linutronix.de, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Cc: john.stultz@linaro.org, nicolas.pitre@linaro.org, arnd@arndb.de, y2038@lists.linaro.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/8] time: add get_timespec64 and put_timespec64 Date: Sun, 18 Jun 2017 23:45:08 -0700 Message-Id: <20170619064515.922-2-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170619064515.922-1-deepa.kernel@gmail.com> References: <20170619064515.922-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 Add helper functions to convert between struct timespec64 and struct timespec at userspace boundaries. This is a preparatory patch to use timespec64 as the basic type internally in the kernel as timespec is not y2038 safe on 32 bit systems. The patch helps the cause by containing all data conversions at the userspace boundaries within these functions. Suggested-by: Arnd Bergmann Signed-off-by: Deepa Dinamani --- include/linux/compat.h | 2 ++ include/linux/time.h | 5 +++++ kernel/compat.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ kernel/time/time.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/include/linux/compat.h b/include/linux/compat.h index 1c5f3152cbb5..72be68953411 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -156,6 +156,8 @@ extern int compat_get_timespec(struct timespec *, const void __user *); extern int compat_put_timespec(const struct timespec *, void __user *); extern int compat_get_timeval(struct timeval *, const void __user *); extern int compat_put_timeval(const struct timeval *, void __user *); +extern int compat_get_timespec64(struct timespec64 *, const void __user *); +extern int compat_put_timespec64(const struct timespec64 *, void __user *); /* * This function convert a timespec if necessary and returns a *user diff --git a/include/linux/time.h b/include/linux/time.h index c0543f5f25de..36afb579495f 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -8,6 +8,11 @@ extern struct timezone sys_tz; +int get_timespec64(struct timespec64 *ts, + const struct timespec __user *uts); +int put_timespec64(const struct timespec64 *ts, + struct timespec __user *uts); + #define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) static inline int timespec_equal(const struct timespec *a, diff --git a/kernel/compat.c b/kernel/compat.c index 933bcb31ae10..c7a01a01222d 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -154,6 +154,50 @@ static int __compat_put_timespec(const struct timespec *ts, struct compat_timesp __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; } +static int __compat_get_timespec64(struct timespec64 *ts64, + const struct compat_timespec __user *cts) +{ + struct compat_timespec ts; + int ret; + + ret = copy_from_user(&ts, cts, sizeof(ts)); + if (ret) + return -EFAULT; + + ts64->tv_sec = ts.tv_sec; + ts64->tv_nsec = ts.tv_nsec; + + return 0; +} + +static int __compat_put_timespec64(const struct timespec64 *ts64, + struct compat_timespec __user *cts) +{ + struct compat_timespec ts = { + .tv_sec = ts64->tv_sec, + .tv_nsec = ts64->tv_nsec + }; + return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0; +} + +int compat_get_timespec64(struct timespec64 *ts, const void __user *uts) +{ + if (COMPAT_USE_64BIT_TIME) + return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0; + else + return __compat_get_timespec64(ts, uts); +} +EXPORT_SYMBOL_GPL(compat_get_timespec64); + +int compat_put_timespec64(const struct timespec64 *ts, void __user *uts) +{ + if (COMPAT_USE_64BIT_TIME) + return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0; + else + return __compat_put_timespec64(ts, uts); +} +EXPORT_SYMBOL_GPL(compat_put_timespec64); + int compat_get_timeval(struct timeval *tv, const void __user *utv) { if (COMPAT_USE_64BIT_TIME) diff --git a/kernel/time/time.c b/kernel/time/time.c index 49c73c6ed648..fdd55c7681ec 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -786,3 +786,31 @@ struct timespec64 timespec64_add_safe(const struct timespec64 lhs, return res; } + +int get_timespec64(struct timespec64 *ts, + const struct timespec __user *uts) +{ + struct timespec kts; + int ret; + + ret = copy_from_user(&kts, uts, sizeof(kts)); + if (ret) + return -EFAULT; + + ts->tv_sec = kts.tv_sec; + ts->tv_nsec = kts.tv_nsec; + + return 0; +} +EXPORT_SYMBOL_GPL(get_timespec64); + +int put_timespec64(const struct timespec64 *ts, + struct timespec __user *uts) +{ + struct timespec kts = { + .tv_sec = ts->tv_sec, + .tv_nsec = ts->tv_nsec + }; + return copy_to_user(uts, &kts, sizeof(kts)) ? -EFAULT : 0; +} +EXPORT_SYMBOL_GPL(put_timespec64);