From patchwork Wed Apr 25 16:03:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 134362 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1052206lji; Wed, 25 Apr 2018 09:06:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+HZDrZSRZt2wx+iV9JostBcM2cMc99LyRe9+T8Xms392ZBTj3/kYXBvJLoL5zLCyubQDm7 X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr29940196plc.248.1524672369275; Wed, 25 Apr 2018 09:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524672369; cv=none; d=google.com; s=arc-20160816; b=mxI8WMXqLGu6fAYAzJoyNSDxkRIz64D9TXAkMpHraSxF5OscJf0BYssQS1Tinnm/8U i6BrTuxRmr4YogJKcPILoN7FjXuqR9KmGcYzMRDcD8mxtothO6gog6kNUfM4iuiHhCWu 6XWCuHU7V+6fRl20Qqilb4VfokphDovZFCTal9DLTn/i+7PNV8lCFQpKhW+5V0SbNge0 ZxGe9DxkrxWD0vTbc8mbVxsu8T/RX2f3KV/AdpxCWPaXhTE2WSaVl5QSVWM6gccut/zV VrxJCk1J2MkUPh4Q36vPGa1OFy/9hkWry2Q74vC1CV2BNozcArD8613T6PTxGCUz9BU3 608g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=k6BKIDGNr4aRSihwjW8CDckp/YYb/FOq2x3qRhPOJUU=; b=JpY75DB4hPr/wTnIr/u51FrxPPBbgr8b3M1a+MWWHZxbxhYu0DXo5/MOnOifiH2AbW qYb8q81HJhG31si9kQihJSBBqDaRREvJ5R7yv7vmYSkoOfdN6jnbBtHJlHspDuniCPcu d7urc3R3fVzcM9rh1FERrwjPDWwX5djBB7CgmYrzBZTZphSmm6rSeKmkpOPt2lau1hka Mb4n4p82baOB0N7Af627ARmtoQZ9GDr+JYmqu6qs83ZJoe6zkbgu8oInXG46cpAgC9qd J467IoLZeQeA+lIOjJCFYdFJZivLlnh2be2ylZw9HCL/eIYuy4XkX0Xa+RtSL/nQNBdC StAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z187si9171792pgd.646.2018.04.25.09.06.04; Wed, 25 Apr 2018 09:06:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932195AbeDYQFk (ORCPT + 29 others); Wed, 25 Apr 2018 12:05:40 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:35143 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932078AbeDYQFe (ORCPT ); Wed, 25 Apr 2018 12:05:34 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MQNoq-1eoJAi2ILU-00TkiG; Wed, 25 Apr 2018 18:03:36 +0200 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Arnd Bergmann , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, libc-alpha@sourceware.org, tglx@linutronix.de, netdev@vger.kernel.org, deepa.kernel@gmail.com, viro@zeniv.linux.org.uk, albert.aribaud@3adev.fr, Peter Zijlstra , Darren Hart , "Eric W. Biederman" , Dominik Brodowski Subject: [PATCH 10/17] y2038: futex: Add support for __kernel_timespec Date: Wed, 25 Apr 2018 18:03:04 +0200 Message-Id: <20180425160311.2718314-11-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180425160311.2718314-1-arnd@arndb.de> References: <20180425160311.2718314-1-arnd@arndb.de> X-Provags-ID: V03:K1:R+roZ20fps50o8bhsoif6KUk5c477hWheUOOag1vwJQdx4bczbN QfoGM98CTTlwDtNDkOVTpy9x7hipDga2Z2modAfJNO+sp9UQE12ChlKBhOWakNTbQeebGVb +i9ONbOAZiyXkLceKX56at7KkSGrGQM6M8UhohZejnRQcjjPnaKFP9ipHESkBuQYjuvatfo EZimJGfab/3bHGhZukeZw== X-UI-Out-Filterresults: notjunk:1; V01:K0:SUiMPOKmfI4=:3TDfbWFT8Wz6ivM86zMSPl nxR4bHy+me6XFt7hAkwwVHgBqen9LzU2HvTQlpkwrsELgFOHafxg8a3X9BWme7AhoOzPIdZiu CK/bfMKIwKusVy6U2blk+zpa4kWBgPe/DQ0hR99e0uRdNMhlz2QXV0R3egzBgSqn6afaXHfaB XI508Eog+6/4ccqONNBgPmWxlCtFcs/5VodCGWxVlcXLCfzGqczzbySnHmh06BGKFoPe1kPom 74/3LwC8tElpLiKBRsnIXeepQy0myvdcYNL1g1yu/TCA3jBstQ6KY+mapGzDaon/NmFuboFhC 2iAvSfK7sbWeAdTuI7oy458utB1lFhza2OCF5vk7NUqrqsCn+A7mSd1vurnwq5YS2kB6Rkwlt x8BL/bVQbUZPEdq63Gap4fT16a03foTqVBjAKBZrDCWcoq1Pndb+/GjmJX5CX8HsvhdPrKL14 lgMX2l2mL360WdNHrBHlamwxbzkefJAEIe+Mxy6U6kgBWqWIGGFQOD3SRsDTq+FGsbX/tJoxa ljD7EFNvyuCGl9Tmq08SChld/Cdg0KDRWNoAB43eAaW+LW1w/1ziattqg9DCOyUprcIqlcVsj aS4RAgOp+eAyfw8v5cCkEAbu/d45MLBcCtno/e/rtA0bcCktNSLgmppUn9jOzCIH5ocBy+Pqb 9tQK7yKpg0jUR8drLG9wg7eDduAG6s2xp3bEHc7qLgysZrnfHMkFrMqc/QLInx6lILhk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This prepares sys_futex for y2038 safe calling: the native syscall is changed to receive a __kernel_timespec argument, which will be switched to 64-bit time_t in the future. All the internal time handling gets changed to timespec64, and the compat_sys_futex entry point is moved under the CONFIG_COMPAT_32BIT_TIME check to provide compatibility for existing 32-bit architectures. Signed-off-by: Arnd Bergmann --- include/linux/syscalls.h | 2 +- kernel/futex.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) -- 2.9.0 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index d2b19e814218..c3d504dbba9c 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -528,7 +528,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags); /* kernel/futex.c */ asmlinkage long sys_futex(u32 __user *uaddr, int op, u32 val, - struct timespec __user *utime, u32 __user *uaddr2, + struct __kernel_timespec __user *utime, u32 __user *uaddr2, u32 val3); asmlinkage long sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr, diff --git a/kernel/futex.c b/kernel/futex.c index e9013d1e65a1..129555a3b64d 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -3556,10 +3556,10 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, - struct timespec __user *, utime, u32 __user *, uaddr2, + struct __kernel_timespec __user *, utime, u32 __user *, uaddr2, u32, val3) { - struct timespec ts; + struct timespec64 ts; ktime_t t, *tp = NULL; u32 val2 = 0; int cmd = op & FUTEX_CMD_MASK; @@ -3569,12 +3569,12 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, cmd == FUTEX_WAIT_REQUEUE_PI)) { if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG)))) return -EFAULT; - if (copy_from_user(&ts, utime, sizeof(ts)) != 0) + if (get_timespec64(&ts, utime)) return -EFAULT; - if (!timespec_valid(&ts)) + if (!timespec64_valid(&ts)) return -EINVAL; - t = timespec_to_ktime(ts); + t = timespec64_to_ktime(ts); if (cmd == FUTEX_WAIT) t = ktime_add_safe(ktime_get(), t); tp = &t; @@ -3745,12 +3745,14 @@ COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid, return ret; } +#endif /* CONFIG_COMPAT */ +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, struct compat_timespec __user *, utime, u32 __user *, uaddr2, u32, val3) { - struct timespec ts; + struct timespec64 ts; ktime_t t, *tp = NULL; int val2 = 0; int cmd = op & FUTEX_CMD_MASK; @@ -3758,12 +3760,12 @@ COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI || cmd == FUTEX_WAIT_BITSET || cmd == FUTEX_WAIT_REQUEUE_PI)) { - if (compat_get_timespec(&ts, utime)) + if (compat_get_timespec64(&ts, utime)) return -EFAULT; - if (!timespec_valid(&ts)) + if (!timespec64_valid(&ts)) return -EINVAL; - t = timespec_to_ktime(ts); + t = timespec64_to_ktime(ts); if (cmd == FUTEX_WAIT) t = ktime_add_safe(ktime_get(), t); tp = &t; @@ -3774,7 +3776,7 @@ COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); } -#endif /* CONFIG_COMPAT */ +#endif /* CONFIG_COMPAT_32BIT_TIME */ static void __init futex_detect_cmpxchg(void) {