From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753588AbdK0Tbx (ORCPT ); Mon, 27 Nov 2017 14:31:53 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:41460 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753521AbdK0Tbt (ORCPT ); Mon, 27 Nov 2017 14:31:49 -0500 X-Google-Smtp-Source: AGs4zMYaKQI+bglApnuQB11E5tEPfD1EdqaNBGWfOUHEoznr3ber1p5dSu/624/iBaANSYajX+AICg== From: Deepa Dinamani To: tglx@linutronix.de, john.stultz@linaro.org Cc: linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v2 03/10] compat: enable compat_get/put_timespec64 always Date: Mon, 27 Nov 2017 11:30:30 -0800 Message-Id: <20171127193037.8711-4-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171127193037.8711-1-deepa.kernel@gmail.com> References: <20171127193037.8711-1-deepa.kernel@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These functions are used in the repurposed compat syscalls to provide backward compatibility for using 32 bit time_t on 32 bit systems. Signed-off-by: Deepa Dinamani --- include/linux/compat.h | 2 - include/linux/compat_time.h | 4 ++ kernel/Makefile | 2 +- kernel/compat.c | 92 +++++++++++++++++++++++---------------------- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/include/linux/compat.h b/include/linux/compat.h index 2f79dac5ed65..e06f11886000 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -168,8 +168,6 @@ 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 *); extern int get_compat_itimerspec64(struct itimerspec64 *its, const struct compat_itimerspec __user *uits); extern int put_compat_itimerspec64(const struct itimerspec64 *its, diff --git a/include/linux/compat_time.h b/include/linux/compat_time.h index 56a54a1e4355..31f2774f1994 100644 --- a/include/linux/compat_time.h +++ b/include/linux/compat_time.h @@ -3,6 +3,7 @@ #define _LINUX_COMPAT_TIME_H #include +#include typedef s32 compat_time_t; @@ -16,4 +17,7 @@ struct compat_timeval { s32 tv_usec; }; +extern int compat_get_timespec64(struct timespec64 *, const void __user *); +extern int compat_put_timespec64(const struct timespec64 *, void __user *); + #endif /* _LINUX_COMPAT_TIME_H */ diff --git a/kernel/Makefile b/kernel/Makefile index 172d151d429c..2e3df3deee18 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -66,7 +66,7 @@ obj-$(CONFIG_KEXEC_CORE) += kexec_core.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o -obj-$(CONFIG_COMPAT) += compat.o +obj-y += compat.o obj-$(CONFIG_CGROUPS) += cgroup/ obj-$(CONFIG_UTS_NS) += utsname.o obj-$(CONFIG_USER_NS) += user_namespace.o diff --git a/kernel/compat.c b/kernel/compat.c index d1cee656a7ed..42653ac977c0 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -30,6 +30,52 @@ #include +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); + +#ifdef CONFIG_COMPAT + int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp) { struct compat_timex tx32; @@ -120,50 +166,6 @@ 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) @@ -582,3 +584,5 @@ void __user *compat_alloc_user_space(unsigned long len) return ptr; } EXPORT_SYMBOL_GPL(compat_alloc_user_space); + +#endif -- 2.14.1