Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * 32bit Socket syscall emulation. Based on arch/sparc64/kernel/sys_sparc32.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2000		VA Linux Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2000		Don Dugger <n0ano@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 1999 		Arun Sharma <arun.sharma@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 1997,1998 	Jakub Jelinek (jj@sunsite.mff.cuni.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 1997 		David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 2000		Hewlett-Packard Co.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 2000		David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Copyright (C) 2000,2001	Andi Kleen, SuSE Labs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/filter.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <net/scm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <net/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int __get_compat_msghdr(struct msghdr *kmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			struct compat_msghdr __user *umsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			struct sockaddr __user **save_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			compat_uptr_t *ptr, compat_size_t *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct compat_msghdr msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (copy_from_user(&msg, umsg, sizeof(*umsg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	kmsg->msg_flags = msg.msg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	kmsg->msg_namelen = msg.msg_namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (!msg.msg_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		kmsg->msg_namelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (kmsg->msg_namelen < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		kmsg->msg_namelen = sizeof(struct sockaddr_storage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	kmsg->msg_control_is_user = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	kmsg->msg_control_user = compat_ptr(msg.msg_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	kmsg->msg_controllen = msg.msg_controllen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (save_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		*save_addr = compat_ptr(msg.msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (msg.msg_name && kmsg->msg_namelen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (!save_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			err = move_addr_to_kernel(compat_ptr(msg.msg_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 						  kmsg->msg_namelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 						  kmsg->msg_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		kmsg->msg_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		kmsg->msg_namelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (msg.msg_iovlen > UIO_MAXIOV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	kmsg->msg_iocb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	*ptr = msg.msg_iov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	*len = msg.msg_iovlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) int get_compat_msghdr(struct msghdr *kmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		      struct compat_msghdr __user *umsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		      struct sockaddr __user **save_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		      struct iovec **iov)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	compat_uptr_t ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	compat_size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	err = __get_compat_msghdr(kmsg, umsg, save_addr, &ptr, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	err = import_iovec(save_addr ? READ : WRITE, compat_ptr(ptr), len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			   UIO_FASTIOV, iov, &kmsg->msg_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return err < 0 ? err : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Bleech... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define CMSG_COMPAT_ALIGN(len)	ALIGN((len), sizeof(s32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define CMSG_COMPAT_DATA(cmsg)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	((void __user *)((char __user *)(cmsg) + sizeof(struct compat_cmsghdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define CMSG_COMPAT_SPACE(len)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	(sizeof(struct compat_cmsghdr) + CMSG_COMPAT_ALIGN(len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define CMSG_COMPAT_LEN(len)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	(sizeof(struct compat_cmsghdr) + (len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define CMSG_COMPAT_FIRSTHDR(msg)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	(((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ?	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 (struct compat_cmsghdr __user *)((msg)->msg_control) :		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 (struct compat_cmsghdr __user *)NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	((ucmlen) >= sizeof(struct compat_cmsghdr) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 (ucmlen) <= (unsigned long) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 ((mhdr)->msg_controllen - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	  ((char __user *)(ucmsg) - (char __user *)(mhdr)->msg_control_user)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		struct compat_cmsghdr __user *cmsg, int cmsg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			msg->msg_controllen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	return (struct compat_cmsghdr __user *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* There is a lot of hair here because the alignment rules (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * thus placement) of cmsg headers and length are different for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * 32-bit apps.  -DaveM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int cmsghdr_from_user_compat_to_kern(struct msghdr *kmsg, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			       unsigned char *stackbuf, int stackbuf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct compat_cmsghdr __user *ucmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct cmsghdr *kcmsg, *kcmsg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	compat_size_t ucmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	__kernel_size_t kcmlen, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	int err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	BUILD_BUG_ON(sizeof(struct compat_cmsghdr) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		     CMSG_COMPAT_ALIGN(sizeof(struct compat_cmsghdr)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	kcmlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kcmsg_base = kcmsg = (struct cmsghdr *)stackbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	while (ucmsg != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (get_user(ucmlen, &ucmsg->cmsg_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		/* Catch bogons. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (!CMSG_COMPAT_OK(ucmlen, ucmsg, kmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		tmp = ((ucmlen - sizeof(*ucmsg)) + sizeof(struct cmsghdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		tmp = CMSG_ALIGN(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		kcmlen += tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, ucmlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (kcmlen == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* The kcmlen holds the 64-bit version of the control length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * It may not be modified as we do not stick it into the kmsg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * until we have successfully copied over all of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * from the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (kcmlen > stackbuf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		kcmsg_base = kcmsg = sock_kmalloc(sk, kcmlen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (kcmsg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/* Now copy them over neatly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	memset(kcmsg, 0, kcmlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	ucmsg = CMSG_COMPAT_FIRSTHDR(kmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	while (ucmsg != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		struct compat_cmsghdr cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		if (copy_from_user(&cmsg, ucmsg, sizeof(cmsg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			goto Efault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (!CMSG_COMPAT_OK(cmsg.cmsg_len, ucmsg, kmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			goto Einval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		tmp = ((cmsg.cmsg_len - sizeof(*ucmsg)) + sizeof(struct cmsghdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if ((char *)kcmsg_base + kcmlen - (char *)kcmsg < CMSG_ALIGN(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			goto Einval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		kcmsg->cmsg_len = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		kcmsg->cmsg_level = cmsg.cmsg_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		kcmsg->cmsg_type = cmsg.cmsg_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		tmp = CMSG_ALIGN(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		if (copy_from_user(CMSG_DATA(kcmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				   CMSG_COMPAT_DATA(ucmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 				   (cmsg.cmsg_len - sizeof(*ucmsg))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			goto Efault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		/* Advance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		kcmsg = (struct cmsghdr *)((char *)kcmsg + tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ucmsg = cmsg_compat_nxthdr(kmsg, ucmsg, cmsg.cmsg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 * check the length of messages copied in is the same as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 * what we get from the first loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if ((char *)kcmsg - (char *)kcmsg_base != kcmlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		goto Einval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	/* Ok, looks like we made it.  Hook it up and return success. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	kmsg->msg_control = kcmsg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	kmsg->msg_controllen = kcmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) Einval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (kcmsg_base != (struct cmsghdr *)stackbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		sock_kfree_s(sk, kcmsg_base, kcmlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct compat_cmsghdr cmhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct old_timeval32 ctv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct old_timespec32 cts[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	int cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (cm == NULL || kmsg->msg_controllen < sizeof(*cm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		kmsg->msg_flags |= MSG_CTRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return 0; /* XXX: return error? check spec. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (!COMPAT_USE_64BIT_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (level == SOL_SOCKET && type == SO_TIMESTAMP_OLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			struct __kernel_old_timeval *tv = (struct __kernel_old_timeval *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			ctv.tv_sec = tv->tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			ctv.tv_usec = tv->tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			data = &ctv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			len = sizeof(ctv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (level == SOL_SOCKET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		    (type == SO_TIMESTAMPNS_OLD || type == SO_TIMESTAMPING_OLD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			int count = type == SO_TIMESTAMPNS_OLD ? 1 : 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			struct __kernel_old_timespec *ts = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				cts[i].tv_sec = ts[i].tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 				cts[i].tv_nsec = ts[i].tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			data = &cts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			len = sizeof(cts[0]) * count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	cmlen = CMSG_COMPAT_LEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (kmsg->msg_controllen < cmlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		kmsg->msg_flags |= MSG_CTRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		cmlen = kmsg->msg_controllen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	cmhdr.cmsg_level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	cmhdr.cmsg_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	cmhdr.cmsg_len = cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (copy_to_user(CMSG_COMPAT_DATA(cm), data, cmlen - sizeof(struct compat_cmsghdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	cmlen = CMSG_COMPAT_SPACE(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (kmsg->msg_controllen < cmlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		cmlen = kmsg->msg_controllen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	kmsg->msg_control += cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	kmsg->msg_controllen -= cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int scm_max_fds_compat(struct msghdr *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (msg->msg_controllen <= sizeof(struct compat_cmsghdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return (msg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct compat_cmsghdr __user *cm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		(struct compat_cmsghdr __user *)msg->msg_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	unsigned int o_flags = (msg->msg_flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int fdmax = min_t(int, scm_max_fds_compat(msg), scm->fp->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	int __user *cmsg_data = CMSG_COMPAT_DATA(cm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int err = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	for (i = 0; i < fdmax; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		err = receive_fd_user(scm->fp->fp[i], cmsg_data + i, o_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (i > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		int cmlen = CMSG_COMPAT_LEN(i * sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		err = put_user(SOL_SOCKET, &cm->cmsg_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			err = put_user(SCM_RIGHTS, &cm->cmsg_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			err = put_user(cmlen, &cm->cmsg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			if (msg->msg_controllen < cmlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				cmlen = msg->msg_controllen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			msg->msg_control += cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			msg->msg_controllen -= cmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (i < scm->fp->count || (scm->fp->count && fdmax <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		msg->msg_flags |= MSG_CTRUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 * All of the files that fit in the message have had their usage counts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	 * incremented, so we just free the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	__scm_destroy(scm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* Argument list sizes for compat_sys_socketcall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #define AL(x) ((x) * sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static unsigned char nas[21] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	AL(4), AL(5), AL(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #undef AL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static inline long __compat_sys_sendmsg(int fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 					struct compat_msghdr __user *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return __sys_sendmsg(fd, (struct user_msghdr __user *)msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			     flags | MSG_CMSG_COMPAT, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		       unsigned int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return __compat_sys_sendmsg(fd, msg, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static inline long __compat_sys_sendmmsg(int fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 					 struct compat_mmsghdr __user *mmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 					 unsigned int vlen, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			      flags | MSG_CMSG_COMPAT, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		       unsigned int, vlen, unsigned int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	return __compat_sys_sendmmsg(fd, mmsg, vlen, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) static inline long __compat_sys_recvmsg(int fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 					struct compat_msghdr __user *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 					unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return __sys_recvmsg(fd, (struct user_msghdr __user *)msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			     flags | MSG_CMSG_COMPAT, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		       unsigned int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return __compat_sys_recvmsg(fd, msg, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static inline long __compat_sys_recvfrom(int fd, void __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 					 compat_size_t len, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					 struct sockaddr __user *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 					 int __user *addrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			      addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, unsigned int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	return __compat_sys_recvfrom(fd, buf, len, flags, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		       unsigned int, flags, struct sockaddr __user *, addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		       int __user *, addrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) COMPAT_SYSCALL_DEFINE5(recvmmsg_time64, int, fd, struct compat_mmsghdr __user *, mmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		       unsigned int, vlen, unsigned int, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		       struct __kernel_timespec __user *, timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			      flags | MSG_CMSG_COMPAT, timeout, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #ifdef CONFIG_COMPAT_32BIT_TIME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) COMPAT_SYSCALL_DEFINE5(recvmmsg_time32, int, fd, struct compat_mmsghdr __user *, mmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		       unsigned int, vlen, unsigned int, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		       struct old_timespec32 __user *, timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			      flags | MSG_CMSG_COMPAT, NULL, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	u32 a[AUDITSC_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	u32 a0, a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (call < SYS_SOCKET || call > SYS_SENDMMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	len = nas[call];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (len > sizeof(a))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (copy_from_user(a, args, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	ret = audit_socketcall_compat(len / sizeof(a[0]), a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	a0 = a[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	a1 = a[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	switch (call) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	case SYS_SOCKET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		ret = __sys_socket(a0, a1, a[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	case SYS_BIND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		ret = __sys_bind(a0, compat_ptr(a1), a[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	case SYS_CONNECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		ret = __sys_connect(a0, compat_ptr(a1), a[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	case SYS_LISTEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		ret = __sys_listen(a0, a1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	case SYS_ACCEPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	case SYS_GETSOCKNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ret = __sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	case SYS_GETPEERNAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		ret = __sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	case SYS_SOCKETPAIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		ret = __sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	case SYS_SEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		ret = __sys_sendto(a0, compat_ptr(a1), a[2], a[3], NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	case SYS_SENDTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		ret = __sys_sendto(a0, compat_ptr(a1), a[2], a[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				   compat_ptr(a[4]), a[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	case SYS_RECV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 					    NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	case SYS_RECVFROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 					    compat_ptr(a[4]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 					    compat_ptr(a[5]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	case SYS_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		ret = __sys_shutdown(a0, a1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	case SYS_SETSOCKOPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		ret = __sys_setsockopt(a0, a1, a[2], compat_ptr(a[3]), a[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	case SYS_GETSOCKOPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		ret = __sys_getsockopt(a0, a1, a[2], compat_ptr(a[3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				       compat_ptr(a[4]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	case SYS_SENDMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		ret = __compat_sys_sendmsg(a0, compat_ptr(a1), a[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	case SYS_SENDMMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		ret = __compat_sys_sendmmsg(a0, compat_ptr(a1), a[2], a[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	case SYS_RECVMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		ret = __compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	case SYS_RECVMMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		ret = __sys_recvmmsg(a0, compat_ptr(a1), a[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				     a[3] | MSG_CMSG_COMPAT, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 				     compat_ptr(a[4]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	case SYS_ACCEPT4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }