From patchwork Wed Apr 25 16:03: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: 134358 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1051912lji; Wed, 25 Apr 2018 09:05:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx48PdZv89IXPu1m1Q+n+0ucxRTnsTvC+YSxrumcsggp1QbJ67gTp89thcax+sOaCeLsKW1cP X-Received: by 2002:a17:902:aa94:: with SMTP id d20-v6mr30705882plr.323.1524672356477; Wed, 25 Apr 2018 09:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524672356; cv=none; d=google.com; s=arc-20160816; b=wJV1PQ9ogvXjSTT2PiEYe7Bjvj09L0Vq9kWvXhw0rRb73SystEtTa9dpNvoWI++Ms3 P6XaBoMipynkP0E83v+dAeYyx+1qkmcvWqXKByGFSRVnE15uvaGyZ55I/JGGDOqPjrVw ep3pq6/2Ds7Xgmm8fMvgWjZf7dM6Ez/vxJkQmf315PBV5AqJICAs2q6iTSjw/Uuu6NzW eLAZZcQOqddKRrM+hbyjPVwYebqUJG63ToEq0fgmSpIYCXKB0/ISCAKbk9X8+gHA7sEL ZxXekyYrlx5IKIr6gQL66lor+1sxYhybq3Xd3myl2VETcxTc1Mia+jJRMxbq/vt8hyOb /jYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :delivered-to:sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=egcI5QX9cF6aF69pSWTBzGBhElnQuCGDbXZFRtMJYSA=; b=ndnFS31YegaXDnUsu1dMeACzHob/Xsjr5Ga3wQ0kJt1wvKLA7+bU9Dj8IDk2g7Ks3L t+kaWS3VcsK7uVwVx1ghz6w8AdMAvqEsl8tjnnHMGoDN7p/0UPjxRxXhw63BczigaClW F67YSRnBbI4plJFnuW0+uEGZpoppZQcEQTihMl/sI/9Tzde+dCmT3mmPnBV/wGRZem3O kxmAKX5VXJrQX4h6tVys/03+waYgPhZcHbd7fhEFWRG5juPTwTMqeJkjA7R9AzfsGEE4 i4/XAmylVgZ0kbR6c7YihciDsxj6BKZ+obH4H5czkxu/pn52qH1oY1wVszxFPxdb0vZz G9fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EA2N3UYm; spf=pass (google.com: domain of libc-alpha-return-91848-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-91848-patch=linaro.org@sourceware.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id z196si13894429pgz.349.2018.04.25.09.05.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 09:05:56 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-91848-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EA2N3UYm; spf=pass (google.com: domain of libc-alpha-return-91848-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-91848-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=fZPSm9qS/lLNpV8S7TaMuOCzvkZdLg4 FK7LK555KglXhcg5wCfDQAV3eqnQPG1elbvyCKgiSOQUM2UJdP5R5iWYyE7mZ+cp bKMLDY1Q/DAY63whMTxx2Ls0PlTT6suNnLlifjAEdJwnNm4uBA6ZSJlllWce1pFU lfYOCG0iJpgA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=uxX7cPbonYGZXvt6XiTDUBefwF4=; b=EA2N3 UYmV+7clC9tFnFYtI1pYCx/cgN8s3UxQcR+TtQOgagCZLjBaQcUgRzoodJG/EHH+ vhZ3rbmYKGw0Ki6NERc18bEyVBshNnZPfJpVpLapljXakR/NJlzJsckSPjM5ly4e hF9cWcV/x1apd6grk4hsM9pfjC21dbtdhn1XhA= Received: (qmail 61179 invoked by alias); 25 Apr 2018 16:05:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 61045 invoked by uid 89); 25 Apr 2018 16:05:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mout.kundenserver.de 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 14/17] y2038: socket: Add compat_sys_recvmmsg_time64 Date: Wed, 25 Apr 2018 18:03:08 +0200 Message-Id: <20180425160311.2718314-15-arnd@arndb.de> In-Reply-To: <20180425160311.2718314-1-arnd@arndb.de> References: <20180425160311.2718314-1-arnd@arndb.de> X-UI-Out-Filterresults: notjunk:1; V01:K0:hsOUounq7to=:uBmn6NOvgVy5KCUbgV6WyK 2CQPwZgE6lIv32HwyOMHt4pNl5RTjNwCjIPNIpBkChqAEwFVXybyE67DFtyE42rXAn41tLxSi M37s4LR3JPdaibYA60OIgH6HXD4P8yvZEt5ryLycKAPgSOBuWI9+sNIv7eF9Frnf2tGETSn57 SXUnRne4yRq1ZEk7PD3KcYvrD72aHgc0jLqACxkc0gHOUeWi9aaLlq4cd6uW8hE8rzIIas5BP wi6EZXawItA5UYe5+QxyaZnbJRQ2eRyauqWc57bN7elZZG72NNDzUuS89Nujc/vIZIJmmUGsH mmKi5jdVpLIIphAYGprZMt72j+4wpXwN2AEQ/l4OflA1CAm9P3ZvsTLdUU8snFx8cCydWl0xe cCCu28tHMFMm2k+d88iAo8cYhhvSEznWdHqDgF+N6pX+0C5w9bW1b+AimgHHa4r5IqHIqevZd J42gJgQL5QbCskMEWCEVezOexhJxgB2vKg9P2rnP32FWz6WJiub093eAk2BoFMQRESR3uo24/ Cwejs/CKOlVjQqgrVoUQJ/VEsN2NyuydKL36VKubnMa2YvWyQTEEHFEpidpF+3iVekJM5Akau LZ4PMwGlj1EuoWuSy3Z7EiZjWiot3RllhttLuo9efPhx65rc3tE/5f0H2jJcsTAL4IDn45Okf I/Cq24X4YTYf0WxsQiZvdG3cTrliFJVxTzIKiqbm38gswfvB7OZfqm+41mYVMryNtVW8= 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. Signed-off-by: Arnd Bergmann --- include/linux/compat.h | 5 ++++- include/linux/socket.h | 15 ++++++++++++++- kernel/sys_ni.c | 1 + net/compat.c | 14 +++++++------- net/socket.c | 39 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 63 insertions(+), 11 deletions(-) -- 2.9.0 diff --git a/include/linux/compat.h b/include/linux/compat.h index 7887b0a54c1e..f9423bbf7e7c 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -863,7 +863,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 compat_timespec __user *timeout); asmlinkage long compat_sys_wait4(compat_pid_t pid, diff --git a/include/linux/socket.h b/include/linux/socket.h index d36a6c1bdbaf..22358e0e1288 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -2,8 +2,8 @@ #ifndef _LINUX_SOCKET_H #define _LINUX_SOCKET_H - #include /* arch-dependent defines */ +#include #include /* the SIOCxxx I/O controls */ #include /* iovec support */ #include /* pid_t */ @@ -346,6 +346,7 @@ extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_sto extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data); struct timespec64; +struct compat_timespec; /* The __sys_...msg variants allow MSG_CMSG_COMPAT iff * forbid_cmsg_compat==false @@ -356,6 +357,18 @@ 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); +#ifdef CONFIG_COMPAT_32BIT_TIME +extern int __compat_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct compat_timespec __user *timeout); +#else +static inline int __compat_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct compat_timespec __user *timeout) +{ + return -EINVAL; +} +#endif extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags, bool forbid_cmsg_compat); diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 9791364925dc..61fc9babe6ce 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -283,6 +283,7 @@ COND_SYSCALL(perf_event_open); COND_SYSCALL(accept4); COND_SYSCALL(recvmmsg); 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 93b80a3d967c..7521a0afe18d 100644 --- a/net/compat.c +++ b/net/compat.c @@ -810,9 +810,9 @@ 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, +static int __compat_sys_recvmmsg_time64(int fd, struct compat_mmsghdr __user *mmsg, unsigned int vlen, unsigned int flags, - struct compat_timespec __user *timeout) + struct __kernel_timespec __user *timeout) { int datagrams; struct timespec64 ktspec; @@ -821,22 +821,22 @@ static int __compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg, return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen, flags | MSG_CMSG_COMPAT, NULL); - if (compat_get_timespec64(&ktspec, timeout)) + if (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)) + if (datagrams > 0 && put_timespec64(&ktspec, timeout)) datagrams = -EFAULT; return datagrams; } -COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg, +COMPAT_SYSCALL_DEFINE5(recvmmsg_time64, int, fd, struct compat_mmsghdr __user *, mmsg, unsigned int, vlen, unsigned int, flags, - struct compat_timespec __user *, timeout) + struct __kernel_timespec __user *, timeout) { - return __compat_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); + return __compat_sys_recvmmsg_time64(fd, mmsg, vlen, flags, timeout); } COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args) diff --git a/net/socket.c b/net/socket.c index 4510e6269764..5e97b645bfee 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2483,6 +2483,37 @@ SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, return do_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); } +#ifdef CONFIG_COMPAT_32BIT_TIME +int __compat_sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, + unsigned int vlen, unsigned int flags, + struct compat_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; +} + +COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, + unsigned int, vlen, unsigned int, flags, + struct compat_timespec __user *, timeout) +{ + return __compat_sys_recvmmsg(fd, mmsg, vlen, flags, timeout); +} +#endif + #ifdef __ARCH_WANT_SYS_SOCKETCALL /* Argument list sizes for sys_socketcall */ #define AL(x) ((x) * sizeof(unsigned long)) @@ -2600,8 +2631,12 @@ 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 = do_sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], + a[3], (struct __kernel_timespec __user *)a[4]); + else + err = __compat_sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], + a[3], (struct compat_timespec __user *)a[4]); break; case SYS_ACCEPT4: err = __sys_accept4(a0, (struct sockaddr __user *)a1,