From patchwork Fri Dec 7 21:18: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: 153215 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp982080ljp; Fri, 7 Dec 2018 13:18:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWLEp4pVTP/wKwMOHkH74E/jWQfWfUv6x0ILJPhBpQgV8RnvRn6uQ9Ua6mjjJ64TZbEY+l X-Received: by 2002:a17:902:2862:: with SMTP id e89mr3697518plb.158.1544217520982; Fri, 07 Dec 2018 13:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544217520; cv=none; d=google.com; s=arc-20160816; b=JTo2o55ItgSwhhfzf79N7gXPSd/9kDi98dyT2m0XoUEGV6bQ7zrcgZnWo6wvsdrvmk Ir29veZ9Gqqu6x4KuJAmSNHWREP6MQAtSQuQrAAcLUTNEGJ/DQqhu0P4uA1k7Sna3YRT r8VJapb3orAF9WSauBR3dz48s5ZxcawN9eGCbcObHvM9TKhdA5/heAZdjo1W8j1HJXH1 2DIhXyuDGX7/a7QTXLgAvAtE3CEgU3M0uKoSjxIBsWcUSIiYDdgUBwqY27TDXD13abwW kvU2iHORPCi2YRCbmgBlCe6ddtKkMLjJT2FpYpNzff9g32mOslGuNGNZzJVZ1uiwpu6T TP+Q== 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; bh=Yskc8CimzkLWSHK0I2AvTq9v4OpR7z7/pvc2TCvWL88=; b=m/Ww4S1hbxt04CZ11og+lipSMlMZ0sk0JZEtr2x3ZNA5AKoz21UKJpp4d7Qj/PdIs7 3GRn09qzyY7gEyG3TwJlpLugW0oODWPJb1wTny6k3giB7KgPYzVk+oSH4Sos/Lu73LbS GabZeH4NDRsfyqfC5T11JehoD9t8y/ZD07m/U0YUY3+rPRcZ4DUz6omSfFm4gk5YEAWt +I1S/+oY9YM0mtf1wS9O5ckpT51xfXyTfpCPZ4JNTF+QzgQI2dSYumGkDnwHVDXjVKi9 0IPC7oUVjcVV6XZdlOBEQ6KAe1AshDU0iSllqdOg6/nPw0vWLoLyhG9xJOyuCZYyTVgE iTQw== 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 n18si4080282pfj.30.2018.12.07.13.18.40; Fri, 07 Dec 2018 13:18:40 -0800 (PST) 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 S1726270AbeLGVSh (ORCPT + 31 others); Fri, 7 Dec 2018 16:18:37 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:39695 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbeLGVSV (ORCPT ); Fri, 7 Dec 2018 16:18:21 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1MsYzD-1hJUzZ40SZ-00tzHj; Fri, 07 Dec 2018 22:18:11 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, Deepa Dinamani , John Stultz , Thomas Gleixner , linux-api@vger.kernel.org, Arnd Bergmann Subject: [PATCH 1/5] y2038: futex: Move compat implementation into futex.c Date: Fri, 7 Dec 2018 22:18:04 +0100 Message-Id: <20181207211808.328719-2-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207211808.328719-1-arnd@arndb.de> References: <20181207211808.328719-1-arnd@arndb.de> X-Provags-ID: V03:K1:l9X29fKB2TzHub3lxGs6a6uk9ozAb5My4ZxqYnF1Wc8SxZnpKWj qCPttoMkrI6PYxQfivJGEtlD5PATMocHuLGe21OI/FhI2DzJN06RHUDwGHjMTKwDbmnFHH4 kZtm2gtAePbb8r9LiVJP1jsTKbPYx2gd/xi4Ha1aysADyhG4Vjm4i6LVY00RVXIuW1PfLTR QAA8/4BLl0yXo0PqQnPJw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:3bcp9Hjq7kQ=:LwnBFx33KMah5m0wj132EU LbTczo+4JDDIXgP5QKfkub8MqUfrSBZ7WrKIq6R+8GnViOYF4Y43VhgvwyM6ue1t+zqnV4mWd 17EHqi2MeahPMY5hTFP3z0TGWKdKnQy+IBAvvSzhb2WGeU+jZxB4SbuF/qwUWBITiuYEIANq4 n4Tp+3LHt8cCgA1/0JEm/2eTQG1tu+tYqXhWki8j8G1ApYnyH+C9tyEZq3slgHfTQqEW5G3Nq 5PR77czoyRaK3flEBO/01AP1q5LPMJ3f0PGwSZSQxtGPXRUQ1dZCiIQhsGYaqLS1WDC8FaAEs 2MfFS/6ERBRG9Sq1+TV9ZbnyIj771WeIXEco4bXwz1C+fNTdAq7AIw1TnN1lkGfBuWULqkVj+ VjYV8Yvn9//Gaf/LF22eHhNBL4Fp/ea9a6PGdzer6CU8XqzgWowdRl/hd/rlMp/jtYutTtNcP BDT4vEDqaDopr5feAs0l+QkS4+BHcHnaIlgAUrwovyqXQYirJlekM8CH4utq99FYxMCwNU55a 1XnyGPWiu9fv7lIB1sB0q4HghBcLBu3HIBETimjaBEjy4N+yx9WnUTTRGtX1VFSoy/JgSZzn5 etlpBx4zg3Nnr0+IRtIKF5pZuttPmC/46xHY8XRuzqqfVGpIREDNcTDMqLB0QZMTUEAhidNr3 uJFggVb/KI7idF8QMV4qnNpO7XLQG8R1kRV4J1QudqBpdgCVTxXKVgMmCRunwxzabpSrkm6om 9X0O7um+5xZZcdbH3Ppjk8JaQoTVKEuVERwtHw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We are going to share the compat_sys_futex() handler between 64-bit architectures and 32-bit architectures that need to deal with both 32-bit and 64-bit time_t, and this is easier if both entry points are in the same file. In fact, most other system call handlers do the same thing these days, so let's follow the trend here and merge all of futex_compat.c into futex.c. In the process, a few minor changes have to be done to make sure everything still makes sense: handle_futex_death() and futex_cmpxchg_enabled() become local symbol, and the compat version of the fetch_robust_entry() function gets renamed to compat_fetch_robust_entry() to avoid a symbol clash. This is intended as a purely cosmetic patch, no behavior should change. Signed-off-by: Arnd Bergmann --- include/linux/futex.h | 8 -- kernel/Makefile | 3 - kernel/futex.c | 195 +++++++++++++++++++++++++++++++++++++++- kernel/futex_compat.c | 202 ------------------------------------------ 4 files changed, 192 insertions(+), 216 deletions(-) delete mode 100644 kernel/futex_compat.c -- 2.18.0 diff --git a/include/linux/futex.h b/include/linux/futex.h index 821ae502d3d8..ccaef0097785 100644 --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -9,9 +9,6 @@ struct inode; struct mm_struct; struct task_struct; -extern int -handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi); - /* * Futexes are matched on equal values of this key. * The key type depends on whether it's a shared or private mapping. @@ -55,11 +52,6 @@ extern void exit_robust_list(struct task_struct *curr); long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, u32 __user *uaddr2, u32 val2, u32 val3); -#ifdef CONFIG_HAVE_FUTEX_CMPXCHG -#define futex_cmpxchg_enabled 1 -#else -extern int futex_cmpxchg_enabled; -#endif #else static inline void exit_robust_list(struct task_struct *curr) { diff --git a/kernel/Makefile b/kernel/Makefile index 7343b3a9bff0..8e40a6742d23 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -49,9 +49,6 @@ obj-$(CONFIG_PROFILING) += profile.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += time/ obj-$(CONFIG_FUTEX) += futex.o -ifeq ($(CONFIG_COMPAT),y) -obj-$(CONFIG_FUTEX) += futex_compat.o -endif obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o obj-$(CONFIG_SMP) += smp.o ifneq ($(CONFIG_SMP),y) diff --git a/kernel/futex.c b/kernel/futex.c index f423f9b6577e..5cc7c3b098e9 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -44,6 +44,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include #include #include @@ -173,8 +174,10 @@ * double_lock_hb() and double_unlock_hb(), respectively. */ -#ifndef CONFIG_HAVE_FUTEX_CMPXCHG -int __read_mostly futex_cmpxchg_enabled; +#ifdef CONFIG_HAVE_FUTEX_CMPXCHG +#define futex_cmpxchg_enabled 1 +#else +static int __read_mostly futex_cmpxchg_enabled; #endif /* @@ -3360,7 +3363,7 @@ SYSCALL_DEFINE3(get_robust_list, int, pid, * Process a futex-list entry, check whether it's owned by the * dying task, and do notification if so: */ -int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi) +static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr, int pi) { u32 uval, uninitialized_var(nval), mval; @@ -3589,6 +3592,192 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); } +#ifdef CONFIG_COMPAT +/* + * Fetch a robust-list pointer. Bit 0 signals PI futexes: + */ +static inline int +compat_fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry, + compat_uptr_t __user *head, unsigned int *pi) +{ + if (get_user(*uentry, head)) + return -EFAULT; + + *entry = compat_ptr((*uentry) & ~1); + *pi = (unsigned int)(*uentry) & 1; + + return 0; +} + +static void __user *futex_uaddr(struct robust_list __user *entry, + compat_long_t futex_offset) +{ + compat_uptr_t base = ptr_to_compat(entry); + void __user *uaddr = compat_ptr(base + futex_offset); + + return uaddr; +} + +/* + * Walk curr->robust_list (very carefully, it's a userspace list!) + * and mark any locks found there dead, and notify any waiters. + * + * We silently return on any sign of list-walking problem. + */ +void compat_exit_robust_list(struct task_struct *curr) +{ + struct compat_robust_list_head __user *head = curr->compat_robust_list; + struct robust_list __user *entry, *next_entry, *pending; + unsigned int limit = ROBUST_LIST_LIMIT, pi, pip; + unsigned int uninitialized_var(next_pi); + compat_uptr_t uentry, next_uentry, upending; + compat_long_t futex_offset; + int rc; + + if (!futex_cmpxchg_enabled) + return; + + /* + * Fetch the list head (which was registered earlier, via + * sys_set_robust_list()): + */ + if (compat_fetch_robust_entry(&uentry, &entry, &head->list.next, &pi)) + return; + /* + * Fetch the relative futex offset: + */ + if (get_user(futex_offset, &head->futex_offset)) + return; + /* + * Fetch any possibly pending lock-add first, and handle it + * if it exists: + */ + if (compat_fetch_robust_entry(&upending, &pending, + &head->list_op_pending, &pip)) + return; + + next_entry = NULL; /* avoid warning with gcc */ + while (entry != (struct robust_list __user *) &head->list) { + /* + * Fetch the next entry in the list before calling + * handle_futex_death: + */ + rc = compat_fetch_robust_entry(&next_uentry, &next_entry, + (compat_uptr_t __user *)&entry->next, &next_pi); + /* + * A pending lock might already be on the list, so + * dont process it twice: + */ + if (entry != pending) { + void __user *uaddr = futex_uaddr(entry, futex_offset); + + if (handle_futex_death(uaddr, curr, pi)) + return; + } + if (rc) + return; + uentry = next_uentry; + entry = next_entry; + pi = next_pi; + /* + * Avoid excessively long or circular lists: + */ + if (!--limit) + break; + + cond_resched(); + } + if (pending) { + void __user *uaddr = futex_uaddr(pending, futex_offset); + + handle_futex_death(uaddr, curr, pip); + } +} + +COMPAT_SYSCALL_DEFINE2(set_robust_list, + struct compat_robust_list_head __user *, head, + compat_size_t, len) +{ + if (!futex_cmpxchg_enabled) + return -ENOSYS; + + if (unlikely(len != sizeof(*head))) + return -EINVAL; + + current->compat_robust_list = head; + + return 0; +} + +COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid, + compat_uptr_t __user *, head_ptr, + compat_size_t __user *, len_ptr) +{ + struct compat_robust_list_head __user *head; + unsigned long ret; + struct task_struct *p; + + if (!futex_cmpxchg_enabled) + return -ENOSYS; + + rcu_read_lock(); + + ret = -ESRCH; + if (!pid) + p = current; + else { + p = find_task_by_vpid(pid); + if (!p) + goto err_unlock; + } + + ret = -EPERM; + if (!ptrace_may_access(p, PTRACE_MODE_READ_REALCREDS)) + goto err_unlock; + + head = p->compat_robust_list; + rcu_read_unlock(); + + if (put_user(sizeof(*head), len_ptr)) + return -EFAULT; + return put_user(ptr_to_compat(head), head_ptr); + +err_unlock: + rcu_read_unlock(); + + return ret; +} + +COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, + struct old_timespec32 __user *, utime, u32 __user *, uaddr2, + u32, val3) +{ + struct timespec ts; + ktime_t t, *tp = NULL; + int val2 = 0; + int cmd = op & FUTEX_CMD_MASK; + + if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI || + cmd == FUTEX_WAIT_BITSET || + cmd == FUTEX_WAIT_REQUEUE_PI)) { + if (compat_get_timespec(&ts, utime)) + return -EFAULT; + if (!timespec_valid(&ts)) + return -EINVAL; + + t = timespec_to_ktime(ts); + if (cmd == FUTEX_WAIT) + t = ktime_add_safe(ktime_get(), t); + tp = &t; + } + if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE || + cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP) + val2 = (int) (unsigned long) utime; + + return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); +} +#endif /* CONFIG_COMPAT */ + static void __init futex_detect_cmpxchg(void) { #ifndef CONFIG_HAVE_FUTEX_CMPXCHG diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c deleted file mode 100644 index 410a77a8f6e2..000000000000 --- a/kernel/futex_compat.c +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * linux/kernel/futex_compat.c - * - * Futex compatibililty routines. - * - * Copyright 2006, Red Hat, Inc., Ingo Molnar - */ - -#include -#include -#include -#include -#include -#include - -#include - - -/* - * Fetch a robust-list pointer. Bit 0 signals PI futexes: - */ -static inline int -fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry, - compat_uptr_t __user *head, unsigned int *pi) -{ - if (get_user(*uentry, head)) - return -EFAULT; - - *entry = compat_ptr((*uentry) & ~1); - *pi = (unsigned int)(*uentry) & 1; - - return 0; -} - -static void __user *futex_uaddr(struct robust_list __user *entry, - compat_long_t futex_offset) -{ - compat_uptr_t base = ptr_to_compat(entry); - void __user *uaddr = compat_ptr(base + futex_offset); - - return uaddr; -} - -/* - * Walk curr->robust_list (very carefully, it's a userspace list!) - * and mark any locks found there dead, and notify any waiters. - * - * We silently return on any sign of list-walking problem. - */ -void compat_exit_robust_list(struct task_struct *curr) -{ - struct compat_robust_list_head __user *head = curr->compat_robust_list; - struct robust_list __user *entry, *next_entry, *pending; - unsigned int limit = ROBUST_LIST_LIMIT, pi, pip; - unsigned int uninitialized_var(next_pi); - compat_uptr_t uentry, next_uentry, upending; - compat_long_t futex_offset; - int rc; - - if (!futex_cmpxchg_enabled) - return; - - /* - * Fetch the list head (which was registered earlier, via - * sys_set_robust_list()): - */ - if (fetch_robust_entry(&uentry, &entry, &head->list.next, &pi)) - return; - /* - * Fetch the relative futex offset: - */ - if (get_user(futex_offset, &head->futex_offset)) - return; - /* - * Fetch any possibly pending lock-add first, and handle it - * if it exists: - */ - if (fetch_robust_entry(&upending, &pending, - &head->list_op_pending, &pip)) - return; - - next_entry = NULL; /* avoid warning with gcc */ - while (entry != (struct robust_list __user *) &head->list) { - /* - * Fetch the next entry in the list before calling - * handle_futex_death: - */ - rc = fetch_robust_entry(&next_uentry, &next_entry, - (compat_uptr_t __user *)&entry->next, &next_pi); - /* - * A pending lock might already be on the list, so - * dont process it twice: - */ - if (entry != pending) { - void __user *uaddr = futex_uaddr(entry, futex_offset); - - if (handle_futex_death(uaddr, curr, pi)) - return; - } - if (rc) - return; - uentry = next_uentry; - entry = next_entry; - pi = next_pi; - /* - * Avoid excessively long or circular lists: - */ - if (!--limit) - break; - - cond_resched(); - } - if (pending) { - void __user *uaddr = futex_uaddr(pending, futex_offset); - - handle_futex_death(uaddr, curr, pip); - } -} - -COMPAT_SYSCALL_DEFINE2(set_robust_list, - struct compat_robust_list_head __user *, head, - compat_size_t, len) -{ - if (!futex_cmpxchg_enabled) - return -ENOSYS; - - if (unlikely(len != sizeof(*head))) - return -EINVAL; - - current->compat_robust_list = head; - - return 0; -} - -COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid, - compat_uptr_t __user *, head_ptr, - compat_size_t __user *, len_ptr) -{ - struct compat_robust_list_head __user *head; - unsigned long ret; - struct task_struct *p; - - if (!futex_cmpxchg_enabled) - return -ENOSYS; - - rcu_read_lock(); - - ret = -ESRCH; - if (!pid) - p = current; - else { - p = find_task_by_vpid(pid); - if (!p) - goto err_unlock; - } - - ret = -EPERM; - if (!ptrace_may_access(p, PTRACE_MODE_READ_REALCREDS)) - goto err_unlock; - - head = p->compat_robust_list; - rcu_read_unlock(); - - if (put_user(sizeof(*head), len_ptr)) - return -EFAULT; - return put_user(ptr_to_compat(head), head_ptr); - -err_unlock: - rcu_read_unlock(); - - return ret; -} - -COMPAT_SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, - struct old_timespec32 __user *, utime, u32 __user *, uaddr2, - u32, val3) -{ - struct timespec ts; - ktime_t t, *tp = NULL; - int val2 = 0; - int cmd = op & FUTEX_CMD_MASK; - - if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI || - cmd == FUTEX_WAIT_BITSET || - cmd == FUTEX_WAIT_REQUEUE_PI)) { - if (compat_get_timespec(&ts, utime)) - return -EFAULT; - if (!timespec_valid(&ts)) - return -EINVAL; - - t = timespec_to_ktime(ts); - if (cmd == FUTEX_WAIT) - t = ktime_add_safe(ktime_get(), t); - tp = &t; - } - if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE || - cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP) - val2 = (int) (unsigned long) utime; - - return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); -} From patchwork Fri Dec 7 21:18:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 153213 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp981890ljp; Fri, 7 Dec 2018 13:18:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UO1TKJEn2Opcqycm86tFUFQeMtqZ2yrRqKup0hVuCAqaJaAcUYe0WEbpInctjjihYqV39N X-Received: by 2002:a63:334a:: with SMTP id z71mr3383243pgz.400.1544217509644; Fri, 07 Dec 2018 13:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544217509; cv=none; d=google.com; s=arc-20160816; b=tXUAMZfYcTezpFMCG3oetLTZeylDW1HJZ21IzEdouZGTF0yD2cXxxfw9nbcwA8CC68 TnS8grlbkY8XKDFYX8i4kFQ/zbjvqOpQ73Sd5qsUlXytMt3Rn94+3nnUDcYK4anQ00Ng XLkrnmTJ8g4nO9ychaucH+qbUw3rdU3MjwpLKb0KCCxzuPM8ywGR4W9qfTxCvrvQZ+N4 8c3HZ86plsoJNz66mQCHmwn1NK/8BvFAUsTGqi3PqKffiS8Y45IOLcLyJe4PmMvl/vDR B89axfEJdv88c4z2vLA97EJl6MIGdPkJsdBcwsqAx9YIfu6xzYb60Eb5YewAfKf9frpj nALw== 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; bh=xO26Z/2Cf8MU25iwQ5j/9NRI6TvUg9dgMmllWe0OlyE=; b=dKjU0cpbQiO4MsQ30CTwxvDA5cOg7JjJvRJlB9XSTIqqlTfDL8vqwTszI9R0CpEPUu dsfYMkdLaBBTzoXM9XdT7X9YZKdQ3C4M8OqCIQLZqh1cMPwo7JHYw+PgRMvvMBgWx+Vj eRHSRJxfB4Ldhn5XPWEDRmwhQkqBhHDRF9S2SyqeVr25qmNlshnnzs0MBM9Cmvp9YoPz 2CkRb2NGhLKJ5/GSmmyaKy4RxdcjWSOt8KorCJ06ClDSVwQf58VF46AKWs74jv694Cox 6Ir4ZUTrjfmrKYpPWyFWzuIZhAdlXeKKsQoPOcMPyV0dPbyT1XNEw2pX5hoZpy/vIPNB +Tow== 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 d65si4058380pfc.201.2018.12.07.13.18.29; Fri, 07 Dec 2018 13:18:29 -0800 (PST) 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 S1726186AbeLGVSV (ORCPT + 31 others); Fri, 7 Dec 2018 16:18:21 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:52417 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbeLGVST (ORCPT ); Fri, 7 Dec 2018 16:18:19 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1N6KML-1hXEVe16zZ-016eTl; Fri, 07 Dec 2018 22:18:11 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, Deepa Dinamani , John Stultz , Thomas Gleixner , linux-api@vger.kernel.org, Arnd Bergmann Subject: [PATCH 2/5] y2038: futex: Add support for __kernel_timespec Date: Fri, 7 Dec 2018 22:18:05 +0100 Message-Id: <20181207211808.328719-3-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207211808.328719-1-arnd@arndb.de> References: <20181207211808.328719-1-arnd@arndb.de> X-Provags-ID: V03:K1:7ftGwTPI7nF5tkVyrja5NNO8XIM3pe9wwKW0ivr2EU7CWAR7+sJ HNlClwPMuAFys8UuHBQ8XVzUZPxvyoUwUYSmHgMcm5M2RHVe0Ko0liKUc5Sf6yXL2T1wcl6 +4aUBv0+pmN2/m3i4kS2ikZfyMvprft3rNiGo+FGJVBYc+lcyMApCz1fidszd6Oznu99YG0 iqxpFDS+Kwss9rPv0bPQA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:E5NpT+phjsU=:P4Ju90ZAdT3wAhcNFqTgPF 8kD2ckQI6TG/iR5mudT5GuZolIXK9+Vydv9z4xVuhUrQ14rCGPlCaIcevQe6Sfi+cLyV1aQyU KbkfWQdC1XWX2sSQSRz/hmxBgC7ykqeUwtw/ajywquDNipbQk0h1tvpiP1+UkpD8WCwHdEymg im50plQBOhKRe5jZa11bbiCn5cn+KDkHw1aCCbzHFSb62kqEuiWhGAfXOPECSsYqMUXC+NAvi EXLkO0z9Q9Fpfa7FsehGHpXcbokjy7rGQ2VM8uJzzFVpEe5tACPrc6uyoJccXsjAm1iqez7DC 0kJUp2D2nQ0xMb4R12OhMhpFA0hdrCDi8dIAWXTAtG0YQ0QtSq2Tmj4u4Sg1XWjTL30Th2Uqm kWnVf4SvNzf1gaW4eH1LxjDFSpi2cPzuA1PxzTHuPlH/35orgXjiuYywwLowMpaAoYReEU6FQ A/Wswtkj1FY5FdT7j3nwu9B+hND9PqN9DkjDvQjGPvuUKitH+xRsLSWQGZiA0G7b0NtYxC1V9 nAhkLiGbZZHbnTsQnouMs3nui/lv2I0Udps21cNfMIRenbD+bncNj/i0dMHNZhgoox67Q2jUz 1z97Fzgq95IcbXlZzxg8D2V2AaF3uGBnuwiky/x5+Prk+N6Iy5Q8UcO7yRnTPP+HyUdcYr6cp UiCdB/uxYPWJi6H0o1AuBzRfbsmaEJYeyAlGjDxfEwm03WUvADluCg+5vGa7UBZmNVZ+R8T/C kTzF43/O01HePHZT2rrAb20Wr5lKKfPUPET2WA== 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.18.0 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a27cf407de92..247ad9eca955 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -553,7 +553,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 5cc7c3b098e9..b305beaab739 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -3558,10 +3558,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; @@ -3571,12 +3571,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; @@ -3747,12 +3747,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 old_timespec32 __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; @@ -3760,12 +3762,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 (get_old_timespec32(&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; @@ -3776,7 +3778,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) { From patchwork Fri Dec 7 21:18:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 153214 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp981972ljp; Fri, 7 Dec 2018 13:18:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/U0vK77f+uAH/OmTaGOa/gLpJ7lNQfvp7FukXDHPqqdQszD5NZ6F4Y5vrQ/b6WLvYcUUTOI X-Received: by 2002:a62:db41:: with SMTP id f62mr3840384pfg.123.1544217513907; Fri, 07 Dec 2018 13:18:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544217513; cv=none; d=google.com; s=arc-20160816; b=i6tRFbmlZ/hs7ekVpRBOZVeIIqpm2Ebk/I/hWxA0SxSt7RaNnBuKT089bS35AnDQSy lQK7XONlcAzYBTsmLA9R4ryT8Mgd/L4F8Ttr2cmzGgbzxY7au2yDmMYnPBV/Pf2E/FTf Z5qhqpfRpDqeq0r5yZIq8iSLbCiguUo1D/5S/gf1JegspjwkwSXYwKf5k/F3BOV56/YR UI6ADPfnRYRyjzv06PKia5BqnOkvc+z5HRbkv4qc3EOjpMix9OCsRk3ZXxnHtE56yKzP SR67PLPvy7IT0i9V+EZdwTypx7A53dM7Bbtdth0vF01kV5t8q0KHv9OPYQZDHLvQFjAa P48A== 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; bh=Qyf25qqDWWEz3l571WTdLLV+y8aMdgyAJEzMSZIqsHE=; b=cPKAfoy0uG47pa7kuU65dRvlbzvezNPnmKLPK21Wn37n92kUFg72ztweQKCQYT9oVg RwAvqz/O/uEGb/ma2xlpmgb7wuf9FWeXY2COkOQgD0Cjp8KTpIiYLOvCrTdR9tk14coZ EgyeWw64l/uzN33JvMr7nL6f50Z57wd+z5rm0140SBsjXkqxdVqyGT+/RrYziHgPv4IX eBWv3RXMmUwrHPasPgLuhP/loGy9oSQV477/OgVsAz4ts51tNurHwuInuUp8e1b7k2xC VVw2ohk3SOgjiKbex90M23ZtXqrQG//zN6mH5Pxag8JOQgWdZff7ytk5RvdKGgpeDs/h 3jrA== 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 d65si4058380pfc.201.2018.12.07.13.18.33; Fri, 07 Dec 2018 13:18:33 -0800 (PST) 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 S1726248AbeLGVSd (ORCPT + 31 others); Fri, 7 Dec 2018 16:18:33 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:53605 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726008AbeLGVSV (ORCPT ); Fri, 7 Dec 2018 16:18:21 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1MplPh-1hGo5W2S5d-00qE5Z; Fri, 07 Dec 2018 22:18:11 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, Deepa Dinamani , John Stultz , Thomas Gleixner , linux-api@vger.kernel.org, Arnd Bergmann Subject: [PATCH 3/5] y2038: socket: Add compat_sys_recvmmsg_time64 Date: Fri, 7 Dec 2018 22:18:06 +0100 Message-Id: <20181207211808.328719-4-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207211808.328719-1-arnd@arndb.de> References: <20181207211808.328719-1-arnd@arndb.de> X-Provags-ID: V03:K1:sOlXinQ15YOEvSUzUUIl491MtCJ259elSjV8IWfK7TdcmuBugiO L6su+CjwmFZ34M//TbTI8Sdw2NScRBUJZlGvtfjVv6quZYHW29SAyZRsiZT688SXbgylWNz T5HwBN25FRyViOa3dnOQn+t8FIeyglUdvs+tetm6GAnk6fV04WuCFLklXjvN229kwlCE3bx iTm79ZALE3Bd/V5dNpB7w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:IRwf1Zkm8Ak=:o/1Jea/hqYwpfNIynMOBWb Z8+ZrYpsGxocze14uTdqHvhqAj+T6KzcCS7I+JZTElNeu2nDnY9MK7W3bkCLmyIZSCgTXa9Rc OSxtuqowA1ZhvjQp9sywqxggaZazdwksZ7ZdutLvEE1N4BeiuxDP59tVmpnpWJkDWibUmmwiE ivmT5ySeI21YFDo0zL4wve3c1X98gyCZ7RdIcMh9oWx2DeRAkrO/hykTiDJN5UVgXHQehJL3J D6Aa6wyrQvciyNQ9Y7GgPXRY/LMXUXXl7UyDH/+7bECia0pxnLfKHeeQTWY8a4Lq9yEs9F4cp h+uAZWUYLcrmzAkghB1aqh2mEJRTrFdSeqNVXhuHjDscuxGIvCb60IEfDMomnHbvIyOX0ItGx s1yTugpWOnHIUApXB5/8NjAKcJhxr12WfAdU+rG7T04vZcVnsBTgBC3e9wTZ1rjsiPxk0BFrc PeJxz5pqqulx16ajuw6LT06BKnj5p++BnHhrTyj0Ulgf7rtQ9dayN81VUtAZv9hmWnj/fwf3k 6tD8pwVluvnhoc+o1hvWAy/Yn0t3u4WA5FGMAj/QJtO/jFBH4xyWXZZUc9EEAr+2tsqU8ovIj n09NFaGFRPD3SoiQcYnmUtVDu2vMJKx0hHS5gpgObnqpnGtWbmYU1xvcmQMYJ2ccB2yOEeD9B iHeg10iTK/aFqNghgdEgwlcHdYSB9nnsycq3h+eGYCKmlHpzqnpnCBvYtvhk/2Qp/XwzHJEsl aOK4xGF+luB5zSBCgD+1bEDndlpM6bmmvO4tVg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org recvmmsg() takes two arguments to pointers of structures that differ between 32-bit and 64-bit architectures: mmsghdr and timespec. For y2038 compatbility, we are changing the native system call from timespec to __kernel_timespec with a 64-bit time_t (in another patch), and use the existing compat system call on both 32-bit and 64-bit architectures for compatibility with traditional 32-bit user space. As we now have two variants of recvmmsg() for 32-bit tasks that are both different from the variant that we use on 64-bit tasks, this means we also require two compat system calls! The solution I picked is to flip things around: The existing compat_sys_recvmmsg() call gets moved from net/compat.c into net/socket.c and now handles the case for old user space on all architectures that have set CONFIG_COMPAT_32BIT_TIME. A new compat_sys_recvmmsg_time64() call gets added in the old place for 64-bit architectures only, this one handles the case of a compat mmsghdr structure combined with __kernel_timespec. In the indirect sys_socketcall(), we now need to call either do_sys_recvmmsg() or __compat_sys_recvmmsg(), depending on what kind of architecture we are on. For compat_sys_socketcall(), no such change is needed, we always call __compat_sys_recvmmsg(). I decided to not add a new SYS_RECVMMSG_TIME64 socketcall: Any libc implementation for 64-bit time_t will need significant changes including an updated asm/unistd.h, and it seems better to consistently use the separate syscalls that configuration, leaving the socketcall only for backward compatibility with 32-bit time_t based libc. The naming is asymmetric for the moment, so both existing syscalls entry points keep their names, while the new ones are recvmmsg_time32 and compat_recvmmsg_time64 respectively. I expect that we will rename the compat syscalls later as we start using generated syscall tables everywhere and add these entry points. Signed-off-by: Arnd Bergmann --- include/linux/compat.h | 5 +++- include/linux/socket.h | 9 ++++-- include/linux/syscalls.h | 3 ++ kernel/sys_ni.c | 2 ++ net/compat.c | 34 ++++++++-------------- net/socket.c | 62 +++++++++++++++++++++++++++++----------- 6 files changed, 73 insertions(+), 42 deletions(-) -- 2.18.0 diff --git a/include/linux/compat.h b/include/linux/compat.h index 8be8daa38c9a..72969d303434 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -893,7 +893,10 @@ asmlinkage long compat_sys_move_pages(pid_t pid, compat_ulong_t nr_pages, asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid, compat_pid_t pid, int sig, struct compat_siginfo __user *uinfo); -asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, +asmlinkage long compat_sys_recvmmsg_time64(int fd, struct compat_mmsghdr __user *mmsg, + unsigned vlen, unsigned int flags, + struct __kernel_timespec __user *timeout); +asmlinkage long compat_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned vlen, unsigned int flags, struct old_timespec32 __user *timeout); asmlinkage long compat_sys_wait4(compat_pid_t pid, diff --git a/include/linux/socket.h b/include/linux/socket.h index 8b571e9b9f76..333b5df8a1b2 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -348,7 +348,8 @@ struct ucred { extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr); extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data); -struct timespec64; +struct __kernel_timespec; +struct old_timespec32; /* The __sys_...msg variants allow MSG_CMSG_COMPAT iff * forbid_cmsg_compat==false @@ -357,8 +358,10 @@ extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned int flags, bool forbid_cmsg_compat); extern long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned int flags, bool forbid_cmsg_compat); -extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, - unsigned int flags, struct timespec64 *timeout); +extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct __kernel_timespec __user *timeout, + struct old_timespec32 __user *timeout32); extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags, bool forbid_cmsg_compat); diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 247ad9eca955..03cda6793be3 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -843,6 +843,9 @@ asmlinkage long sys_accept4(int, struct sockaddr __user *, int __user *, int); asmlinkage long sys_recvmmsg(int fd, struct mmsghdr __user *msg, unsigned int vlen, unsigned flags, struct __kernel_timespec __user *timeout); +asmlinkage long sys_recvmmsg_time32(int fd, struct mmsghdr __user *msg, + unsigned int vlen, unsigned flags, + struct old_timespec32 __user *timeout); asmlinkage long sys_wait4(pid_t pid, int __user *stat_addr, int options, struct rusage __user *ru); diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index df556175be50..ab9d0e3c6d50 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -284,7 +284,9 @@ COND_SYSCALL_COMPAT(move_pages); COND_SYSCALL(perf_event_open); COND_SYSCALL(accept4); COND_SYSCALL(recvmmsg); +COND_SYSCALL(recvmmsg_time32); COND_SYSCALL_COMPAT(recvmmsg); +COND_SYSCALL_COMPAT(recvmmsg_time64); /* * Architecture specific syscalls: see further below diff --git a/net/compat.c b/net/compat.c index 47a614b370cd..f7084780a8f8 100644 --- a/net/compat.c +++ b/net/compat.c @@ -810,34 +810,23 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen); } -static int __compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, - unsigned int vlen, unsigned int flags, - struct old_timespec32 __user *timeout) +COMPAT_SYSCALL_DEFINE5(recvmmsg_time64, int, fd, struct compat_mmsghdr __user *, mmsg, + unsigned int, vlen, unsigned int, flags, + struct __kernel_timespec __user *, timeout) { - int datagrams; - struct timespec64 ktspec; - - if (timeout == NULL) - return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, - flags | MSG_CMSG_COMPAT, NULL); - - if (compat_get_timespec64(&ktspec, timeout)) - return -EFAULT; - - datagrams = __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, - flags | MSG_CMSG_COMPAT, &ktspec); - if (datagrams > 0 && compat_put_timespec64(&ktspec, timeout)) - datagrams = -EFAULT; - - return datagrams; + return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, + flags | MSG_CMSG_COMPAT, timeout, NULL); } +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, struct old_timespec32 __user *, timeout) { - return __compat_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); + return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, + flags | MSG_CMSG_COMPAT, NULL, timeout); } +#endif COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) { @@ -925,8 +914,9 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) ret = __compat_sys_recvmsg(a0, compat_ptr(a1), a[2]); break; case SYS_RECVMMSG: - ret = __compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3], - compat_ptr(a[4])); + ret = __sys_recvmmsg(a0, compat_ptr(a1), a[2], + a[3] | MSG_CMSG_COMPAT, NULL, + compat_ptr(a[4])); break; case SYS_ACCEPT4: ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]); diff --git a/net/socket.c b/net/socket.c index 593826e11a53..f6a2d3a7b611 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2341,8 +2341,9 @@ SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg, * Linux recvmmsg interface */ -int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, - unsigned int flags, struct timespec64 *timeout) +static int do_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct timespec64 *timeout) { int fput_needed, err, datagrams; struct socket *sock; @@ -2451,25 +2452,32 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, return datagrams; } -static int do_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, - unsigned int vlen, unsigned int flags, - struct __kernel_timespec __user *timeout) +int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct __kernel_timespec __user *timeout, + struct old_timespec32 __user *timeout32) { int datagrams; struct timespec64 timeout_sys; - if (flags & MSG_CMSG_COMPAT) - return -EINVAL; - - if (!timeout) - return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL); + if (timeout && get_timespec64(&timeout_sys, timeout)) + return -EFAULT; - if (get_timespec64(&timeout_sys, timeout)) + if (timeout32 && get_old_timespec32(&timeout_sys, timeout32)) return -EFAULT; - datagrams = __sys_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys); + if (!timeout && !timeout32) + do_recvmmsg(fd, mmsg, vlen, flags, NULL); + + datagrams = do_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys); - if (datagrams > 0 && put_timespec64(&timeout_sys, timeout)) + if (!datagrams) + return 0; + + if (timeout && put_timespec64(&timeout_sys, timeout)) + datagrams = -EFAULT; + + if (timeout32 && put_old_timespec32(&timeout_sys, timeout32)) datagrams = -EFAULT; return datagrams; @@ -2479,8 +2487,23 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, struct __kernel_timespec __user *, timeout) { - return do_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); + if (flags & MSG_CMSG_COMPAT) + return -EINVAL; + + return __sys_recvmmsg(fd, mmsg, vlen, flags, timeout, NULL); +} + +#ifdef CONFIG_COMPAT_32BIT_TIME +SYSCALL_DEFINE5(recvmmsg_time32, int, fd, struct mmsghdr __user *, mmsg, + unsigned int, vlen, unsigned int, flags, + struct old_timespec32 __user *, timeout) +{ + if (flags & MSG_CMSG_COMPAT) + return -EINVAL; + + return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL, timeout); } +#endif #ifdef __ARCH_WANT_SYS_SOCKETCALL /* Argument list sizes for sys_socketcall */ @@ -2600,8 +2623,15 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) a[2], true); break; case SYS_RECVMMSG: - err = do_sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], - a[3], (struct __kernel_timespec __user *)a[4]); + if (IS_ENABLED(CONFIG_64BIT) || !IS_ENABLED(CONFIG_64BIT_TIME)) + err = __sys_recvmmsg(a0, (struct mmsghdr __user *)a1, + a[2], a[3], + (struct __kernel_timespec __user *)a[4], + NULL); + else + err = __sys_recvmmsg(a0, (struct mmsghdr __user *)a1, + a[2], a[3], NULL, + (struct old_timespec32 __user *)a[4]); break; case SYS_ACCEPT4: err = __sys_accept4(a0, (struct sockaddr __user *)a1, From patchwork Fri Dec 7 21:18:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 153216 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp982164ljp; Fri, 7 Dec 2018 13:18:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/WHoiroSyiuZRzC1GKjsrOLoRujAJ2bQv0Gg6L/GnW9p5nWtBHVj0/wP7BhJl/O81AVLiNQ X-Received: by 2002:a17:902:4401:: with SMTP id k1mr3626046pld.307.1544217525290; Fri, 07 Dec 2018 13:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544217525; cv=none; d=google.com; s=arc-20160816; b=XEJ+6NIn46+anVbov3Ws1HOpCjwcdFEyJWMOfspGYRCkpcog36YVYZUyTlVlPDiL2I Ph8uu6PWmkN6v0/+CcibJChz6H1mEhViL4Av/JUBHJB1ATLSwi1GWU9ZgRR8LWOFR9Cs OopxbIcMWH9alCyFjWc3fj+V7Q75zV/cHewp2l9X05OMXELZsJtFdt9nnTeUfwZmF2JU nnfvMC05KFr60HFIiDvEKmRdLpgmYya37aFIKAZBktPYd1nkvNDXVzDQOnDMBkKA7xZ5 pa1pORxG446QQ2aW7boxa9+rxY2KZ2LiaRvXQAt+b4lZeUjFXD6gg0+G0SceFjiWe+TV 7eAg== 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; bh=pr5ecYhHSFIsJkPVCC6kJspJ3eJH9Gxmc/N/Y+vp9s4=; b=f0wOpKCVzD4k/+KFBpCxAsnu7mMYp1DrXusO77+I9aUaeSwBBO7TvdiOoibTG/+Jtg zZxHehqg62Dlz/xSnhOtrfcWuypSYJqUmSI7mIX8WmLIheyQhyfUqlpT2FgW9B896qmm mI3P8AGha82hNYXdDJvNzoVJkacx3Pmx4TWRv4EMKG8wg5U9c53R1IdmcJ2Hw1FnYfWk XQPAZvMKKH2H62YzCP4h/nFVYpRriOM8BNYn7wuBVHekgGuNruHK2sOV2+Duncb04rFf wndGX2MxPrbpANfl+M1YP4l+GRDfqDCC9jiHuvSEftlSSJ64qpcTwSUpl5gxsGXm7hd1 F/1A== 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 n18si4080282pfj.30.2018.12.07.13.18.44; Fri, 07 Dec 2018 13:18:45 -0800 (PST) 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 S1726294AbeLGVSn (ORCPT + 31 others); Fri, 7 Dec 2018 16:18:43 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:51673 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbeLGVSU (ORCPT ); Fri, 7 Dec 2018 16:18:20 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1Mw9Lw-1hN4Yp3l8m-00s3Tc; Fri, 07 Dec 2018 22:18:12 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, Deepa Dinamani , John Stultz , Thomas Gleixner , linux-api@vger.kernel.org, Arnd Bergmann Subject: [PATCH 4/5] y2038: signal: Add sys_rt_sigtimedwait_time32 Date: Fri, 7 Dec 2018 22:18:07 +0100 Message-Id: <20181207211808.328719-5-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207211808.328719-1-arnd@arndb.de> References: <20181207211808.328719-1-arnd@arndb.de> X-Provags-ID: V03:K1:9/bXOgXlO7u0sJ91CfOocMwpttHH+17Xfkde7QGcqXCtXbRVlQA aCxKzXNfyUMgkD/nEzNaRk6f6zxGFgltNuujLCwBsz6QRGW9tEs58FnD/vunLWBOs7L5XDY CeVGkPbfnpP7YIlgQgFreUF/0MvL2y8MZgcMyDTqq+OV4WtBb7Pcq0RRVKniP69gIbUY227 tOGU9aTjSsfho46XO/L+Q== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:ZYi/Jb0Y4ww=:FOp45kB5zlBpwkxzYpmhaM J/hZGky1w0Q0yc97fAZMHtDHgOfYpkunNiuXthtUdUxJnEnbjAQVj5kJG7gvEYPyRaaJFUWs1 aQwDLMbC4pKzSmyR4OgfjfXQCS+Jlf+M4fRweMoXR4UlNy53hyY61zYZmtCgcwmDUd1Obx2cn NcBT6DrskLhQcL7EktWayR7xDHDlXX8XodcMjaVwXwxnpqTG7CLDulzVhQvTKb6cyavteR60y yax+3kEUBsdRKQvCB3Sm/Pnhy2RWFCVl2Ss9JRlAN4YHPVijV3n8WmDQXmvVhdbCKF15p5S+C lbKQf3rbApAJ0XcGeOEyD1l/ozkU/5n4nUp5ABH38CoJerpPlRq8tHlRdXVIcs4GgG64TrD9K BF6+UE01Xdb83HkjGWN7WV2SyfPv6JHAI3FwGn1hC/46XnfkCpEqzW4WdKaN1zkonbvkA8eOM f9TG8UaKlkdTD6FZq9rRcDxQCxJ2wRRdEmBF0YeU18t/HZ8H4HrBRwUZWbf0fUDlP+UF+/G25 p5Cb3H+OgtzliyO9OXeQjSMEbsvsc8kfmEWuvo/42pHVbcqtB5Nj+zIc+UqggR6iGDcXLfA+K Zxn5o+0fV4uaqsD3kZrsX5dNxoBltBp3Uo7bdR0iXi/oyF0OGxTZiXsJ2Wy/iS4WLMxxh9ntK FhNpbs4+H4pMTppNeLbCib8FGRmAjL/AVXWF7/T6i5M9HmUOFv0TFaHhYpfZdxVAuwOo8iuPA eNu7aFdDJNjhp16YPsTRHbq4d+9yaYj51fOfTQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Once sys_rt_sigtimedwait() gets changed to a 64-bit time_t, we have to provide compatibility support for existing binaries. An earlier version of this patch reused the compat_sys_rt_sigtimedwait entry point to avoid code duplication, but this newer approach duplicates the existing native entry point instead, which seems a bit cleaner. Signed-off-by: Arnd Bergmann --- include/linux/syscalls.h | 4 ++++ kernel/signal.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) -- 2.18.0 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 03cda6793be3..251979d2e709 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -649,6 +649,10 @@ asmlinkage long sys_rt_sigtimedwait(const sigset_t __user *uthese, siginfo_t __user *uinfo, const struct __kernel_timespec __user *uts, size_t sigsetsize); +asmlinkage long sys_rt_sigtimedwait_time32(const sigset_t __user *uthese, + siginfo_t __user *uinfo, + const struct old_timespec32 __user *uts, + size_t sigsetsize); asmlinkage long sys_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t __user *uinfo); /* kernel/sys.c */ diff --git a/kernel/signal.c b/kernel/signal.c index 3c8ea7a328e0..be6744cd0a11 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3332,6 +3332,39 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, return ret; } +#ifdef CONFIG_COMPAT_32BIT_TIME +SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese, + siginfo_t __user *, uinfo, + const struct old_timespec32 __user *, uts, + size_t, sigsetsize) +{ + sigset_t these; + struct timespec64 ts; + kernel_siginfo_t info; + int ret; + + if (sigsetsize != sizeof(sigset_t)) + return -EINVAL; + + if (copy_from_user(&these, uthese, sizeof(these))) + return -EFAULT; + + if (uts) { + if (get_old_timespec32(&ts, uts)) + return -EFAULT; + } + + ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL); + + if (ret > 0 && uinfo) { + if (copy_siginfo_to_user(uinfo, &info)) + ret = -EFAULT; + } + + return ret; +} +#endif + #ifdef CONFIG_COMPAT COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, struct compat_siginfo __user *, uinfo, From patchwork Fri Dec 7 21:18:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 153212 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp981850ljp; Fri, 7 Dec 2018 13:18:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2lsr3F4TrihjIUEFgcmHjiufs9KdFAbalo83nl3OmYdPclyk+nwZa4ZeeazskaUP9Ove+ X-Received: by 2002:a17:902:3064:: with SMTP id u91mr3530713plb.325.1544217506862; Fri, 07 Dec 2018 13:18:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544217506; cv=none; d=google.com; s=arc-20160816; b=jgL9XbJuCvPzBrM90IorgB6dqXjUygxvRob/14Lf8yyN2KM5H13PqnNMkMvhEWFROm HHq/2sapRzTIQh97ddFIDJcINkE+sAw+2FyXaW0ncDWBshtoTj0qBrrpXspBIEPP66vx 2uuirpKMPScrTTRWqGtKrKzRdfZxH7m3fMn8A9bzupGqziryVPb1ZVrsHGmdy4RpdvGH YZI4VrQ3cRjlvLof9BElCVF6o3db2noXml5vYQ9teVxKBEB12QUDFJiWXzy91j2TaodU YcF4pDC1xURxcx0v9GsLSDlmS1YsVga3epcSBYs4rW5oABXrEYuX0xIqu0BRGni04jWp kFMA== 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; bh=IY0qpYJrGYW+/dtyvT6rfSUemJG59MXZpKq9Bi9rdJA=; b=G3IjNa/6H74/GNU2HYLzdyLSjRqmL8ckcWVTrX6LWm1Uq7pMW74pSHE4u0c41drCkW m6LVmE848wtabXg0WkL4V3Jpo7bRaQ5o3KT6QIqbr7nmHnvW3UJsIf9iTPeSJVA/u4Hi 2xZuDBls5F27e1hZM+nit1iuHyLuBuvnqRDZqHvjScvsMmGh5KKDJ6bR8Bm5sllQxV6X d3Eb1JLe4PTsu5T26DVfvkn/U0HvJ4JvpyaWR5dmlB7AhdjLUBvDyzMmxLiBAlgzgjvK sQELZ35QGAXqNNr/Bwg0mpaGVXTJBf37GheEakTkCkQ6uaOb6v/JuzhqFB33QbPEuM5I zEWw== 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 1si3890310pls.16.2018.12.07.13.18.26; Fri, 07 Dec 2018 13:18:26 -0800 (PST) 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 S1726218AbeLGVSY (ORCPT + 31 others); Fri, 7 Dec 2018 16:18:24 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:56405 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbeLGVSU (ORCPT ); Fri, 7 Dec 2018 16:18:20 -0500 Received: from wuerfel.lan ([109.192.41.194]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.129]) with ESMTPA (Nemesis) id 1MJV9M-1gkiXU0plQ-00Jp7U; Fri, 07 Dec 2018 22:18:12 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org Cc: linux-kernel@vger.kernel.org, Deepa Dinamani , John Stultz , Thomas Gleixner , linux-api@vger.kernel.org, Arnd Bergmann Subject: [PATCH 5/5] y2038: signal: Add compat_sys_rt_sigtimedwait_time64 Date: Fri, 7 Dec 2018 22:18:08 +0100 Message-Id: <20181207211808.328719-6-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181207211808.328719-1-arnd@arndb.de> References: <20181207211808.328719-1-arnd@arndb.de> X-Provags-ID: V03:K1:jaYEvBfisS0VH6w5saqRe9sT8/XD5lZ11dVe3XVzU/Ndgu+b6m/ 5f0AKwRVduUQJNEgwEsPlH1qf3xV07PTRj6bgLonKVxVhTvwXKjaTTEA74SzOUI88WlUGk4 DFvuQM4IUYcbVnhTuMZCrBwLvaZxJRCktBLK36xV/Piard5WrCAyioBdghpyNeu2eSTwoFi W3HCDot4zg0KIiunb8z4A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:/KDsyr0jmQw=:DqxU95dJYhhoXYeHZtYGXi g9Exk5h5cFbIecgVxX+9WCH07VLNbhZ1RyXnXiH4+Lw/uPt7So8SjfRvjZ37KSDMMMYDs0frx xvubZGF9wKeyRHsuLy5TPGRadoSCmAUprQAfKXENgZ6E84UxD4EQJh0XjOUEd5StKUO7aQPgm hgwqKiQuDzvXYl+Y83PH5fWO7VaD5C47yu6380li+xVe72uFYn92pK+giga4DTuYuRO8hURpg xz+f7xDUnGBD3RyiG1l88mujdC0cYtyiNbWQNBH0Vl1K0oeG8kZhQg92nIFxHeP+xCcXiTRbn QhAb/Zj6+B4c2gIZntpyHxZIP/hrImvH5rEc8bixo62C2LNJQ7JRXe68loV7oH+gpBqCfrmYJ 2xnkAuR0y+8LDaTQGNftp9XE/MyJKeE3NKT7tVr/UvHb5SC1h0TsCkQL/lZ6D9BWICFKuyO3H rhLIqHjV0jsjpf0fn5g8ueOuv1GY3jsiuT5nUALzxY8mEg1GSGWOlZ4biMizGKiCvkTnKeWdv kx3AGInoMpy6Ndqfc25+IDCPTDHRE0TjnjBFhywcmckzo10Eb1x4F9I6LkTBRIiOjg1ZnkBEf ff8BO9o20AmnzehQtNBJBQ3kKeQ/b9QuL9LHQ85GpxeNp6D21Tg48VdJKwvrIleRNVoGapBKY lD6JadOk5mCxaPRwvF1qL5fVrnhS9Bdx/b7xTzRF6uEsgptlYsgBE6uFS4mAjlfLerRRoXcrW cglDz0j240NbrKFgPvNZozatpUCdglVTXzsLww== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that 32-bit architectures have two variants of sys_rt_sigtimedwaid() for 32-bit and 64-bit time_t, we also need to have a second compat system call entry point on the corresponding 64-bit architectures. The traditional system call keeps getting handled by compat_sys_rt_sigtimedwait(), and this adds a new compat_sys_rt_sigtimedwait_time64() that differs only in the timeout argument type. The naming remains a bit asymmetric for the moment. Ideally we would want to have compat_sys_rt_sigtimedwait_time32() for the old version and compat_sys_rt_sigtimedwait() for the new one to mirror the names of the native entry points, but renaming the existing system call tables causes unnecessary churn. I would suggest renaming all such system calls together at a later point. Signed-off-by: Arnd Bergmann --- include/linux/compat.h | 3 +++ kernel/signal.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) -- 2.18.0 diff --git a/include/linux/compat.h b/include/linux/compat.h index 72969d303434..3bc5f218efd8 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -788,6 +788,9 @@ asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset, asmlinkage long compat_sys_rt_sigtimedwait(compat_sigset_t __user *uthese, struct compat_siginfo __user *uinfo, struct old_timespec32 __user *uts, compat_size_t sigsetsize); +asmlinkage long compat_sys_rt_sigtimedwait_time64(compat_sigset_t __user *uthese, + struct compat_siginfo __user *uinfo, + struct __kernel_timespec __user *uts, compat_size_t sigsetsize); asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig, struct compat_siginfo __user *uinfo); /* No generic prototype for rt_sigreturn */ diff --git a/kernel/signal.c b/kernel/signal.c index be6744cd0a11..53e07d97ffe0 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3366,6 +3366,37 @@ SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese, #endif #ifdef CONFIG_COMPAT +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese, + struct compat_siginfo __user *, uinfo, + struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize) +{ + sigset_t s; + struct timespec64 t; + kernel_siginfo_t info; + long ret; + + if (sigsetsize != sizeof(sigset_t)) + return -EINVAL; + + if (get_compat_sigset(&s, uthese)) + return -EFAULT; + + if (uts) { + if (get_timespec64(&t, uts)) + return -EFAULT; + } + + ret = do_sigtimedwait(&s, &info, uts ? &t : NULL); + + if (ret > 0 && uinfo) { + if (copy_siginfo_to_user32(uinfo, &info)) + ret = -EFAULT; + } + + return ret; +} + +#ifdef CONFIG_COMPAT_32BIT_TIME COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, struct compat_siginfo __user *, uinfo, struct old_timespec32 __user *, uts, compat_size_t, sigsetsize) @@ -3396,6 +3427,7 @@ COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, return ret; } #endif +#endif /** * sys_kill - send a signal to a process