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)  *  linux/kernel/compat.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Kernel compatibililty routines for e.g. 32 bit syscall support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  on 64 bit kernels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched.h>	/* for MAX_SCHEDULE_TIMEOUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/migrate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/posix-timers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef __ARCH_WANT_SYS_SIGPROCMASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * blocked set of signals to the supplied signal set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	memcpy(blocked->sig, &set, sizeof(set));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		       compat_old_sigset_t __user *, nset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		       compat_old_sigset_t __user *, oset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	old_sigset_t old_set, new_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	sigset_t new_blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	old_set = current->blocked.sig[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (nset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		if (get_user(new_set, nset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		new_blocked = current->blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		switch (how) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		case SIG_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			sigaddsetmask(&new_blocked, new_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		case SIG_UNBLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			sigdelsetmask(&new_blocked, new_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		case SIG_SETMASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			compat_sig_setmask(&new_blocked, new_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		set_current_blocked(&new_blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (oset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (put_user(old_set, oset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct compat_rusage r32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	memset(&r32, 0, sizeof(r32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	r32.ru_utime.tv_sec = r->ru_utime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	r32.ru_utime.tv_usec = r->ru_utime.tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	r32.ru_stime.tv_sec = r->ru_stime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	r32.ru_stime.tv_usec = r->ru_stime.tv_usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	r32.ru_maxrss = r->ru_maxrss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	r32.ru_ixrss = r->ru_ixrss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	r32.ru_idrss = r->ru_idrss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	r32.ru_isrss = r->ru_isrss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	r32.ru_minflt = r->ru_minflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	r32.ru_majflt = r->ru_majflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	r32.ru_nswap = r->ru_nswap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	r32.ru_inblock = r->ru_inblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	r32.ru_oublock = r->ru_oublock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	r32.ru_msgsnd = r->ru_msgsnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	r32.ru_msgrcv = r->ru_msgrcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	r32.ru_nsignals = r->ru_nsignals;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	r32.ru_nvcsw = r->ru_nvcsw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	r32.ru_nivcsw = r->ru_nivcsw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (copy_to_user(ru, &r32, sizeof(r32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return 0;
^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) static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				    unsigned len, struct cpumask *new_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	unsigned long *k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (len < cpumask_size())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		memset(new_mask, 0, cpumask_size());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	else if (len > cpumask_size())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		len = cpumask_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	k = cpumask_bits(new_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return compat_get_bitmap(k, user_mask_ptr, len * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		       unsigned int, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		       compat_ulong_t __user *, user_mask_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	cpumask_var_t new_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	retval = compat_get_user_cpu_mask(user_mask_ptr, len, new_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	retval = sched_setaffinity(pid, new_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	free_cpumask_var(new_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t,  pid, unsigned int, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		       compat_ulong_t __user *, user_mask_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	cpumask_var_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if ((len * BITS_PER_BYTE) < nr_cpu_ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (len & (sizeof(compat_ulong_t)-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ret = sched_getaffinity(pid, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		unsigned int retlen = min(len, cpumask_size());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			ret = retlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	free_cpumask_var(mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * We currently only need the following fields from the sigevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * structure: sigev_value, sigev_signo, sig_notify and (sometimes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * sigev_notify_thread_id).  The others are handled in user mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * We also assume that copying sigev_value.sival_int is sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * to keep all the bits of sigev_value.sival_ptr intact.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int get_compat_sigevent(struct sigevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		const struct compat_sigevent __user *u_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	memset(event, 0, sizeof(*event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return (!access_ok(u_event, sizeof(*u_event)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		__get_user(event->sigev_value.sival_int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			&u_event->sigev_value.sival_int) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		__get_user(event->sigev_signo, &u_event->sigev_signo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		__get_user(event->sigev_notify, &u_event->sigev_notify) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		__get_user(event->sigev_notify_thread_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			&u_event->sigev_notify_thread_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		       unsigned long bitmap_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	unsigned long nr_compat_longs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/* align bitmap up to nearest compat_long_t boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!user_read_access_begin(umask, bitmap_size / 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	while (nr_compat_longs > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		compat_ulong_t l1, l2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		unsafe_get_user(l1, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		unsafe_get_user(l2, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		*mask++ = ((unsigned long)l2 << BITS_PER_COMPAT_LONG) | l1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		nr_compat_longs -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (nr_compat_longs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		unsafe_get_user(*mask, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	user_read_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	user_read_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		       unsigned long bitmap_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned long nr_compat_longs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	/* align bitmap up to nearest compat_long_t boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (!user_write_access_begin(umask, bitmap_size / 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	while (nr_compat_longs > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		unsigned long m = *mask++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		unsafe_put_user((compat_ulong_t)m, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		unsafe_put_user(m >> BITS_PER_COMPAT_LONG, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		nr_compat_longs -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (nr_compat_longs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		unsafe_put_user((compat_ulong_t)*mask, umask++, Efault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	user_write_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) Efault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	user_write_access_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	compat_sigset_t v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (copy_from_user(&v, compat, sizeof(compat_sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	switch (_NSIG_WORDS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	case 4: set->sig[3] = v.sig[6] | (((long)v.sig[7]) << 32 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	case 3: set->sig[2] = v.sig[4] | (((long)v.sig[5]) << 32 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	case 2: set->sig[1] = v.sig[2] | (((long)v.sig[3]) << 32 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	case 1: set->sig[0] = v.sig[0] | (((long)v.sig[1]) << 32 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (copy_from_user(set, compat, sizeof(compat_sigset_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) EXPORT_SYMBOL_GPL(get_compat_sigset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * Allocate user-space memory for the duration of a single system call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * in order to marshall parameters inside a compat thunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) void __user *compat_alloc_user_space(unsigned long len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	void __user *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/* If len would occupy more than half of the entire compat space... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (unlikely(len > (((compat_uptr_t)~0) >> 1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ptr = arch_compat_alloc_user_space(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	if (unlikely(!access_ok(ptr, len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) EXPORT_SYMBOL_GPL(compat_alloc_user_space);