From patchwork Mon Jul 16 16:11:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 142049 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2604290ljj; Mon, 16 Jul 2018 09:12:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfsB0qTi2rEpkLneoim5tRksazJd/+O7sijSeA1z7zwr0IHs+61Pt6ng99Rox4dnCD/pcPy X-Received: by 2002:a62:57dc:: with SMTP id i89-v6mr18662144pfj.65.1531757535201; Mon, 16 Jul 2018 09:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531757535; cv=none; d=google.com; s=arc-20160816; b=cK/S3dSET5VMhRSnVsyVm4gdXcdAGGpfqkMjvfcJD6GybOe2GKM3oIkJnU2tLqHd7I +lIdppYc+E+HSTLC3q2QoDEiCmU3ZJOCa8Zurl1dxXuSCN+7CquzZobzd5EA+LMk9dd6 19nVBjEnQ/sk9p7WitE2aH24kt85CLzM8f/5VcWf/H84Q/gIHJzAnOQeciZUQECzxRgI UcaczZk+J0s6JUDRIwNReAPsIrGy9kCQxuW7epoq6eMwxGrgGxE/wDpgtMIc/rv/K2uj nQrcBHF75rdIER4fQwpZJx2tAIGclbOqanUZPDVWx4UgNHUFo5op8mUOBpob6FlTQAwP op0A== 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=W9TyeCWG9I51J9sblrkiEmSH42YxmcOdv1Q5qDUnaZI=; b=BpVuz/KuVE+Xcwoj5f0yJ6Js8y7dhRsooPTd3qXKbSj/jSHgFqdqGyqQGyVhDqJUwT Kgwg8VT5EoWwaBPq8IrADeXNTOZLDwqzDtLKSCicjChBYZKSipuaTTPEATvO62+LB7Rt 4JyzFfRygdm+x0UaXGbXG/KclJbTVgRKJs0853TG18kIyHUKS2RgroSknrWfcLfJDPBn P/j/7qjAHmWXCDK65/hnAxkJr3O+lyvHnSKmPCtDaNZdJYZgmq6yKLgxAsRmTqRCVLUx qTmgdsEfElBtz4vbiFGkkBPcAjZz6qUsJ0E6l8CDQTc8mOXLNQ7pbfDHV1xAKvpy08HJ eUUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 x18-v6si30410996pfh.84.2018.07.16.09.12.14; Mon, 16 Jul 2018 09:12:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731228AbeGPQkT (ORCPT + 10 others); Mon, 16 Jul 2018 12:40:19 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:37721 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731178AbeGPQkT (ORCPT ); Mon, 16 Jul 2018 12:40:19 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue007 [212.227.15.129]) with ESMTPA (Nemesis) id 0MTrXg-1fWGP32aG0-00QXBW; Mon, 16 Jul 2018 18:11:13 +0200 From: Arnd Bergmann To: tglx@linutronix.de Cc: y2038@lists.linaro.org, hch@infradead.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, libc-alpha@sourceware.org, albert.aribaud@3adev.fr, netdev@vger.kernel.org, viro@zeniv.linux.org.uk, peterz@infradead.org, dvhart@infradead.org, ebiederm@xmission.com, linux@dominikbrodowski.net, Arnd Bergmann Subject: [PATCH v2 14/17] y2038: socket: Add compat_sys_recvmmsg_time64 Date: Mon, 16 Jul 2018 18:11:00 +0200 Message-Id: <20180716161103.16239-15-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180716161103.16239-1-arnd@arndb.de> References: <20180716161103.16239-1-arnd@arndb.de> X-Provags-ID: V03:K1:sqMhgMKuO7X7VSSFswGJblrWZxPOOy6aMZe20r/MUJGT+wTW9Us AiMg98uaZdpx1xG5Qyx58SgYdK58soBG/+A2Hkt38/xBFP3O8dlpDHVyBBu1qHcj/RoOqTX q4YqW9xwxKqVH2ZwzKFEXXLUjIdsvKiOLS+eqn5MK1VLO4J6lG4j4upVTJj3wWetIqErG1Z fh4m4IDNUmsDEksbm6xXQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:qPF2d23m6d4=:UqY0JiXjsXnEN4PGdNrF64 o9yGd7Gj2KRkyssyFaodth11WuiuipipP+iRPxjb/OHBLiu0B2ggFWjMjd4w0MbcrCrjdcYMc oZsjbANl/tocvpR+9Vd+bXYHEMoWA+KdGAGHg1BrRbrBhWH69gIn0rymlmmcSywcgzIcfr468 RGSFXhoW71C5q7X+MWJIdsw00YoBW8LrTO2C8TjXqRdAV2bjyM0xW6hrp2LwdC7p5nUYpfSPY b21NBdKO2DAJStUcjBuKxAQhurw+AshnEhBDtO8ozRyOpqhdZ5TcImpWmei1r7Kmu35+UHyyt q5XlVS0uYlLVBGIUKYoM8S03Ixoz0Mel/wQN0z+nX/3DgyYk1X0axF5sCBkW1m4KZF1JOOulj 1S7iYBLFlh+ReGjsom16rTCHo8UDCfmo6gBW6IKBlvnKNF01+xnT1hzrqWuQucTg4nsHrKMrn VvK78tQnJwbJviMtQzO0WgukKLWR/C+Xx0CMC/fNOCNAR4lNrgPUMdzA/Ob30H+5nu8F1fZyE 3n1B6t/q46QKMgWU9wfQQPzXYvXlvcFMDg0wEurQqpaqUW/Almw3ciLoVei/aLD15ge/MyyaQ VDo3JRW9Ymc1XjAMN+ZbWexDXzpih9oHwZ2tJulEVUKYDO70iQ3z2XMBoGbYa36WdscbAuJdY ta9KdPp1X1e8rSMY3oKgHtVtm/rQJ/kPPakVnLVwoYHZoNgtm7qlh09/fcklsY39rhz8= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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. 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 ab0b1f48dc5b..0ede0543b84f 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -867,7 +867,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 8b571e9b9f76..65b8db095f1d 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 */ @@ -349,6 +349,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 @@ -359,6 +360,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 df556175be50..c3fdba58565a 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -285,6 +285,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 0380fbb9a321..5af2af1b9723 100644 --- a/net/compat.c +++ b/net/compat.c @@ -812,9 +812,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; @@ -823,22 +823,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 c0838a278cfd..f4b6be81c6af 100644 --- a/net/socket.c +++ b/net/socket.c @@ -2473,6 +2473,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)) @@ -2590,8 +2621,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,