11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Conversion between 32-bit and 64-bit native system calls. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 2000 Silicon Graphics, Inc. 51da177e4SLinus Torvalds * Written by Ulf Carlsson (ulfc@engr.sgi.com) 61da177e4SLinus Torvalds * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com) 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds #include <linux/compiler.h> 91da177e4SLinus Torvalds #include <linux/mm.h> 101da177e4SLinus Torvalds #include <linux/errno.h> 111da177e4SLinus Torvalds #include <linux/file.h> 121da177e4SLinus Torvalds #include <linux/smp_lock.h> 131da177e4SLinus Torvalds #include <linux/highuid.h> 141da177e4SLinus Torvalds #include <linux/dirent.h> 151da177e4SLinus Torvalds #include <linux/resource.h> 161da177e4SLinus Torvalds #include <linux/highmem.h> 171da177e4SLinus Torvalds #include <linux/time.h> 181da177e4SLinus Torvalds #include <linux/times.h> 191da177e4SLinus Torvalds #include <linux/poll.h> 201da177e4SLinus Torvalds #include <linux/slab.h> 211da177e4SLinus Torvalds #include <linux/skbuff.h> 221da177e4SLinus Torvalds #include <linux/filter.h> 231da177e4SLinus Torvalds #include <linux/shm.h> 241da177e4SLinus Torvalds #include <linux/sem.h> 251da177e4SLinus Torvalds #include <linux/msg.h> 261da177e4SLinus Torvalds #include <linux/icmpv6.h> 271da177e4SLinus Torvalds #include <linux/syscalls.h> 281da177e4SLinus Torvalds #include <linux/sysctl.h> 291da177e4SLinus Torvalds #include <linux/utime.h> 301da177e4SLinus Torvalds #include <linux/utsname.h> 311da177e4SLinus Torvalds #include <linux/personality.h> 321da177e4SLinus Torvalds #include <linux/dnotify.h> 331da177e4SLinus Torvalds #include <linux/module.h> 341da177e4SLinus Torvalds #include <linux/binfmts.h> 351da177e4SLinus Torvalds #include <linux/security.h> 361da177e4SLinus Torvalds #include <linux/compat.h> 371da177e4SLinus Torvalds #include <linux/vfs.h> 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds #include <net/sock.h> 401da177e4SLinus Torvalds #include <net/scm.h> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #include <asm/ipc.h> 431da177e4SLinus Torvalds #include <asm/sim.h> 441da177e4SLinus Torvalds #include <asm/uaccess.h> 451da177e4SLinus Torvalds #include <asm/mmu_context.h> 461da177e4SLinus Torvalds #include <asm/mman.h> 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /* Use this to get at 32-bit user passed pointers. */ 491da177e4SLinus Torvalds /* A() macro should be used for places where you e.g. 501da177e4SLinus Torvalds have some internal variable u32 and just want to get 511da177e4SLinus Torvalds rid of a compiler warning. AA() has to be used in 521da177e4SLinus Torvalds places where you want to convert a function argument 531da177e4SLinus Torvalds to 32bit pointer or when you e.g. access pt_regs 541da177e4SLinus Torvalds structure and want to consider 32bit registers only. 551da177e4SLinus Torvalds */ 561da177e4SLinus Torvalds #define A(__x) ((unsigned long)(__x)) 571da177e4SLinus Torvalds #define AA(__x) ((unsigned long)((int)__x)) 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds #ifdef __MIPSEB__ 601da177e4SLinus Torvalds #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) 611da177e4SLinus Torvalds #endif 621da177e4SLinus Torvalds #ifdef __MIPSEL__ 631da177e4SLinus Torvalds #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) 641da177e4SLinus Torvalds #endif 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* 671da177e4SLinus Torvalds * Revalidate the inode. This is required for proper NFS attribute caching. 681da177e4SLinus Torvalds */ 691da177e4SLinus Torvalds 70219ac73aSAtsushi Nemoto int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf) 711da177e4SLinus Torvalds { 721da177e4SLinus Torvalds struct compat_stat tmp; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev)) 751da177e4SLinus Torvalds return -EOVERFLOW; 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds memset(&tmp, 0, sizeof(tmp)); 781da177e4SLinus Torvalds tmp.st_dev = new_encode_dev(stat->dev); 791da177e4SLinus Torvalds tmp.st_ino = stat->ino; 80afefdbb2SDavid Howells if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino) 81afefdbb2SDavid Howells return -EOVERFLOW; 821da177e4SLinus Torvalds tmp.st_mode = stat->mode; 831da177e4SLinus Torvalds tmp.st_nlink = stat->nlink; 841da177e4SLinus Torvalds SET_UID(tmp.st_uid, stat->uid); 851da177e4SLinus Torvalds SET_GID(tmp.st_gid, stat->gid); 861da177e4SLinus Torvalds tmp.st_rdev = new_encode_dev(stat->rdev); 871da177e4SLinus Torvalds tmp.st_size = stat->size; 881da177e4SLinus Torvalds tmp.st_atime = stat->atime.tv_sec; 891da177e4SLinus Torvalds tmp.st_mtime = stat->mtime.tv_sec; 901da177e4SLinus Torvalds tmp.st_ctime = stat->ctime.tv_sec; 911da177e4SLinus Torvalds #ifdef STAT_HAVE_NSEC 921da177e4SLinus Torvalds tmp.st_atime_nsec = stat->atime.tv_nsec; 931da177e4SLinus Torvalds tmp.st_mtime_nsec = stat->mtime.tv_nsec; 941da177e4SLinus Torvalds tmp.st_ctime_nsec = stat->ctime.tv_nsec; 951da177e4SLinus Torvalds #endif 961da177e4SLinus Torvalds tmp.st_blocks = stat->blocks; 971da177e4SLinus Torvalds tmp.st_blksize = stat->blksize; 981da177e4SLinus Torvalds return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds asmlinkage unsigned long 1021da177e4SLinus Torvalds sys32_mmap2(unsigned long addr, unsigned long len, unsigned long prot, 1031da177e4SLinus Torvalds unsigned long flags, unsigned long fd, unsigned long pgoff) 1041da177e4SLinus Torvalds { 1051da177e4SLinus Torvalds struct file * file = NULL; 1061da177e4SLinus Torvalds unsigned long error; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds error = -EINVAL; 109947df17cSH. Peter Anvin if (pgoff & (~PAGE_MASK >> 12)) 110947df17cSH. Peter Anvin goto out; 111947df17cSH. Peter Anvin pgoff >>= PAGE_SHIFT-12; 112947df17cSH. Peter Anvin 1131da177e4SLinus Torvalds if (!(flags & MAP_ANONYMOUS)) { 1141da177e4SLinus Torvalds error = -EBADF; 1151da177e4SLinus Torvalds file = fget(fd); 1161da177e4SLinus Torvalds if (!file) 1171da177e4SLinus Torvalds goto out; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds down_write(¤t->mm->mmap_sem); 1221da177e4SLinus Torvalds error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); 1231da177e4SLinus Torvalds up_write(¤t->mm->mmap_sem); 1241da177e4SLinus Torvalds if (file) 1251da177e4SLinus Torvalds fput(file); 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds out: 1281da177e4SLinus Torvalds return error; 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds 132219ac73aSAtsushi Nemoto asmlinkage int sys_truncate64(const char __user *path, unsigned int high, 1331da177e4SLinus Torvalds unsigned int low) 1341da177e4SLinus Torvalds { 1351da177e4SLinus Torvalds if ((int)high < 0) 1361da177e4SLinus Torvalds return -EINVAL; 1371da177e4SLinus Torvalds return sys_truncate(path, ((long) high << 32) | low); 1381da177e4SLinus Torvalds } 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds asmlinkage int sys_ftruncate64(unsigned int fd, unsigned int high, 1411da177e4SLinus Torvalds unsigned int low) 1421da177e4SLinus Torvalds { 1431da177e4SLinus Torvalds if ((int)high < 0) 1441da177e4SLinus Torvalds return -EINVAL; 1451da177e4SLinus Torvalds return sys_ftruncate(fd, ((long) high << 32) | low); 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds /* 1491da177e4SLinus Torvalds * sys_execve() executes a new program. 1501da177e4SLinus Torvalds */ 1511da177e4SLinus Torvalds asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs) 1521da177e4SLinus Torvalds { 1531da177e4SLinus Torvalds int error; 1541da177e4SLinus Torvalds char * filename; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds filename = getname(compat_ptr(regs.regs[4])); 1571da177e4SLinus Torvalds error = PTR_ERR(filename); 1581da177e4SLinus Torvalds if (IS_ERR(filename)) 1591da177e4SLinus Torvalds goto out; 1601da177e4SLinus Torvalds error = compat_do_execve(filename, compat_ptr(regs.regs[5]), 1611da177e4SLinus Torvalds compat_ptr(regs.regs[6]), ®s); 1621da177e4SLinus Torvalds putname(filename); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds out: 1651da177e4SLinus Torvalds return error; 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds 16854f2da75SRalf Baechle asmlinkage long 16954f2da75SRalf Baechle sysn32_waitid(int which, compat_pid_t pid, 17054f2da75SRalf Baechle siginfo_t __user *uinfo, int options, 17154f2da75SRalf Baechle struct compat_rusage __user *uru) 17254f2da75SRalf Baechle { 17354f2da75SRalf Baechle struct rusage ru; 17454f2da75SRalf Baechle long ret; 17554f2da75SRalf Baechle mm_segment_t old_fs = get_fs(); 176219ac73aSAtsushi Nemoto int si_signo; 17754f2da75SRalf Baechle 178f3468e0cSRalf Baechle if (!access_ok(VERIFY_WRITE, uinfo, sizeof(*uinfo))) 179f3468e0cSRalf Baechle return -EFAULT; 180f3468e0cSRalf Baechle 18154f2da75SRalf Baechle set_fs (KERNEL_DS); 18254f2da75SRalf Baechle ret = sys_waitid(which, pid, uinfo, options, 18354f2da75SRalf Baechle uru ? (struct rusage __user *) &ru : NULL); 18454f2da75SRalf Baechle set_fs (old_fs); 18554f2da75SRalf Baechle 186219ac73aSAtsushi Nemoto if (__get_user(si_signo, &uinfo->si_signo)) 187219ac73aSAtsushi Nemoto return -EFAULT; 188219ac73aSAtsushi Nemoto if (ret < 0 || si_signo == 0) 18954f2da75SRalf Baechle return ret; 19054f2da75SRalf Baechle 19154f2da75SRalf Baechle if (uru) 19254f2da75SRalf Baechle ret = put_compat_rusage(&ru, uru); 19354f2da75SRalf Baechle return ret; 19454f2da75SRalf Baechle } 19554f2da75SRalf Baechle 1961da177e4SLinus Torvalds struct sysinfo32 { 1971da177e4SLinus Torvalds s32 uptime; 1981da177e4SLinus Torvalds u32 loads[3]; 1991da177e4SLinus Torvalds u32 totalram; 2001da177e4SLinus Torvalds u32 freeram; 2011da177e4SLinus Torvalds u32 sharedram; 2021da177e4SLinus Torvalds u32 bufferram; 2031da177e4SLinus Torvalds u32 totalswap; 2041da177e4SLinus Torvalds u32 freeswap; 2051da177e4SLinus Torvalds u16 procs; 2061da177e4SLinus Torvalds u32 totalhigh; 2071da177e4SLinus Torvalds u32 freehigh; 2081da177e4SLinus Torvalds u32 mem_unit; 2091da177e4SLinus Torvalds char _f[8]; 2101da177e4SLinus Torvalds }; 2111da177e4SLinus Torvalds 212219ac73aSAtsushi Nemoto asmlinkage int sys32_sysinfo(struct sysinfo32 __user *info) 2131da177e4SLinus Torvalds { 2141da177e4SLinus Torvalds struct sysinfo s; 2151da177e4SLinus Torvalds int ret, err; 2161da177e4SLinus Torvalds mm_segment_t old_fs = get_fs (); 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds set_fs (KERNEL_DS); 219219ac73aSAtsushi Nemoto ret = sys_sysinfo((struct sysinfo __user *)&s); 2201da177e4SLinus Torvalds set_fs (old_fs); 2211da177e4SLinus Torvalds err = put_user (s.uptime, &info->uptime); 2221da177e4SLinus Torvalds err |= __put_user (s.loads[0], &info->loads[0]); 2231da177e4SLinus Torvalds err |= __put_user (s.loads[1], &info->loads[1]); 2241da177e4SLinus Torvalds err |= __put_user (s.loads[2], &info->loads[2]); 2251da177e4SLinus Torvalds err |= __put_user (s.totalram, &info->totalram); 2261da177e4SLinus Torvalds err |= __put_user (s.freeram, &info->freeram); 2271da177e4SLinus Torvalds err |= __put_user (s.sharedram, &info->sharedram); 2281da177e4SLinus Torvalds err |= __put_user (s.bufferram, &info->bufferram); 2291da177e4SLinus Torvalds err |= __put_user (s.totalswap, &info->totalswap); 2301da177e4SLinus Torvalds err |= __put_user (s.freeswap, &info->freeswap); 2311da177e4SLinus Torvalds err |= __put_user (s.procs, &info->procs); 2321da177e4SLinus Torvalds err |= __put_user (s.totalhigh, &info->totalhigh); 2331da177e4SLinus Torvalds err |= __put_user (s.freehigh, &info->freehigh); 2341da177e4SLinus Torvalds err |= __put_user (s.mem_unit, &info->mem_unit); 2351da177e4SLinus Torvalds if (err) 2361da177e4SLinus Torvalds return -EFAULT; 2371da177e4SLinus Torvalds return ret; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds #define RLIM_INFINITY32 0x7fffffff 2411da177e4SLinus Torvalds #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds struct rlimit32 { 2441da177e4SLinus Torvalds int rlim_cur; 2451da177e4SLinus Torvalds int rlim_max; 2461da177e4SLinus Torvalds }; 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds #ifdef __MIPSEB__ 249219ac73aSAtsushi Nemoto asmlinkage long sys32_truncate64(const char __user * path, unsigned long __dummy, 2501da177e4SLinus Torvalds int length_hi, int length_lo) 2511da177e4SLinus Torvalds #endif 2521da177e4SLinus Torvalds #ifdef __MIPSEL__ 253219ac73aSAtsushi Nemoto asmlinkage long sys32_truncate64(const char __user * path, unsigned long __dummy, 2541da177e4SLinus Torvalds int length_lo, int length_hi) 2551da177e4SLinus Torvalds #endif 2561da177e4SLinus Torvalds { 2571da177e4SLinus Torvalds loff_t length; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds return sys_truncate(path, length); 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds #ifdef __MIPSEB__ 2651da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, 2661da177e4SLinus Torvalds int length_hi, int length_lo) 2671da177e4SLinus Torvalds #endif 2681da177e4SLinus Torvalds #ifdef __MIPSEL__ 2691da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, 2701da177e4SLinus Torvalds int length_lo, int length_hi) 2711da177e4SLinus Torvalds #endif 2721da177e4SLinus Torvalds { 2731da177e4SLinus Torvalds loff_t length; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds return sys_ftruncate(fd, length); 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds static inline long 281219ac73aSAtsushi Nemoto get_tv32(struct timeval *o, struct compat_timeval __user *i) 2821da177e4SLinus Torvalds { 2831da177e4SLinus Torvalds return (!access_ok(VERIFY_READ, i, sizeof(*i)) || 2841da177e4SLinus Torvalds (__get_user(o->tv_sec, &i->tv_sec) | 2851da177e4SLinus Torvalds __get_user(o->tv_usec, &i->tv_usec))); 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds static inline long 289219ac73aSAtsushi Nemoto put_tv32(struct compat_timeval __user *o, struct timeval *i) 2901da177e4SLinus Torvalds { 2911da177e4SLinus Torvalds return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || 2921da177e4SLinus Torvalds (__put_user(i->tv_sec, &o->tv_sec) | 2931da177e4SLinus Torvalds __put_user(i->tv_usec, &o->tv_usec))); 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds extern struct timezone sys_tz; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds asmlinkage int 299219ac73aSAtsushi Nemoto sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) 3001da177e4SLinus Torvalds { 3011da177e4SLinus Torvalds if (tv) { 3021da177e4SLinus Torvalds struct timeval ktv; 3031da177e4SLinus Torvalds do_gettimeofday(&ktv); 3041da177e4SLinus Torvalds if (put_tv32(tv, &ktv)) 3051da177e4SLinus Torvalds return -EFAULT; 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds if (tz) { 3081da177e4SLinus Torvalds if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) 3091da177e4SLinus Torvalds return -EFAULT; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds return 0; 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds 314219ac73aSAtsushi Nemoto static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i) 3151da177e4SLinus Torvalds { 3161da177e4SLinus Torvalds long usec; 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, i, sizeof(*i))) 3191da177e4SLinus Torvalds return -EFAULT; 3201da177e4SLinus Torvalds if (__get_user(o->tv_sec, &i->tv_sec)) 3211da177e4SLinus Torvalds return -EFAULT; 3221da177e4SLinus Torvalds if (__get_user(usec, &i->tv_usec)) 3231da177e4SLinus Torvalds return -EFAULT; 3241da177e4SLinus Torvalds o->tv_nsec = usec * 1000; 3251da177e4SLinus Torvalds return 0; 3261da177e4SLinus Torvalds } 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds asmlinkage int 329219ac73aSAtsushi Nemoto sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) 3301da177e4SLinus Torvalds { 3311da177e4SLinus Torvalds struct timespec kts; 3321da177e4SLinus Torvalds struct timezone ktz; 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds if (tv) { 3351da177e4SLinus Torvalds if (get_ts32(&kts, tv)) 3361da177e4SLinus Torvalds return -EFAULT; 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds if (tz) { 3391da177e4SLinus Torvalds if (copy_from_user(&ktz, tz, sizeof(ktz))) 3401da177e4SLinus Torvalds return -EFAULT; 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); 3441da177e4SLinus Torvalds } 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high, 347219ac73aSAtsushi Nemoto unsigned int offset_low, loff_t __user * result, 3481da177e4SLinus Torvalds unsigned int origin) 3491da177e4SLinus Torvalds { 3501da177e4SLinus Torvalds return sys_llseek(fd, offset_high, offset_low, result, origin); 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + 3541da177e4SLinus Torvalds lseek back to original location. They fail just like lseek does on 3551da177e4SLinus Torvalds non-seekable files. */ 3561da177e4SLinus Torvalds 357219ac73aSAtsushi Nemoto asmlinkage ssize_t sys32_pread(unsigned int fd, char __user * buf, 3581da177e4SLinus Torvalds size_t count, u32 unused, u64 a4, u64 a5) 3591da177e4SLinus Torvalds { 3606ad0013bSAl Viro return sys_pread64(fd, buf, count, merge_64(a4, a5)); 3611da177e4SLinus Torvalds } 3621da177e4SLinus Torvalds 363219ac73aSAtsushi Nemoto asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char __user * buf, 3641da177e4SLinus Torvalds size_t count, u32 unused, u64 a4, u64 a5) 3651da177e4SLinus Torvalds { 3666ad0013bSAl Viro return sys_pwrite64(fd, buf, count, merge_64(a4, a5)); 3671da177e4SLinus Torvalds } 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid, 370219ac73aSAtsushi Nemoto struct compat_timespec __user *interval) 3711da177e4SLinus Torvalds { 3721da177e4SLinus Torvalds struct timespec t; 3731da177e4SLinus Torvalds int ret; 3741da177e4SLinus Torvalds mm_segment_t old_fs = get_fs (); 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds set_fs (KERNEL_DS); 377219ac73aSAtsushi Nemoto ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t); 3781da177e4SLinus Torvalds set_fs (old_fs); 3791da177e4SLinus Torvalds if (put_user (t.tv_sec, &interval->tv_sec) || 3801da177e4SLinus Torvalds __put_user (t.tv_nsec, &interval->tv_nsec)) 3811da177e4SLinus Torvalds return -EFAULT; 3821da177e4SLinus Torvalds return ret; 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds struct msgbuf32 { s32 mtype; char mtext[1]; }; 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds struct ipc_perm32 3881da177e4SLinus Torvalds { 3891da177e4SLinus Torvalds key_t key; 390202e5979SStephen Rothwell __compat_uid_t uid; 391202e5979SStephen Rothwell __compat_gid_t gid; 392202e5979SStephen Rothwell __compat_uid_t cuid; 393202e5979SStephen Rothwell __compat_gid_t cgid; 3941da177e4SLinus Torvalds compat_mode_t mode; 3951da177e4SLinus Torvalds unsigned short seq; 3961da177e4SLinus Torvalds }; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds struct ipc64_perm32 { 3991da177e4SLinus Torvalds key_t key; 400202e5979SStephen Rothwell __compat_uid_t uid; 401202e5979SStephen Rothwell __compat_gid_t gid; 402202e5979SStephen Rothwell __compat_uid_t cuid; 403202e5979SStephen Rothwell __compat_gid_t cgid; 4041da177e4SLinus Torvalds compat_mode_t mode; 4051da177e4SLinus Torvalds unsigned short seq; 4061da177e4SLinus Torvalds unsigned short __pad1; 4071da177e4SLinus Torvalds unsigned int __unused1; 4081da177e4SLinus Torvalds unsigned int __unused2; 4091da177e4SLinus Torvalds }; 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds struct semid_ds32 { 4121da177e4SLinus Torvalds struct ipc_perm32 sem_perm; /* permissions .. see ipc.h */ 4131da177e4SLinus Torvalds compat_time_t sem_otime; /* last semop time */ 4141da177e4SLinus Torvalds compat_time_t sem_ctime; /* last change time */ 4151da177e4SLinus Torvalds u32 sem_base; /* ptr to first semaphore in array */ 4161da177e4SLinus Torvalds u32 sem_pending; /* pending operations to be processed */ 4171da177e4SLinus Torvalds u32 sem_pending_last; /* last pending operation */ 4181da177e4SLinus Torvalds u32 undo; /* undo requests on this array */ 4191da177e4SLinus Torvalds unsigned short sem_nsems; /* no. of semaphores in array */ 4201da177e4SLinus Torvalds }; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds struct semid64_ds32 { 4231da177e4SLinus Torvalds struct ipc64_perm32 sem_perm; 4241da177e4SLinus Torvalds compat_time_t sem_otime; 4251da177e4SLinus Torvalds compat_time_t sem_ctime; 4261da177e4SLinus Torvalds unsigned int sem_nsems; 4271da177e4SLinus Torvalds unsigned int __unused1; 4281da177e4SLinus Torvalds unsigned int __unused2; 4291da177e4SLinus Torvalds }; 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds struct msqid_ds32 4321da177e4SLinus Torvalds { 4331da177e4SLinus Torvalds struct ipc_perm32 msg_perm; 4341da177e4SLinus Torvalds u32 msg_first; 4351da177e4SLinus Torvalds u32 msg_last; 4361da177e4SLinus Torvalds compat_time_t msg_stime; 4371da177e4SLinus Torvalds compat_time_t msg_rtime; 4381da177e4SLinus Torvalds compat_time_t msg_ctime; 4391da177e4SLinus Torvalds u32 wwait; 4401da177e4SLinus Torvalds u32 rwait; 4411da177e4SLinus Torvalds unsigned short msg_cbytes; 4421da177e4SLinus Torvalds unsigned short msg_qnum; 4431da177e4SLinus Torvalds unsigned short msg_qbytes; 4441da177e4SLinus Torvalds compat_ipc_pid_t msg_lspid; 4451da177e4SLinus Torvalds compat_ipc_pid_t msg_lrpid; 4461da177e4SLinus Torvalds }; 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds struct msqid64_ds32 { 4491da177e4SLinus Torvalds struct ipc64_perm32 msg_perm; 4501da177e4SLinus Torvalds compat_time_t msg_stime; 4511da177e4SLinus Torvalds unsigned int __unused1; 4521da177e4SLinus Torvalds compat_time_t msg_rtime; 4531da177e4SLinus Torvalds unsigned int __unused2; 4541da177e4SLinus Torvalds compat_time_t msg_ctime; 4551da177e4SLinus Torvalds unsigned int __unused3; 4561da177e4SLinus Torvalds unsigned int msg_cbytes; 4571da177e4SLinus Torvalds unsigned int msg_qnum; 4581da177e4SLinus Torvalds unsigned int msg_qbytes; 4591da177e4SLinus Torvalds compat_pid_t msg_lspid; 4601da177e4SLinus Torvalds compat_pid_t msg_lrpid; 4611da177e4SLinus Torvalds unsigned int __unused4; 4621da177e4SLinus Torvalds unsigned int __unused5; 4631da177e4SLinus Torvalds }; 4641da177e4SLinus Torvalds 4651da177e4SLinus Torvalds struct shmid_ds32 { 4661da177e4SLinus Torvalds struct ipc_perm32 shm_perm; 4671da177e4SLinus Torvalds int shm_segsz; 4681da177e4SLinus Torvalds compat_time_t shm_atime; 4691da177e4SLinus Torvalds compat_time_t shm_dtime; 4701da177e4SLinus Torvalds compat_time_t shm_ctime; 4711da177e4SLinus Torvalds compat_ipc_pid_t shm_cpid; 4721da177e4SLinus Torvalds compat_ipc_pid_t shm_lpid; 4731da177e4SLinus Torvalds unsigned short shm_nattch; 4741da177e4SLinus Torvalds }; 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds struct shmid64_ds32 { 4771da177e4SLinus Torvalds struct ipc64_perm32 shm_perm; 4781da177e4SLinus Torvalds compat_size_t shm_segsz; 4791da177e4SLinus Torvalds compat_time_t shm_atime; 4801da177e4SLinus Torvalds compat_time_t shm_dtime; 4811da177e4SLinus Torvalds compat_time_t shm_ctime; 4821da177e4SLinus Torvalds compat_pid_t shm_cpid; 4831da177e4SLinus Torvalds compat_pid_t shm_lpid; 4841da177e4SLinus Torvalds unsigned int shm_nattch; 4851da177e4SLinus Torvalds unsigned int __unused1; 4861da177e4SLinus Torvalds unsigned int __unused2; 4871da177e4SLinus Torvalds }; 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds struct ipc_kludge32 { 4901da177e4SLinus Torvalds u32 msgp; 4911da177e4SLinus Torvalds s32 msgtyp; 4921da177e4SLinus Torvalds }; 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds static int 495219ac73aSAtsushi Nemoto do_sys32_semctl(int first, int second, int third, void __user *uptr) 4961da177e4SLinus Torvalds { 4971da177e4SLinus Torvalds union semun fourth; 4981da177e4SLinus Torvalds u32 pad; 4991da177e4SLinus Torvalds int err, err2; 5001da177e4SLinus Torvalds struct semid64_ds s; 5011da177e4SLinus Torvalds mm_segment_t old_fs; 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds if (!uptr) 5041da177e4SLinus Torvalds return -EINVAL; 5051da177e4SLinus Torvalds err = -EFAULT; 506219ac73aSAtsushi Nemoto if (get_user (pad, (u32 __user *)uptr)) 5071da177e4SLinus Torvalds return err; 5081da177e4SLinus Torvalds if ((third & ~IPC_64) == SETVAL) 5091da177e4SLinus Torvalds fourth.val = (int)pad; 5101da177e4SLinus Torvalds else 511219ac73aSAtsushi Nemoto fourth.__pad = (void __user *)A(pad); 5121da177e4SLinus Torvalds switch (third & ~IPC_64) { 5131da177e4SLinus Torvalds case IPC_INFO: 5141da177e4SLinus Torvalds case IPC_RMID: 5151da177e4SLinus Torvalds case IPC_SET: 5161da177e4SLinus Torvalds case SEM_INFO: 5171da177e4SLinus Torvalds case GETVAL: 5181da177e4SLinus Torvalds case GETPID: 5191da177e4SLinus Torvalds case GETNCNT: 5201da177e4SLinus Torvalds case GETZCNT: 5211da177e4SLinus Torvalds case GETALL: 5221da177e4SLinus Torvalds case SETVAL: 5231da177e4SLinus Torvalds case SETALL: 5241da177e4SLinus Torvalds err = sys_semctl (first, second, third, fourth); 5251da177e4SLinus Torvalds break; 5261da177e4SLinus Torvalds 5271da177e4SLinus Torvalds case IPC_STAT: 5281da177e4SLinus Torvalds case SEM_STAT: 529219ac73aSAtsushi Nemoto fourth.__pad = (struct semid64_ds __user *)&s; 5301da177e4SLinus Torvalds old_fs = get_fs(); 5311da177e4SLinus Torvalds set_fs(KERNEL_DS); 5321da177e4SLinus Torvalds err = sys_semctl(first, second, third | IPC_64, fourth); 5331da177e4SLinus Torvalds set_fs(old_fs); 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds if (third & IPC_64) { 536219ac73aSAtsushi Nemoto struct semid64_ds32 __user *usp64 = (struct semid64_ds32 __user *) A(pad); 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) { 5391da177e4SLinus Torvalds err = -EFAULT; 5401da177e4SLinus Torvalds break; 5411da177e4SLinus Torvalds } 5421da177e4SLinus Torvalds err2 = __put_user(s.sem_perm.key, &usp64->sem_perm.key); 5431da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.uid, &usp64->sem_perm.uid); 5441da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.gid, &usp64->sem_perm.gid); 5451da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cuid, &usp64->sem_perm.cuid); 5461da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cgid, &usp64->sem_perm.cgid); 5471da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.mode, &usp64->sem_perm.mode); 5481da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.seq, &usp64->sem_perm.seq); 5491da177e4SLinus Torvalds err2 |= __put_user(s.sem_otime, &usp64->sem_otime); 5501da177e4SLinus Torvalds err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime); 5511da177e4SLinus Torvalds err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems); 5521da177e4SLinus Torvalds } else { 553219ac73aSAtsushi Nemoto struct semid_ds32 __user *usp32 = (struct semid_ds32 __user *) A(pad); 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) { 5561da177e4SLinus Torvalds err = -EFAULT; 5571da177e4SLinus Torvalds break; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds err2 = __put_user(s.sem_perm.key, &usp32->sem_perm.key); 5601da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.uid, &usp32->sem_perm.uid); 5611da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.gid, &usp32->sem_perm.gid); 5621da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cuid, &usp32->sem_perm.cuid); 5631da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cgid, &usp32->sem_perm.cgid); 5641da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.mode, &usp32->sem_perm.mode); 5651da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.seq, &usp32->sem_perm.seq); 5661da177e4SLinus Torvalds err2 |= __put_user(s.sem_otime, &usp32->sem_otime); 5671da177e4SLinus Torvalds err2 |= __put_user(s.sem_ctime, &usp32->sem_ctime); 5681da177e4SLinus Torvalds err2 |= __put_user(s.sem_nsems, &usp32->sem_nsems); 5691da177e4SLinus Torvalds } 5701da177e4SLinus Torvalds if (err2) 5711da177e4SLinus Torvalds err = -EFAULT; 5721da177e4SLinus Torvalds break; 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds default: 5751da177e4SLinus Torvalds err = - EINVAL; 5761da177e4SLinus Torvalds break; 5771da177e4SLinus Torvalds } 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds return err; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds static int 583219ac73aSAtsushi Nemoto do_sys32_msgsnd (int first, int second, int third, void __user *uptr) 5841da177e4SLinus Torvalds { 585219ac73aSAtsushi Nemoto struct msgbuf32 __user *up = (struct msgbuf32 __user *)uptr; 5861da177e4SLinus Torvalds struct msgbuf *p; 5871da177e4SLinus Torvalds mm_segment_t old_fs; 5881da177e4SLinus Torvalds int err; 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds if (second < 0) 5911da177e4SLinus Torvalds return -EINVAL; 5921da177e4SLinus Torvalds p = kmalloc (second + sizeof (struct msgbuf) 5931da177e4SLinus Torvalds + 4, GFP_USER); 5941da177e4SLinus Torvalds if (!p) 5951da177e4SLinus Torvalds return -ENOMEM; 5961da177e4SLinus Torvalds err = get_user (p->mtype, &up->mtype); 5971da177e4SLinus Torvalds if (err) 5981da177e4SLinus Torvalds goto out; 5991da177e4SLinus Torvalds err |= __copy_from_user (p->mtext, &up->mtext, second); 6001da177e4SLinus Torvalds if (err) 6011da177e4SLinus Torvalds goto out; 6021da177e4SLinus Torvalds old_fs = get_fs (); 6031da177e4SLinus Torvalds set_fs (KERNEL_DS); 604219ac73aSAtsushi Nemoto err = sys_msgsnd (first, (struct msgbuf __user *)p, second, third); 6051da177e4SLinus Torvalds set_fs (old_fs); 6061da177e4SLinus Torvalds out: 6071da177e4SLinus Torvalds kfree (p); 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds return err; 6101da177e4SLinus Torvalds } 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds static int 6131da177e4SLinus Torvalds do_sys32_msgrcv (int first, int second, int msgtyp, int third, 614219ac73aSAtsushi Nemoto int version, void __user *uptr) 6151da177e4SLinus Torvalds { 616219ac73aSAtsushi Nemoto struct msgbuf32 __user *up; 6171da177e4SLinus Torvalds struct msgbuf *p; 6181da177e4SLinus Torvalds mm_segment_t old_fs; 6191da177e4SLinus Torvalds int err; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds if (!version) { 622219ac73aSAtsushi Nemoto struct ipc_kludge32 __user *uipck = (struct ipc_kludge32 __user *)uptr; 6231da177e4SLinus Torvalds struct ipc_kludge32 ipck; 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds err = -EINVAL; 6261da177e4SLinus Torvalds if (!uptr) 6271da177e4SLinus Torvalds goto out; 6281da177e4SLinus Torvalds err = -EFAULT; 6291da177e4SLinus Torvalds if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32))) 6301da177e4SLinus Torvalds goto out; 631219ac73aSAtsushi Nemoto uptr = (void __user *)AA(ipck.msgp); 6321da177e4SLinus Torvalds msgtyp = ipck.msgtyp; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds if (second < 0) 6361da177e4SLinus Torvalds return -EINVAL; 6371da177e4SLinus Torvalds err = -ENOMEM; 6381da177e4SLinus Torvalds p = kmalloc (second + sizeof (struct msgbuf) + 4, GFP_USER); 6391da177e4SLinus Torvalds if (!p) 6401da177e4SLinus Torvalds goto out; 6411da177e4SLinus Torvalds old_fs = get_fs (); 6421da177e4SLinus Torvalds set_fs (KERNEL_DS); 643219ac73aSAtsushi Nemoto err = sys_msgrcv (first, (struct msgbuf __user *)p, second + 4, msgtyp, third); 6441da177e4SLinus Torvalds set_fs (old_fs); 6451da177e4SLinus Torvalds if (err < 0) 6461da177e4SLinus Torvalds goto free_then_out; 647219ac73aSAtsushi Nemoto up = (struct msgbuf32 __user *)uptr; 6481da177e4SLinus Torvalds if (put_user (p->mtype, &up->mtype) || 6491da177e4SLinus Torvalds __copy_to_user (&up->mtext, p->mtext, err)) 6501da177e4SLinus Torvalds err = -EFAULT; 6511da177e4SLinus Torvalds free_then_out: 6521da177e4SLinus Torvalds kfree (p); 6531da177e4SLinus Torvalds out: 6541da177e4SLinus Torvalds return err; 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds static int 658219ac73aSAtsushi Nemoto do_sys32_msgctl (int first, int second, void __user *uptr) 6591da177e4SLinus Torvalds { 6601da177e4SLinus Torvalds int err = -EINVAL, err2; 6611da177e4SLinus Torvalds struct msqid64_ds m; 662219ac73aSAtsushi Nemoto struct msqid_ds32 __user *up32 = (struct msqid_ds32 __user *)uptr; 663219ac73aSAtsushi Nemoto struct msqid64_ds32 __user *up64 = (struct msqid64_ds32 __user *)uptr; 6641da177e4SLinus Torvalds mm_segment_t old_fs; 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds switch (second & ~IPC_64) { 6671da177e4SLinus Torvalds case IPC_INFO: 6681da177e4SLinus Torvalds case IPC_RMID: 6691da177e4SLinus Torvalds case MSG_INFO: 670219ac73aSAtsushi Nemoto err = sys_msgctl (first, second, (struct msqid_ds __user *)uptr); 6711da177e4SLinus Torvalds break; 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds case IPC_SET: 6741da177e4SLinus Torvalds if (second & IPC_64) { 6751da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, up64, sizeof(*up64))) { 6761da177e4SLinus Torvalds err = -EFAULT; 6771da177e4SLinus Torvalds break; 6781da177e4SLinus Torvalds } 6791da177e4SLinus Torvalds err = __get_user(m.msg_perm.uid, &up64->msg_perm.uid); 6801da177e4SLinus Torvalds err |= __get_user(m.msg_perm.gid, &up64->msg_perm.gid); 6811da177e4SLinus Torvalds err |= __get_user(m.msg_perm.mode, &up64->msg_perm.mode); 6821da177e4SLinus Torvalds err |= __get_user(m.msg_qbytes, &up64->msg_qbytes); 6831da177e4SLinus Torvalds } else { 6841da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, up32, sizeof(*up32))) { 6851da177e4SLinus Torvalds err = -EFAULT; 6861da177e4SLinus Torvalds break; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds err = __get_user(m.msg_perm.uid, &up32->msg_perm.uid); 6891da177e4SLinus Torvalds err |= __get_user(m.msg_perm.gid, &up32->msg_perm.gid); 6901da177e4SLinus Torvalds err |= __get_user(m.msg_perm.mode, &up32->msg_perm.mode); 6911da177e4SLinus Torvalds err |= __get_user(m.msg_qbytes, &up32->msg_qbytes); 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds if (err) 6941da177e4SLinus Torvalds break; 6951da177e4SLinus Torvalds old_fs = get_fs(); 6961da177e4SLinus Torvalds set_fs(KERNEL_DS); 697219ac73aSAtsushi Nemoto err = sys_msgctl(first, second | IPC_64, (struct msqid_ds __user *)&m); 6981da177e4SLinus Torvalds set_fs(old_fs); 6991da177e4SLinus Torvalds break; 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds case IPC_STAT: 7021da177e4SLinus Torvalds case MSG_STAT: 7031da177e4SLinus Torvalds old_fs = get_fs(); 7041da177e4SLinus Torvalds set_fs(KERNEL_DS); 705219ac73aSAtsushi Nemoto err = sys_msgctl(first, second | IPC_64, (struct msqid_ds __user *)&m); 7061da177e4SLinus Torvalds set_fs(old_fs); 7071da177e4SLinus Torvalds if (second & IPC_64) { 7081da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { 7091da177e4SLinus Torvalds err = -EFAULT; 7101da177e4SLinus Torvalds break; 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds err2 = __put_user(m.msg_perm.key, &up64->msg_perm.key); 7131da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.uid, &up64->msg_perm.uid); 7141da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.gid, &up64->msg_perm.gid); 7151da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cuid, &up64->msg_perm.cuid); 7161da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cgid, &up64->msg_perm.cgid); 7171da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.mode, &up64->msg_perm.mode); 7181da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.seq, &up64->msg_perm.seq); 7191da177e4SLinus Torvalds err2 |= __put_user(m.msg_stime, &up64->msg_stime); 7201da177e4SLinus Torvalds err2 |= __put_user(m.msg_rtime, &up64->msg_rtime); 7211da177e4SLinus Torvalds err2 |= __put_user(m.msg_ctime, &up64->msg_ctime); 7221da177e4SLinus Torvalds err2 |= __put_user(m.msg_cbytes, &up64->msg_cbytes); 7231da177e4SLinus Torvalds err2 |= __put_user(m.msg_qnum, &up64->msg_qnum); 7241da177e4SLinus Torvalds err2 |= __put_user(m.msg_qbytes, &up64->msg_qbytes); 7251da177e4SLinus Torvalds err2 |= __put_user(m.msg_lspid, &up64->msg_lspid); 7261da177e4SLinus Torvalds err2 |= __put_user(m.msg_lrpid, &up64->msg_lrpid); 7271da177e4SLinus Torvalds if (err2) 7281da177e4SLinus Torvalds err = -EFAULT; 7291da177e4SLinus Torvalds } else { 7301da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { 7311da177e4SLinus Torvalds err = -EFAULT; 7321da177e4SLinus Torvalds break; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds err2 = __put_user(m.msg_perm.key, &up32->msg_perm.key); 7351da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.uid, &up32->msg_perm.uid); 7361da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.gid, &up32->msg_perm.gid); 7371da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cuid, &up32->msg_perm.cuid); 7381da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cgid, &up32->msg_perm.cgid); 7391da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.mode, &up32->msg_perm.mode); 7401da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.seq, &up32->msg_perm.seq); 7411da177e4SLinus Torvalds err2 |= __put_user(m.msg_stime, &up32->msg_stime); 7421da177e4SLinus Torvalds err2 |= __put_user(m.msg_rtime, &up32->msg_rtime); 7431da177e4SLinus Torvalds err2 |= __put_user(m.msg_ctime, &up32->msg_ctime); 7441da177e4SLinus Torvalds err2 |= __put_user(m.msg_cbytes, &up32->msg_cbytes); 7451da177e4SLinus Torvalds err2 |= __put_user(m.msg_qnum, &up32->msg_qnum); 7461da177e4SLinus Torvalds err2 |= __put_user(m.msg_qbytes, &up32->msg_qbytes); 7471da177e4SLinus Torvalds err2 |= __put_user(m.msg_lspid, &up32->msg_lspid); 7481da177e4SLinus Torvalds err2 |= __put_user(m.msg_lrpid, &up32->msg_lrpid); 7491da177e4SLinus Torvalds if (err2) 7501da177e4SLinus Torvalds err = -EFAULT; 7511da177e4SLinus Torvalds } 7521da177e4SLinus Torvalds break; 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds return err; 7561da177e4SLinus Torvalds } 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds static int 759219ac73aSAtsushi Nemoto do_sys32_shmat (int first, int second, int third, int version, void __user *uptr) 7601da177e4SLinus Torvalds { 7611da177e4SLinus Torvalds unsigned long raddr; 762219ac73aSAtsushi Nemoto u32 __user *uaddr = (u32 __user *)A((u32)third); 7631da177e4SLinus Torvalds int err = -EINVAL; 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds if (version == 1) 7661da177e4SLinus Torvalds return err; 7671da177e4SLinus Torvalds err = do_shmat (first, uptr, second, &raddr); 7681da177e4SLinus Torvalds if (err) 7691da177e4SLinus Torvalds return err; 7701da177e4SLinus Torvalds err = put_user (raddr, uaddr); 7711da177e4SLinus Torvalds return err; 7721da177e4SLinus Torvalds } 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds struct shm_info32 { 7751da177e4SLinus Torvalds int used_ids; 7761da177e4SLinus Torvalds u32 shm_tot, shm_rss, shm_swp; 7771da177e4SLinus Torvalds u32 swap_attempts, swap_successes; 7781da177e4SLinus Torvalds }; 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds static int 781219ac73aSAtsushi Nemoto do_sys32_shmctl (int first, int second, void __user *uptr) 7821da177e4SLinus Torvalds { 783219ac73aSAtsushi Nemoto struct shmid64_ds32 __user *up64 = (struct shmid64_ds32 __user *)uptr; 784219ac73aSAtsushi Nemoto struct shmid_ds32 __user *up32 = (struct shmid_ds32 __user *)uptr; 785219ac73aSAtsushi Nemoto struct shm_info32 __user *uip = (struct shm_info32 __user *)uptr; 7861da177e4SLinus Torvalds int err = -EFAULT, err2; 7871da177e4SLinus Torvalds struct shmid64_ds s64; 7881da177e4SLinus Torvalds mm_segment_t old_fs; 7891da177e4SLinus Torvalds struct shm_info si; 7901da177e4SLinus Torvalds struct shmid_ds s; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds switch (second & ~IPC_64) { 7931da177e4SLinus Torvalds case IPC_INFO: 7941da177e4SLinus Torvalds second = IPC_INFO; /* So that we don't have to translate it */ 7951da177e4SLinus Torvalds case IPC_RMID: 7961da177e4SLinus Torvalds case SHM_LOCK: 7971da177e4SLinus Torvalds case SHM_UNLOCK: 798219ac73aSAtsushi Nemoto err = sys_shmctl(first, second, (struct shmid_ds __user *)uptr); 7991da177e4SLinus Torvalds break; 8001da177e4SLinus Torvalds case IPC_SET: 8011da177e4SLinus Torvalds if (second & IPC_64) { 8021da177e4SLinus Torvalds err = get_user(s.shm_perm.uid, &up64->shm_perm.uid); 8031da177e4SLinus Torvalds err |= get_user(s.shm_perm.gid, &up64->shm_perm.gid); 8041da177e4SLinus Torvalds err |= get_user(s.shm_perm.mode, &up64->shm_perm.mode); 8051da177e4SLinus Torvalds } else { 8061da177e4SLinus Torvalds err = get_user(s.shm_perm.uid, &up32->shm_perm.uid); 8071da177e4SLinus Torvalds err |= get_user(s.shm_perm.gid, &up32->shm_perm.gid); 8081da177e4SLinus Torvalds err |= get_user(s.shm_perm.mode, &up32->shm_perm.mode); 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds if (err) 8111da177e4SLinus Torvalds break; 8121da177e4SLinus Torvalds old_fs = get_fs(); 8131da177e4SLinus Torvalds set_fs(KERNEL_DS); 814219ac73aSAtsushi Nemoto err = sys_shmctl(first, second & ~IPC_64, (struct shmid_ds __user *)&s); 8151da177e4SLinus Torvalds set_fs(old_fs); 8161da177e4SLinus Torvalds break; 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds case IPC_STAT: 8191da177e4SLinus Torvalds case SHM_STAT: 8201da177e4SLinus Torvalds old_fs = get_fs(); 8211da177e4SLinus Torvalds set_fs(KERNEL_DS); 822219ac73aSAtsushi Nemoto err = sys_shmctl(first, second | IPC_64, (void __user *) &s64); 8231da177e4SLinus Torvalds set_fs(old_fs); 8241da177e4SLinus Torvalds if (err < 0) 8251da177e4SLinus Torvalds break; 8261da177e4SLinus Torvalds if (second & IPC_64) { 8271da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { 8281da177e4SLinus Torvalds err = -EFAULT; 8291da177e4SLinus Torvalds break; 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds err2 = __put_user(s64.shm_perm.key, &up64->shm_perm.key); 8321da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.uid, &up64->shm_perm.uid); 8331da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.gid, &up64->shm_perm.gid); 8341da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cuid, &up64->shm_perm.cuid); 8351da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cgid, &up64->shm_perm.cgid); 8361da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.mode, &up64->shm_perm.mode); 8371da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.seq, &up64->shm_perm.seq); 8381da177e4SLinus Torvalds err2 |= __put_user(s64.shm_atime, &up64->shm_atime); 8391da177e4SLinus Torvalds err2 |= __put_user(s64.shm_dtime, &up64->shm_dtime); 8401da177e4SLinus Torvalds err2 |= __put_user(s64.shm_ctime, &up64->shm_ctime); 8411da177e4SLinus Torvalds err2 |= __put_user(s64.shm_segsz, &up64->shm_segsz); 8421da177e4SLinus Torvalds err2 |= __put_user(s64.shm_nattch, &up64->shm_nattch); 8431da177e4SLinus Torvalds err2 |= __put_user(s64.shm_cpid, &up64->shm_cpid); 8441da177e4SLinus Torvalds err2 |= __put_user(s64.shm_lpid, &up64->shm_lpid); 8451da177e4SLinus Torvalds } else { 8461da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { 8471da177e4SLinus Torvalds err = -EFAULT; 8481da177e4SLinus Torvalds break; 8491da177e4SLinus Torvalds } 8501da177e4SLinus Torvalds err2 = __put_user(s64.shm_perm.key, &up32->shm_perm.key); 8511da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.uid, &up32->shm_perm.uid); 8521da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.gid, &up32->shm_perm.gid); 8531da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cuid, &up32->shm_perm.cuid); 8541da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cgid, &up32->shm_perm.cgid); 8551da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.mode, &up32->shm_perm.mode); 8561da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.seq, &up32->shm_perm.seq); 8571da177e4SLinus Torvalds err2 |= __put_user(s64.shm_atime, &up32->shm_atime); 8581da177e4SLinus Torvalds err2 |= __put_user(s64.shm_dtime, &up32->shm_dtime); 8591da177e4SLinus Torvalds err2 |= __put_user(s64.shm_ctime, &up32->shm_ctime); 8601da177e4SLinus Torvalds err2 |= __put_user(s64.shm_segsz, &up32->shm_segsz); 8611da177e4SLinus Torvalds err2 |= __put_user(s64.shm_nattch, &up32->shm_nattch); 8621da177e4SLinus Torvalds err2 |= __put_user(s64.shm_cpid, &up32->shm_cpid); 8631da177e4SLinus Torvalds err2 |= __put_user(s64.shm_lpid, &up32->shm_lpid); 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds if (err2) 8661da177e4SLinus Torvalds err = -EFAULT; 8671da177e4SLinus Torvalds break; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds case SHM_INFO: 8701da177e4SLinus Torvalds old_fs = get_fs(); 8711da177e4SLinus Torvalds set_fs(KERNEL_DS); 872219ac73aSAtsushi Nemoto err = sys_shmctl(first, second, (void __user *)&si); 8731da177e4SLinus Torvalds set_fs(old_fs); 8741da177e4SLinus Torvalds if (err < 0) 8751da177e4SLinus Torvalds break; 8761da177e4SLinus Torvalds err2 = put_user(si.used_ids, &uip->used_ids); 8771da177e4SLinus Torvalds err2 |= __put_user(si.shm_tot, &uip->shm_tot); 8781da177e4SLinus Torvalds err2 |= __put_user(si.shm_rss, &uip->shm_rss); 8791da177e4SLinus Torvalds err2 |= __put_user(si.shm_swp, &uip->shm_swp); 8801da177e4SLinus Torvalds err2 |= __put_user(si.swap_attempts, &uip->swap_attempts); 8811da177e4SLinus Torvalds err2 |= __put_user (si.swap_successes, &uip->swap_successes); 8821da177e4SLinus Torvalds if (err2) 8831da177e4SLinus Torvalds err = -EFAULT; 8841da177e4SLinus Torvalds break; 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds default: 8871da177e4SLinus Torvalds err = -EINVAL; 8881da177e4SLinus Torvalds break; 8891da177e4SLinus Torvalds } 8901da177e4SLinus Torvalds 8911da177e4SLinus Torvalds return err; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds 894219ac73aSAtsushi Nemoto static int sys32_semtimedop(int semid, struct sembuf __user *tsems, int nsems, 895219ac73aSAtsushi Nemoto const struct compat_timespec __user *timeout32) 8961da177e4SLinus Torvalds { 8971da177e4SLinus Torvalds struct compat_timespec t32; 898219ac73aSAtsushi Nemoto struct timespec __user *t64 = compat_alloc_user_space(sizeof(*t64)); 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds if (copy_from_user(&t32, timeout32, sizeof(t32))) 9011da177e4SLinus Torvalds return -EFAULT; 9021da177e4SLinus Torvalds 9031da177e4SLinus Torvalds if (put_user(t32.tv_sec, &t64->tv_sec) || 9041da177e4SLinus Torvalds put_user(t32.tv_nsec, &t64->tv_nsec)) 9051da177e4SLinus Torvalds return -EFAULT; 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds return sys_semtimedop(semid, tsems, nsems, t64); 9081da177e4SLinus Torvalds } 9091da177e4SLinus Torvalds 9101da177e4SLinus Torvalds asmlinkage long 9111da177e4SLinus Torvalds sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth) 9121da177e4SLinus Torvalds { 9131da177e4SLinus Torvalds int version, err; 9141da177e4SLinus Torvalds 9151da177e4SLinus Torvalds version = call >> 16; /* hack for backward compatibility */ 9161da177e4SLinus Torvalds call &= 0xffff; 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds switch (call) { 9191da177e4SLinus Torvalds case SEMOP: 9201da177e4SLinus Torvalds /* struct sembuf is the same on 32 and 64bit :)) */ 921219ac73aSAtsushi Nemoto err = sys_semtimedop (first, (struct sembuf __user *)AA(ptr), second, 9221da177e4SLinus Torvalds NULL); 9231da177e4SLinus Torvalds break; 9241da177e4SLinus Torvalds case SEMTIMEDOP: 925219ac73aSAtsushi Nemoto err = sys32_semtimedop (first, (struct sembuf __user *)AA(ptr), second, 9261da177e4SLinus Torvalds (const struct compat_timespec __user *)AA(fifth)); 9271da177e4SLinus Torvalds break; 9281da177e4SLinus Torvalds case SEMGET: 9291da177e4SLinus Torvalds err = sys_semget (first, second, third); 9301da177e4SLinus Torvalds break; 9311da177e4SLinus Torvalds case SEMCTL: 9321da177e4SLinus Torvalds err = do_sys32_semctl (first, second, third, 933219ac73aSAtsushi Nemoto (void __user *)AA(ptr)); 9341da177e4SLinus Torvalds break; 9351da177e4SLinus Torvalds 9361da177e4SLinus Torvalds case MSGSND: 9371da177e4SLinus Torvalds err = do_sys32_msgsnd (first, second, third, 938219ac73aSAtsushi Nemoto (void __user *)AA(ptr)); 9391da177e4SLinus Torvalds break; 9401da177e4SLinus Torvalds case MSGRCV: 9411da177e4SLinus Torvalds err = do_sys32_msgrcv (first, second, fifth, third, 942219ac73aSAtsushi Nemoto version, (void __user *)AA(ptr)); 9431da177e4SLinus Torvalds break; 9441da177e4SLinus Torvalds case MSGGET: 9451da177e4SLinus Torvalds err = sys_msgget ((key_t) first, second); 9461da177e4SLinus Torvalds break; 9471da177e4SLinus Torvalds case MSGCTL: 948219ac73aSAtsushi Nemoto err = do_sys32_msgctl (first, second, (void __user *)AA(ptr)); 9491da177e4SLinus Torvalds break; 9501da177e4SLinus Torvalds 9511da177e4SLinus Torvalds case SHMAT: 9521da177e4SLinus Torvalds err = do_sys32_shmat (first, second, third, 953219ac73aSAtsushi Nemoto version, (void __user *)AA(ptr)); 9541da177e4SLinus Torvalds break; 9551da177e4SLinus Torvalds case SHMDT: 956219ac73aSAtsushi Nemoto err = sys_shmdt ((char __user *)A(ptr)); 9571da177e4SLinus Torvalds break; 9581da177e4SLinus Torvalds case SHMGET: 9591da177e4SLinus Torvalds err = sys_shmget (first, (unsigned)second, third); 9601da177e4SLinus Torvalds break; 9611da177e4SLinus Torvalds case SHMCTL: 962219ac73aSAtsushi Nemoto err = do_sys32_shmctl (first, second, (void __user *)AA(ptr)); 9631da177e4SLinus Torvalds break; 9641da177e4SLinus Torvalds default: 9651da177e4SLinus Torvalds err = -EINVAL; 9661da177e4SLinus Torvalds break; 9671da177e4SLinus Torvalds } 9681da177e4SLinus Torvalds 9691da177e4SLinus Torvalds return err; 9701da177e4SLinus Torvalds } 9711da177e4SLinus Torvalds 9721da177e4SLinus Torvalds asmlinkage long sys32_shmat(int shmid, char __user *shmaddr, 973219ac73aSAtsushi Nemoto int shmflg, int32_t __user *addr) 9741da177e4SLinus Torvalds { 9751da177e4SLinus Torvalds unsigned long raddr; 9761da177e4SLinus Torvalds int err; 9771da177e4SLinus Torvalds 9781da177e4SLinus Torvalds err = do_shmat(shmid, shmaddr, shmflg, &raddr); 9791da177e4SLinus Torvalds if (err) 9801da177e4SLinus Torvalds return err; 9811da177e4SLinus Torvalds 9821da177e4SLinus Torvalds return put_user(raddr, addr); 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds 9851da177e4SLinus Torvalds struct sysctl_args32 9861da177e4SLinus Torvalds { 9871da177e4SLinus Torvalds compat_caddr_t name; 9881da177e4SLinus Torvalds int nlen; 9891da177e4SLinus Torvalds compat_caddr_t oldval; 9901da177e4SLinus Torvalds compat_caddr_t oldlenp; 9911da177e4SLinus Torvalds compat_caddr_t newval; 9921da177e4SLinus Torvalds compat_size_t newlen; 9931da177e4SLinus Torvalds unsigned int __unused[4]; 9941da177e4SLinus Torvalds }; 9951da177e4SLinus Torvalds 996b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 9971da177e4SLinus Torvalds 998219ac73aSAtsushi Nemoto asmlinkage long sys32_sysctl(struct sysctl_args32 __user *args) 9991da177e4SLinus Torvalds { 10001da177e4SLinus Torvalds struct sysctl_args32 tmp; 10011da177e4SLinus Torvalds int error; 1002219ac73aSAtsushi Nemoto size_t oldlen; 1003219ac73aSAtsushi Nemoto size_t __user *oldlenp = NULL; 1004219ac73aSAtsushi Nemoto unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7; 10051da177e4SLinus Torvalds 10061da177e4SLinus Torvalds if (copy_from_user(&tmp, args, sizeof(tmp))) 10071da177e4SLinus Torvalds return -EFAULT; 10081da177e4SLinus Torvalds 10091da177e4SLinus Torvalds if (tmp.oldval && tmp.oldlenp) { 10101da177e4SLinus Torvalds /* Duh, this is ugly and might not work if sysctl_args 10111da177e4SLinus Torvalds is in read-only memory, but do_sysctl does indirectly 10121da177e4SLinus Torvalds a lot of uaccess in both directions and we'd have to 10131da177e4SLinus Torvalds basically copy the whole sysctl.c here, and 10141da177e4SLinus Torvalds glibc's __sysctl uses rw memory for the structure 10151da177e4SLinus Torvalds anyway. */ 1016219ac73aSAtsushi Nemoto if (get_user(oldlen, (u32 __user *)A(tmp.oldlenp)) || 1017219ac73aSAtsushi Nemoto put_user(oldlen, (size_t __user *)addr)) 10181da177e4SLinus Torvalds return -EFAULT; 1019219ac73aSAtsushi Nemoto oldlenp = (size_t __user *)addr; 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds lock_kernel(); 1023219ac73aSAtsushi Nemoto error = do_sysctl((int __user *)A(tmp.name), tmp.nlen, (void __user *)A(tmp.oldval), 1024219ac73aSAtsushi Nemoto oldlenp, (void __user *)A(tmp.newval), tmp.newlen); 10251da177e4SLinus Torvalds unlock_kernel(); 10261da177e4SLinus Torvalds if (oldlenp) { 10271da177e4SLinus Torvalds if (!error) { 1028219ac73aSAtsushi Nemoto if (get_user(oldlen, (size_t __user *)addr) || 1029219ac73aSAtsushi Nemoto put_user(oldlen, (u32 __user *)A(tmp.oldlenp))) 10301da177e4SLinus Torvalds error = -EFAULT; 10311da177e4SLinus Torvalds } 10321da177e4SLinus Torvalds copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); 10331da177e4SLinus Torvalds } 10341da177e4SLinus Torvalds return error; 10351da177e4SLinus Torvalds } 10361da177e4SLinus Torvalds 1037b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 10381da177e4SLinus Torvalds 1039219ac73aSAtsushi Nemoto asmlinkage long sys32_newuname(struct new_utsname __user * name) 10401da177e4SLinus Torvalds { 10411da177e4SLinus Torvalds int ret = 0; 10421da177e4SLinus Torvalds 10431da177e4SLinus Torvalds down_read(&uts_sem); 1044e9ff3990SSerge E. Hallyn if (copy_to_user(name, utsname(), sizeof *name)) 10451da177e4SLinus Torvalds ret = -EFAULT; 10461da177e4SLinus Torvalds up_read(&uts_sem); 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds if (current->personality == PER_LINUX32 && !ret) 10491da177e4SLinus Torvalds if (copy_to_user(name->machine, "mips\0\0\0", 8)) 10501da177e4SLinus Torvalds ret = -EFAULT; 10511da177e4SLinus Torvalds 10521da177e4SLinus Torvalds return ret; 10531da177e4SLinus Torvalds } 10541da177e4SLinus Torvalds 10551da177e4SLinus Torvalds asmlinkage int sys32_personality(unsigned long personality) 10561da177e4SLinus Torvalds { 10571da177e4SLinus Torvalds int ret; 1058*53571ce4SThiemo Seufer personality &= 0xffffffff; 1059*53571ce4SThiemo Seufer if (personality(current->personality) == PER_LINUX32 && 1060*53571ce4SThiemo Seufer personality == PER_LINUX) 10611da177e4SLinus Torvalds personality = PER_LINUX32; 10621da177e4SLinus Torvalds ret = sys_personality(personality); 10631da177e4SLinus Torvalds if (ret == PER_LINUX32) 10641da177e4SLinus Torvalds ret = PER_LINUX; 10651da177e4SLinus Torvalds return ret; 10661da177e4SLinus Torvalds } 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds /* ustat compatibility */ 10691da177e4SLinus Torvalds struct ustat32 { 10701da177e4SLinus Torvalds compat_daddr_t f_tfree; 10711da177e4SLinus Torvalds compat_ino_t f_tinode; 10721da177e4SLinus Torvalds char f_fname[6]; 10731da177e4SLinus Torvalds char f_fpack[6]; 10741da177e4SLinus Torvalds }; 10751da177e4SLinus Torvalds 1076219ac73aSAtsushi Nemoto extern asmlinkage long sys_ustat(dev_t dev, struct ustat __user * ubuf); 10771da177e4SLinus Torvalds 1078219ac73aSAtsushi Nemoto asmlinkage int sys32_ustat(dev_t dev, struct ustat32 __user * ubuf32) 10791da177e4SLinus Torvalds { 10801da177e4SLinus Torvalds int err; 10811da177e4SLinus Torvalds struct ustat tmp; 10821da177e4SLinus Torvalds struct ustat32 tmp32; 10831da177e4SLinus Torvalds mm_segment_t old_fs = get_fs(); 10841da177e4SLinus Torvalds 10851da177e4SLinus Torvalds set_fs(KERNEL_DS); 1086219ac73aSAtsushi Nemoto err = sys_ustat(dev, (struct ustat __user *)&tmp); 10871da177e4SLinus Torvalds set_fs (old_fs); 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvalds if (err) 10901da177e4SLinus Torvalds goto out; 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds memset(&tmp32,0,sizeof(struct ustat32)); 10931da177e4SLinus Torvalds tmp32.f_tfree = tmp.f_tfree; 10941da177e4SLinus Torvalds tmp32.f_tinode = tmp.f_tinode; 10951da177e4SLinus Torvalds 10961da177e4SLinus Torvalds err = copy_to_user(ubuf32,&tmp32,sizeof(struct ustat32)) ? -EFAULT : 0; 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds out: 10991da177e4SLinus Torvalds return err; 11001da177e4SLinus Torvalds } 11011da177e4SLinus Torvalds 1102219ac73aSAtsushi Nemoto asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, 11031da177e4SLinus Torvalds s32 count) 11041da177e4SLinus Torvalds { 11051da177e4SLinus Torvalds mm_segment_t old_fs = get_fs(); 11061da177e4SLinus Torvalds int ret; 11071da177e4SLinus Torvalds off_t of; 11081da177e4SLinus Torvalds 11091da177e4SLinus Torvalds if (offset && get_user(of, offset)) 11101da177e4SLinus Torvalds return -EFAULT; 11111da177e4SLinus Torvalds 11121da177e4SLinus Torvalds set_fs(KERNEL_DS); 1113219ac73aSAtsushi Nemoto ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count); 11141da177e4SLinus Torvalds set_fs(old_fs); 11151da177e4SLinus Torvalds 11161da177e4SLinus Torvalds if (offset && put_user(of, offset)) 11171da177e4SLinus Torvalds return -EFAULT; 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds return ret; 11201da177e4SLinus Torvalds } 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, 11231da177e4SLinus Torvalds size_t count) 11241da177e4SLinus Torvalds { 11251da177e4SLinus Torvalds return sys_readahead(fd, merge_64(a2, a3), count); 11261da177e4SLinus Torvalds } 11271da177e4SLinus Torvalds 1128a8d587a7SRalf Baechle asmlinkage long sys32_sync_file_range(int fd, int __pad, 1129a8d587a7SRalf Baechle unsigned long a2, unsigned long a3, 1130a8d587a7SRalf Baechle unsigned long a4, unsigned long a5, 1131a8d587a7SRalf Baechle int flags) 1132a8d587a7SRalf Baechle { 1133a8d587a7SRalf Baechle return sys_sync_file_range(fd, 1134a8d587a7SRalf Baechle merge_64(a2, a3), merge_64(a4, a5), 1135a8d587a7SRalf Baechle flags); 1136a8d587a7SRalf Baechle } 1137a8d587a7SRalf Baechle 11381da177e4SLinus Torvalds /* Argument list sizes for sys_socketcall */ 11391da177e4SLinus Torvalds #define AL(x) ((x) * sizeof(unsigned int)) 11401da177e4SLinus Torvalds static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 11411da177e4SLinus Torvalds AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 11421da177e4SLinus Torvalds AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)}; 11431da177e4SLinus Torvalds #undef AL 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds /* 11461da177e4SLinus Torvalds * System call vectors. 11471da177e4SLinus Torvalds * 11481da177e4SLinus Torvalds * Argument checking cleaned up. Saved 20% in size. 11491da177e4SLinus Torvalds * This function doesn't need to set the kernel lock because 11501da177e4SLinus Torvalds * it is set by the callees. 11511da177e4SLinus Torvalds */ 11521da177e4SLinus Torvalds 1153219ac73aSAtsushi Nemoto asmlinkage long sys32_socketcall(int call, unsigned int __user *args32) 11541da177e4SLinus Torvalds { 11551da177e4SLinus Torvalds unsigned int a[6]; 11561da177e4SLinus Torvalds unsigned int a0,a1; 11571da177e4SLinus Torvalds int err; 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds extern asmlinkage long sys_socket(int family, int type, int protocol); 11601da177e4SLinus Torvalds extern asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen); 11611da177e4SLinus Torvalds extern asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen); 11621da177e4SLinus Torvalds extern asmlinkage long sys_listen(int fd, int backlog); 11631da177e4SLinus Torvalds extern asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen); 11641da177e4SLinus Torvalds extern asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); 11651da177e4SLinus Torvalds extern asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); 11661da177e4SLinus Torvalds extern asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec); 11671da177e4SLinus Torvalds extern asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags); 11681da177e4SLinus Torvalds extern asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags, 11691da177e4SLinus Torvalds struct sockaddr __user *addr, int addr_len); 11701da177e4SLinus Torvalds extern asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags); 11711da177e4SLinus Torvalds extern asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags, 11721da177e4SLinus Torvalds struct sockaddr __user *addr, int __user *addr_len); 11731da177e4SLinus Torvalds extern asmlinkage long sys_shutdown(int fd, int how); 11741da177e4SLinus Torvalds extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen); 1175219ac73aSAtsushi Nemoto extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen); 11761da177e4SLinus Torvalds extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags); 11771da177e4SLinus Torvalds extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags); 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds if(call<1||call>SYS_RECVMSG) 11811da177e4SLinus Torvalds return -EINVAL; 11821da177e4SLinus Torvalds 11831da177e4SLinus Torvalds /* copy_from_user should be SMP safe. */ 11841da177e4SLinus Torvalds if (copy_from_user(a, args32, socketcall_nargs[call])) 11851da177e4SLinus Torvalds return -EFAULT; 11861da177e4SLinus Torvalds 11871da177e4SLinus Torvalds a0=a[0]; 11881da177e4SLinus Torvalds a1=a[1]; 11891da177e4SLinus Torvalds 11901da177e4SLinus Torvalds switch(call) 11911da177e4SLinus Torvalds { 11921da177e4SLinus Torvalds case SYS_SOCKET: 11931da177e4SLinus Torvalds err = sys_socket(a0,a1,a[2]); 11941da177e4SLinus Torvalds break; 11951da177e4SLinus Torvalds case SYS_BIND: 11961da177e4SLinus Torvalds err = sys_bind(a0,(struct sockaddr __user *)A(a1), a[2]); 11971da177e4SLinus Torvalds break; 11981da177e4SLinus Torvalds case SYS_CONNECT: 11991da177e4SLinus Torvalds err = sys_connect(a0, (struct sockaddr __user *)A(a1), a[2]); 12001da177e4SLinus Torvalds break; 12011da177e4SLinus Torvalds case SYS_LISTEN: 12021da177e4SLinus Torvalds err = sys_listen(a0,a1); 12031da177e4SLinus Torvalds break; 12041da177e4SLinus Torvalds case SYS_ACCEPT: 12051da177e4SLinus Torvalds err = sys_accept(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 12061da177e4SLinus Torvalds break; 12071da177e4SLinus Torvalds case SYS_GETSOCKNAME: 12081da177e4SLinus Torvalds err = sys_getsockname(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 12091da177e4SLinus Torvalds break; 12101da177e4SLinus Torvalds case SYS_GETPEERNAME: 12111da177e4SLinus Torvalds err = sys_getpeername(a0, (struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 12121da177e4SLinus Torvalds break; 12131da177e4SLinus Torvalds case SYS_SOCKETPAIR: 12141da177e4SLinus Torvalds err = sys_socketpair(a0,a1, a[2], (int __user *)A(a[3])); 12151da177e4SLinus Torvalds break; 12161da177e4SLinus Torvalds case SYS_SEND: 12171da177e4SLinus Torvalds err = sys_send(a0, (void __user *)A(a1), a[2], a[3]); 12181da177e4SLinus Torvalds break; 12191da177e4SLinus Torvalds case SYS_SENDTO: 12201da177e4SLinus Torvalds err = sys_sendto(a0,(void __user *)A(a1), a[2], a[3], 12211da177e4SLinus Torvalds (struct sockaddr __user *)A(a[4]), a[5]); 12221da177e4SLinus Torvalds break; 12231da177e4SLinus Torvalds case SYS_RECV: 12241da177e4SLinus Torvalds err = sys_recv(a0, (void __user *)A(a1), a[2], a[3]); 12251da177e4SLinus Torvalds break; 12261da177e4SLinus Torvalds case SYS_RECVFROM: 12271da177e4SLinus Torvalds err = sys_recvfrom(a0, (void __user *)A(a1), a[2], a[3], 12281da177e4SLinus Torvalds (struct sockaddr __user *)A(a[4]), (int __user *)A(a[5])); 12291da177e4SLinus Torvalds break; 12301da177e4SLinus Torvalds case SYS_SHUTDOWN: 12311da177e4SLinus Torvalds err = sys_shutdown(a0,a1); 12321da177e4SLinus Torvalds break; 12331da177e4SLinus Torvalds case SYS_SETSOCKOPT: 12341da177e4SLinus Torvalds err = sys_setsockopt(a0, a1, a[2], (char __user *)A(a[3]), a[4]); 12351da177e4SLinus Torvalds break; 12361da177e4SLinus Torvalds case SYS_GETSOCKOPT: 12371da177e4SLinus Torvalds err = sys_getsockopt(a0, a1, a[2], (char __user *)A(a[3]), (int __user *)A(a[4])); 12381da177e4SLinus Torvalds break; 12391da177e4SLinus Torvalds case SYS_SENDMSG: 12401da177e4SLinus Torvalds err = sys_sendmsg(a0, (struct msghdr __user *) A(a1), a[2]); 12411da177e4SLinus Torvalds break; 12421da177e4SLinus Torvalds case SYS_RECVMSG: 12431da177e4SLinus Torvalds err = sys_recvmsg(a0, (struct msghdr __user *) A(a1), a[2]); 12441da177e4SLinus Torvalds break; 12451da177e4SLinus Torvalds default: 12461da177e4SLinus Torvalds err = -EINVAL; 12471da177e4SLinus Torvalds break; 12481da177e4SLinus Torvalds } 12491da177e4SLinus Torvalds return err; 12501da177e4SLinus Torvalds } 1251d1abb6a2SRalf Baechle 1252d1abb6a2SRalf Baechle struct sigevent32 { 1253d1abb6a2SRalf Baechle u32 sigev_value; 1254d1abb6a2SRalf Baechle u32 sigev_signo; 1255d1abb6a2SRalf Baechle u32 sigev_notify; 1256d1abb6a2SRalf Baechle u32 payload[(64 / 4) - 3]; 1257d1abb6a2SRalf Baechle }; 1258d1abb6a2SRalf Baechle 1259d1abb6a2SRalf Baechle extern asmlinkage long 1260d1abb6a2SRalf Baechle sys_timer_create(clockid_t which_clock, 1261d1abb6a2SRalf Baechle struct sigevent __user *timer_event_spec, 1262d1abb6a2SRalf Baechle timer_t __user * created_timer_id); 1263d1abb6a2SRalf Baechle 1264d1abb6a2SRalf Baechle long 1265d1abb6a2SRalf Baechle sys32_timer_create(u32 clock, struct sigevent32 __user *se32, timer_t __user *timer_id) 1266d1abb6a2SRalf Baechle { 1267d1abb6a2SRalf Baechle struct sigevent __user *p = NULL; 1268d1abb6a2SRalf Baechle if (se32) { 1269d1abb6a2SRalf Baechle struct sigevent se; 1270d1abb6a2SRalf Baechle p = compat_alloc_user_space(sizeof(struct sigevent)); 1271d1abb6a2SRalf Baechle memset(&se, 0, sizeof(struct sigevent)); 1272d1abb6a2SRalf Baechle if (get_user(se.sigev_value.sival_int, &se32->sigev_value) || 1273d1abb6a2SRalf Baechle __get_user(se.sigev_signo, &se32->sigev_signo) || 1274d1abb6a2SRalf Baechle __get_user(se.sigev_notify, &se32->sigev_notify) || 1275d1abb6a2SRalf Baechle __copy_from_user(&se._sigev_un._pad, &se32->payload, 1276d1abb6a2SRalf Baechle sizeof(se32->payload)) || 1277d1abb6a2SRalf Baechle copy_to_user(p, &se, sizeof(se))) 1278d1abb6a2SRalf Baechle return -EFAULT; 1279d1abb6a2SRalf Baechle } 1280d1abb6a2SRalf Baechle return sys_timer_create(clock, p, timer_id); 1281d1abb6a2SRalf Baechle } 1282d1abb6a2SRalf Baechle 12833c37026dSRalf Baechle save_static_function(sys32_clone); 12843c37026dSRalf Baechle __attribute_used__ noinline static int 12853c37026dSRalf Baechle _sys32_clone(nabi_no_regargs struct pt_regs regs) 12863c37026dSRalf Baechle { 12873c37026dSRalf Baechle unsigned long clone_flags; 12883c37026dSRalf Baechle unsigned long newsp; 12893c37026dSRalf Baechle int __user *parent_tidptr, *child_tidptr; 12903c37026dSRalf Baechle 12913c37026dSRalf Baechle clone_flags = regs.regs[4]; 12923c37026dSRalf Baechle newsp = regs.regs[5]; 12933c37026dSRalf Baechle if (!newsp) 12943c37026dSRalf Baechle newsp = regs.regs[29]; 1295219ac73aSAtsushi Nemoto parent_tidptr = (int __user *) regs.regs[6]; 12963c37026dSRalf Baechle 12973c37026dSRalf Baechle /* Use __dummy4 instead of getting it off the stack, so that 12983c37026dSRalf Baechle syscall() works. */ 12993c37026dSRalf Baechle child_tidptr = (int __user *) __dummy4; 13003c37026dSRalf Baechle return do_fork(clone_flags, newsp, ®s, 0, 13013c37026dSRalf Baechle parent_tidptr, child_tidptr); 13023c37026dSRalf Baechle } 1303