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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * sys_ipc() is the old de-multiplexer for the SysV IPC calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This is really horribly ugly, and new architectures should just wire up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the individual syscalls instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ipc_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #ifdef __ARCH_WANT_SYS_IPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ipc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/shm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) int ksys_ipc(unsigned int call, int first, unsigned long second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	unsigned long third, void __user * ptr, long fifth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int version, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	version = call >> 16; /* hack for backward compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	call &= 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	switch (call) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	case SEMOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		return ksys_semtimedop(first, (struct sembuf __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 				       second, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	case SEMTIMEDOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (IS_ENABLED(CONFIG_64BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			return ksys_semtimedop(first, ptr, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			        (const struct __kernel_timespec __user *)fifth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		else if (IS_ENABLED(CONFIG_COMPAT_32BIT_TIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			return compat_ksys_semtimedop(first, ptr, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			        (const struct old_timespec32 __user *)fifth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	case SEMGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return ksys_semget(first, second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	case SEMCTL: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		unsigned long arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		if (get_user(arg, (unsigned long __user *) ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return ksys_old_semctl(first, second, third, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case MSGSND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return ksys_msgsnd(first, (struct msgbuf __user *) ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				  second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	case MSGRCV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		case 0: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			struct ipc_kludge tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			if (copy_from_user(&tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 					   (struct ipc_kludge __user *) ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 					   sizeof(tmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			return ksys_msgrcv(first, tmp.msgp, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 					   tmp.msgtyp, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			return ksys_msgrcv(first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 					   (struct msgbuf __user *) ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 					   second, fifth, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	case MSGGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return ksys_msgget((key_t) first, second);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	case MSGCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return ksys_old_msgctl(first, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				   (struct msqid_ds __user *)ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	case SHMAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		default: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			unsigned long raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			ret = do_shmat(first, (char __user *)ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				       second, &raddr, SHMLBA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			return put_user(raddr, (unsigned long __user *) third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			 * This was the entry point for kernel-originating calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			 * from iBCS2 in 2.2 days.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	case SHMDT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return ksys_shmdt((char __user *)ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case SHMGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return ksys_shmget(first, second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case SHMCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return ksys_old_shmctl(first, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				   (struct shmid_ds __user *) ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		unsigned long, third, void __user *, ptr, long, fifth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return ksys_ipc(call, first, second, third, ptr, fifth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ifndef COMPAT_SHMLBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define COMPAT_SHMLBA	SHMLBA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct compat_ipc_kludge {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	compat_uptr_t msgp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	compat_long_t msgtyp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int compat_ksys_ipc(u32 call, int first, int second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u32 third, compat_uptr_t ptr, u32 fifth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	u32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	version = call >> 16; /* hack for backward compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	call &= 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	switch (call) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	case SEMOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		/* struct sembuf is the same on 32 and 64bit :)) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return ksys_semtimedop(first, compat_ptr(ptr), second, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	case SEMTIMEDOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		if (!IS_ENABLED(CONFIG_COMPAT_32BIT_TIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return compat_ksys_semtimedop(first, compat_ptr(ptr), second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 						compat_ptr(fifth));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	case SEMGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return ksys_semget(first, second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case SEMCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		if (get_user(pad, (u32 __user *) compat_ptr(ptr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return compat_ksys_old_semctl(first, second, third, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	case MSGSND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return compat_ksys_msgsnd(first, ptr, second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	case MSGRCV: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		void __user *uptr = compat_ptr(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (first < 0 || second < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (!version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			struct compat_ipc_kludge ipck;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			if (!uptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			if (copy_from_user(&ipck, uptr, sizeof(ipck)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			return compat_ksys_msgrcv(first, ipck.msgp, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 						 ipck.msgtyp, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return compat_ksys_msgrcv(first, ptr, second, fifth, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	case MSGGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return ksys_msgget(first, second);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	case MSGCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return compat_ksys_old_msgctl(first, second, compat_ptr(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	case SHMAT: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		unsigned long raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (version == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		err = do_shmat(first, compat_ptr(ptr), second, &raddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			       COMPAT_SHMLBA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	case SHMDT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return ksys_shmdt(compat_ptr(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	case SHMGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return ksys_shmget(first, (unsigned int)second, third);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case SHMCTL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return compat_ksys_old_shmctl(first, second, compat_ptr(ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	u32, third, compat_uptr_t, ptr, u32, fifth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return compat_ksys_ipc(call, first, second, third, ptr, fifth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif