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 60a88b5ba8SSam Ravnborg return sys_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 68a88b5ba8SSam Ravnborg return sys_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 { 203a88b5ba8SSam Ravnborg return sys_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 { 212a88b5ba8SSam Ravnborg return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo); 213a88b5ba8SSam Ravnborg } 214a88b5ba8SSam Ravnborg 215*a00a700bSAl Viro COMPAT_SYSCALL_DEFINE4(readahead, int, fd, u32, offhi, u32, offlo, 216*a00a700bSAl Viro compat_size_t, count) 217a88b5ba8SSam Ravnborg { 218*a00a700bSAl Viro return sys_readahead(fd, ((u64)offhi << 32) | offlo, count); 219a88b5ba8SSam Ravnborg } 220a88b5ba8SSam Ravnborg 221*a00a700bSAl Viro COMPAT_SYSCALL_DEFINE5(fadvise64, int, fd, u32, offhi, u32, offlo, 222*a00a700bSAl Viro compat_size_t, len, int, advice) 223a88b5ba8SSam Ravnborg { 224*a00a700bSAl Viro return sys_fadvise64_64(fd, ((u64)offhi << 32) | offlo, len, advice); 225a88b5ba8SSam Ravnborg } 226a88b5ba8SSam Ravnborg 227*a00a700bSAl Viro COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, u32, offhi, u32, offlo, 228*a00a700bSAl Viro u32, lenhi, u32, lenlo, int, advice) 229a88b5ba8SSam Ravnborg { 230a88b5ba8SSam Ravnborg return sys_fadvise64_64(fd, 231*a00a700bSAl Viro ((u64)offhi << 32) | offlo, 232*a00a700bSAl Viro ((u64)lenhi << 32) | lenlo, 233a88b5ba8SSam Ravnborg advice); 234a88b5ba8SSam Ravnborg } 235a88b5ba8SSam Ravnborg 2362ae80c43SAl 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) 237a88b5ba8SSam Ravnborg { 238a88b5ba8SSam Ravnborg return sys_sync_file_range(fd, 239a88b5ba8SSam Ravnborg (off_high << 32) | off_low, 240a88b5ba8SSam Ravnborg (nb_high << 32) | nb_low, 241a88b5ba8SSam Ravnborg flags); 242a88b5ba8SSam Ravnborg } 243a88b5ba8SSam Ravnborg 244a88b5ba8SSam Ravnborg asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo, 245a88b5ba8SSam Ravnborg u32 lenhi, u32 lenlo) 246a88b5ba8SSam Ravnborg { 247a88b5ba8SSam Ravnborg return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo, 248a88b5ba8SSam Ravnborg ((loff_t)lenhi << 32) | lenlo); 249a88b5ba8SSam Ravnborg } 250