xref: /linux/arch/sparc/kernel/sys_sparc32.c (revision 9d5b7c956b09daab955fb2a42447d5d89ff15093)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a88b5ba8SSam Ravnborg /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
3a88b5ba8SSam Ravnborg  *
4a88b5ba8SSam Ravnborg  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5a88b5ba8SSam Ravnborg  * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
6a88b5ba8SSam Ravnborg  *
7a88b5ba8SSam Ravnborg  * These routines maintain argument size conversion between 32bit and 64bit
8a88b5ba8SSam Ravnborg  * environment.
9a88b5ba8SSam Ravnborg  */
10a88b5ba8SSam Ravnborg 
11a88b5ba8SSam Ravnborg #include <linux/kernel.h>
12a88b5ba8SSam Ravnborg #include <linux/sched.h>
13a88b5ba8SSam Ravnborg #include <linux/capability.h>
14a88b5ba8SSam Ravnborg #include <linux/fs.h>
15a88b5ba8SSam Ravnborg #include <linux/mm.h>
16a88b5ba8SSam Ravnborg #include <linux/file.h>
17a88b5ba8SSam Ravnborg #include <linux/signal.h>
18a88b5ba8SSam Ravnborg #include <linux/resource.h>
19a88b5ba8SSam Ravnborg #include <linux/times.h>
20a88b5ba8SSam Ravnborg #include <linux/smp.h>
21a88b5ba8SSam Ravnborg #include <linux/sem.h>
22a88b5ba8SSam Ravnborg #include <linux/msg.h>
23a88b5ba8SSam Ravnborg #include <linux/shm.h>
24a88b5ba8SSam Ravnborg #include <linux/uio.h>
25a88b5ba8SSam Ravnborg #include <linux/nfs_fs.h>
26a88b5ba8SSam Ravnborg #include <linux/quota.h>
27a88b5ba8SSam Ravnborg #include <linux/poll.h>
28a88b5ba8SSam Ravnborg #include <linux/personality.h>
29a88b5ba8SSam Ravnborg #include <linux/stat.h>
30a88b5ba8SSam Ravnborg #include <linux/filter.h>
31a88b5ba8SSam Ravnborg #include <linux/highmem.h>
32a88b5ba8SSam Ravnborg #include <linux/highuid.h>
33a88b5ba8SSam Ravnborg #include <linux/mman.h>
34a88b5ba8SSam Ravnborg #include <linux/ipv6.h>
35a88b5ba8SSam Ravnborg #include <linux/in.h>
36a88b5ba8SSam Ravnborg #include <linux/icmpv6.h>
37a88b5ba8SSam Ravnborg #include <linux/syscalls.h>
38a88b5ba8SSam Ravnborg #include <linux/sysctl.h>
39a88b5ba8SSam Ravnborg #include <linux/binfmts.h>
40a88b5ba8SSam Ravnborg #include <linux/dnotify.h>
41a88b5ba8SSam Ravnborg #include <linux/security.h>
42a88b5ba8SSam Ravnborg #include <linux/compat.h>
43a88b5ba8SSam Ravnborg #include <linux/vfs.h>
44a88b5ba8SSam Ravnborg #include <linux/ptrace.h>
455a0e3ad6STejun Heo #include <linux/slab.h>
46a88b5ba8SSam Ravnborg 
47a88b5ba8SSam Ravnborg #include <asm/types.h>
487c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
49a88b5ba8SSam Ravnborg #include <asm/fpumacro.h>
50a88b5ba8SSam Ravnborg #include <asm/mmu_context.h>
51a88b5ba8SSam Ravnborg #include <asm/compat_signal.h>
52a88b5ba8SSam Ravnborg 
53ed8eb755SSam Ravnborg #include "systbls.h"
54ed8eb755SSam Ravnborg 
55a88b5ba8SSam Ravnborg asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
56a88b5ba8SSam Ravnborg {
57a88b5ba8SSam Ravnborg 	if ((int)high < 0)
58a88b5ba8SSam Ravnborg 		return -EINVAL;
59a88b5ba8SSam Ravnborg 	else
60df260e21SDominik Brodowski 		return ksys_truncate(path, (high << 32) | low);
61a88b5ba8SSam Ravnborg }
62a88b5ba8SSam Ravnborg 
63a88b5ba8SSam Ravnborg asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
64a88b5ba8SSam Ravnborg {
65a88b5ba8SSam Ravnborg 	if ((int)high < 0)
66a88b5ba8SSam Ravnborg 		return -EINVAL;
67a88b5ba8SSam Ravnborg 	else
68411d9475SDominik Brodowski 		return ksys_ftruncate(fd, (high << 32) | low);
69a88b5ba8SSam Ravnborg }
70a88b5ba8SSam Ravnborg 
71a88b5ba8SSam Ravnborg static int cp_compat_stat64(struct kstat *stat,
72a88b5ba8SSam Ravnborg 			    struct compat_stat64 __user *statbuf)
73a88b5ba8SSam Ravnborg {
74a88b5ba8SSam Ravnborg 	int err;
75a88b5ba8SSam Ravnborg 
76a88b5ba8SSam Ravnborg 	err  = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
77a88b5ba8SSam Ravnborg 	err |= put_user(stat->ino, &statbuf->st_ino);
78a88b5ba8SSam Ravnborg 	err |= put_user(stat->mode, &statbuf->st_mode);
79a88b5ba8SSam Ravnborg 	err |= put_user(stat->nlink, &statbuf->st_nlink);
80a7c1938eSEric W. Biederman 	err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
81a7c1938eSEric W. Biederman 	err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
82a88b5ba8SSam Ravnborg 	err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
83a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
84a88b5ba8SSam Ravnborg 	err |= put_user(stat->size, &statbuf->st_size);
85a88b5ba8SSam Ravnborg 	err |= put_user(stat->blksize, &statbuf->st_blksize);
86a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
87a88b5ba8SSam Ravnborg 	err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
88a88b5ba8SSam Ravnborg 	err |= put_user(stat->blocks, &statbuf->st_blocks);
89a88b5ba8SSam Ravnborg 	err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
90a88b5ba8SSam Ravnborg 	err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
91a88b5ba8SSam Ravnborg 	err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
92a88b5ba8SSam Ravnborg 	err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
93a88b5ba8SSam Ravnborg 	err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
94a88b5ba8SSam Ravnborg 	err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
95a88b5ba8SSam Ravnborg 	err |= put_user(0, &statbuf->__unused4);
96a88b5ba8SSam Ravnborg 	err |= put_user(0, &statbuf->__unused5);
97a88b5ba8SSam Ravnborg 
98a88b5ba8SSam Ravnborg 	return err;
99a88b5ba8SSam Ravnborg }
100a88b5ba8SSam Ravnborg 
101c7887325SDavid Howells asmlinkage long compat_sys_stat64(const char __user * filename,
102a88b5ba8SSam Ravnborg 		struct compat_stat64 __user *statbuf)
103a88b5ba8SSam Ravnborg {
104a88b5ba8SSam Ravnborg 	struct kstat stat;
105a88b5ba8SSam Ravnborg 	int error = vfs_stat(filename, &stat);
106a88b5ba8SSam Ravnborg 
107a88b5ba8SSam Ravnborg 	if (!error)
108a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
109a88b5ba8SSam Ravnborg 	return error;
110a88b5ba8SSam Ravnborg }
111a88b5ba8SSam Ravnborg 
112c7887325SDavid Howells asmlinkage long compat_sys_lstat64(const char __user * filename,
113a88b5ba8SSam Ravnborg 		struct compat_stat64 __user *statbuf)
114a88b5ba8SSam Ravnborg {
115a88b5ba8SSam Ravnborg 	struct kstat stat;
116a88b5ba8SSam Ravnborg 	int error = vfs_lstat(filename, &stat);
117a88b5ba8SSam Ravnborg 
118a88b5ba8SSam Ravnborg 	if (!error)
119a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
120a88b5ba8SSam Ravnborg 	return error;
121a88b5ba8SSam Ravnborg }
122a88b5ba8SSam Ravnborg 
123a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fstat64(unsigned int fd,
124a88b5ba8SSam Ravnborg 		struct compat_stat64 __user * statbuf)
125a88b5ba8SSam Ravnborg {
126a88b5ba8SSam Ravnborg 	struct kstat stat;
127a88b5ba8SSam Ravnborg 	int error = vfs_fstat(fd, &stat);
128a88b5ba8SSam Ravnborg 
129a88b5ba8SSam Ravnborg 	if (!error)
130a88b5ba8SSam Ravnborg 		error = cp_compat_stat64(&stat, statbuf);
131a88b5ba8SSam Ravnborg 	return error;
132a88b5ba8SSam Ravnborg }
133a88b5ba8SSam Ravnborg 
134c7887325SDavid Howells asmlinkage long compat_sys_fstatat64(unsigned int dfd,
135c7887325SDavid Howells 		const char __user *filename,
136a88b5ba8SSam Ravnborg 		struct compat_stat64 __user * statbuf, int flag)
137a88b5ba8SSam Ravnborg {
138a88b5ba8SSam Ravnborg 	struct kstat stat;
1390112fc22SOleg Drokin 	int error;
140a88b5ba8SSam Ravnborg 
1410112fc22SOleg Drokin 	error = vfs_fstatat(dfd, filename, &stat, flag);
1420112fc22SOleg Drokin 	if (error)
143a88b5ba8SSam Ravnborg 		return error;
1440112fc22SOleg Drokin 	return cp_compat_stat64(&stat, statbuf);
145a88b5ba8SSam Ravnborg }
146a88b5ba8SSam Ravnborg 
147a274bd49SAl Viro COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
148a274bd49SAl Viro 			struct compat_old_sigaction __user *,act,
149a274bd49SAl Viro 			struct compat_old_sigaction __user *,oact)
150a88b5ba8SSam Ravnborg {
151a88b5ba8SSam Ravnborg 	WARN_ON_ONCE(sig >= 0);
152a274bd49SAl Viro 	return compat_sys_sigaction(-sig, act, oact);
153a88b5ba8SSam Ravnborg }
154a88b5ba8SSam Ravnborg 
155bdc40abfSAl Viro COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
156bdc40abfSAl Viro 			struct compat_sigaction __user *,act,
157bdc40abfSAl Viro 			struct compat_sigaction __user *,oact,
158bdc40abfSAl Viro 			void __user *,restorer,
159bdc40abfSAl Viro 			compat_size_t,sigsetsize)
160a88b5ba8SSam Ravnborg {
161a88b5ba8SSam Ravnborg         struct k_sigaction new_ka, old_ka;
162a88b5ba8SSam Ravnborg         int ret;
163a88b5ba8SSam Ravnborg 
164a88b5ba8SSam Ravnborg         /* XXX: Don't preclude handling different sized sigset_t's.  */
165a88b5ba8SSam Ravnborg         if (sigsetsize != sizeof(compat_sigset_t))
166a88b5ba8SSam Ravnborg                 return -EINVAL;
167a88b5ba8SSam Ravnborg 
168a88b5ba8SSam Ravnborg         if (act) {
169a88b5ba8SSam Ravnborg 		u32 u_handler, u_restorer;
170a88b5ba8SSam Ravnborg 
171a88b5ba8SSam Ravnborg 		new_ka.ka_restorer = restorer;
172a88b5ba8SSam Ravnborg 		ret = get_user(u_handler, &act->sa_handler);
173a88b5ba8SSam Ravnborg 		new_ka.sa.sa_handler =  compat_ptr(u_handler);
1743968cf62SAl Viro 		ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
1753ddc5b46SMathieu Desnoyers 		ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
1763ddc5b46SMathieu Desnoyers 		ret |= get_user(u_restorer, &act->sa_restorer);
177a88b5ba8SSam Ravnborg 		new_ka.sa.sa_restorer = compat_ptr(u_restorer);
178a88b5ba8SSam Ravnborg                 if (ret)
179a88b5ba8SSam Ravnborg                 	return -EFAULT;
180a88b5ba8SSam Ravnborg 	}
181a88b5ba8SSam Ravnborg 
182a88b5ba8SSam Ravnborg 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
183a88b5ba8SSam Ravnborg 
184a88b5ba8SSam Ravnborg 	if (!ret && oact) {
185a88b5ba8SSam Ravnborg 		ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
186f454322eSDmitry V. Levin 		ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
187f454322eSDmitry V. Levin 					 sizeof(oact->sa_mask));
1883ddc5b46SMathieu Desnoyers 		ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
1893ddc5b46SMathieu Desnoyers 		ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
190a88b5ba8SSam Ravnborg 		if (ret)
191a88b5ba8SSam Ravnborg 			ret = -EFAULT;
192a88b5ba8SSam Ravnborg         }
193a88b5ba8SSam Ravnborg 
194a88b5ba8SSam Ravnborg         return ret;
195a88b5ba8SSam Ravnborg }
196a88b5ba8SSam Ravnborg 
197a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
198a88b5ba8SSam Ravnborg 					char __user *ubuf,
199a88b5ba8SSam Ravnborg 					compat_size_t count,
200a88b5ba8SSam Ravnborg 					unsigned long poshi,
201a88b5ba8SSam Ravnborg 					unsigned long poslo)
202a88b5ba8SSam Ravnborg {
20336028d5dSDominik Brodowski 	return ksys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
204a88b5ba8SSam Ravnborg }
205a88b5ba8SSam Ravnborg 
206a88b5ba8SSam Ravnborg asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
207a88b5ba8SSam Ravnborg 					 char __user *ubuf,
208a88b5ba8SSam Ravnborg 					 compat_size_t count,
209a88b5ba8SSam Ravnborg 					 unsigned long poshi,
210a88b5ba8SSam Ravnborg 					 unsigned long poslo)
211a88b5ba8SSam Ravnborg {
21236028d5dSDominik Brodowski 	return ksys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
213a88b5ba8SSam Ravnborg }
214a88b5ba8SSam Ravnborg 
215a88b5ba8SSam Ravnborg asmlinkage long compat_sys_readahead(int fd,
216a88b5ba8SSam Ravnborg 				     unsigned long offhi,
217a88b5ba8SSam Ravnborg 				     unsigned long offlo,
218a88b5ba8SSam Ravnborg 				     compat_size_t count)
219a88b5ba8SSam Ravnborg {
220a88b5ba8SSam Ravnborg 	return sys_readahead(fd, (offhi << 32) | offlo, count);
221a88b5ba8SSam Ravnborg }
222a88b5ba8SSam Ravnborg 
223a88b5ba8SSam Ravnborg long compat_sys_fadvise64(int fd,
224a88b5ba8SSam Ravnborg 			  unsigned long offhi,
225a88b5ba8SSam Ravnborg 			  unsigned long offlo,
226a88b5ba8SSam Ravnborg 			  compat_size_t len, int advice)
227a88b5ba8SSam Ravnborg {
228*9d5b7c95SDominik Brodowski 	return ksys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
229a88b5ba8SSam Ravnborg }
230a88b5ba8SSam Ravnborg 
231a88b5ba8SSam Ravnborg long compat_sys_fadvise64_64(int fd,
232a88b5ba8SSam Ravnborg 			     unsigned long offhi, unsigned long offlo,
233a88b5ba8SSam Ravnborg 			     unsigned long lenhi, unsigned long lenlo,
234a88b5ba8SSam Ravnborg 			     int advice)
235a88b5ba8SSam Ravnborg {
236*9d5b7c95SDominik Brodowski 	return ksys_fadvise64_64(fd,
237a88b5ba8SSam Ravnborg 				 (offhi << 32) | offlo,
238a88b5ba8SSam Ravnborg 				 (lenhi << 32) | lenlo,
239a88b5ba8SSam Ravnborg 				 advice);
240a88b5ba8SSam Ravnborg }
241a88b5ba8SSam Ravnborg 
2422ae80c43SAl Viro long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, unsigned int flags)
243a88b5ba8SSam Ravnborg {
244806cbae1SDominik Brodowski 	return ksys_sync_file_range(fd,
245a88b5ba8SSam Ravnborg 				   (off_high << 32) | off_low,
246a88b5ba8SSam Ravnborg 				   (nb_high << 32) | nb_low,
247a88b5ba8SSam Ravnborg 				   flags);
248a88b5ba8SSam Ravnborg }
249a88b5ba8SSam Ravnborg 
250a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
251a88b5ba8SSam Ravnborg 				     u32 lenhi, u32 lenlo)
252a88b5ba8SSam Ravnborg {
253edf292c7SDominik Brodowski 	return ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
254a88b5ba8SSam Ravnborg 			      ((loff_t)lenhi << 32) | lenlo);
255a88b5ba8SSam Ravnborg }
256