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/config.h> 91da177e4SLinus Torvalds #include <linux/compiler.h> 101da177e4SLinus Torvalds #include <linux/mm.h> 111da177e4SLinus Torvalds #include <linux/errno.h> 121da177e4SLinus Torvalds #include <linux/file.h> 131da177e4SLinus Torvalds #include <linux/smp_lock.h> 141da177e4SLinus Torvalds #include <linux/highuid.h> 151da177e4SLinus Torvalds #include <linux/dirent.h> 161da177e4SLinus Torvalds #include <linux/resource.h> 171da177e4SLinus Torvalds #include <linux/highmem.h> 181da177e4SLinus Torvalds #include <linux/time.h> 191da177e4SLinus Torvalds #include <linux/times.h> 201da177e4SLinus Torvalds #include <linux/poll.h> 211da177e4SLinus Torvalds #include <linux/slab.h> 221da177e4SLinus Torvalds #include <linux/skbuff.h> 231da177e4SLinus Torvalds #include <linux/filter.h> 241da177e4SLinus Torvalds #include <linux/shm.h> 251da177e4SLinus Torvalds #include <linux/sem.h> 261da177e4SLinus Torvalds #include <linux/msg.h> 271da177e4SLinus Torvalds #include <linux/icmpv6.h> 281da177e4SLinus Torvalds #include <linux/syscalls.h> 291da177e4SLinus Torvalds #include <linux/sysctl.h> 301da177e4SLinus Torvalds #include <linux/utime.h> 311da177e4SLinus Torvalds #include <linux/utsname.h> 321da177e4SLinus Torvalds #include <linux/personality.h> 331da177e4SLinus Torvalds #include <linux/timex.h> 341da177e4SLinus Torvalds #include <linux/dnotify.h> 351da177e4SLinus Torvalds #include <linux/module.h> 361da177e4SLinus Torvalds #include <linux/binfmts.h> 371da177e4SLinus Torvalds #include <linux/security.h> 381da177e4SLinus Torvalds #include <linux/compat.h> 391da177e4SLinus Torvalds #include <linux/vfs.h> 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #include <net/sock.h> 421da177e4SLinus Torvalds #include <net/scm.h> 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds #include <asm/ipc.h> 451da177e4SLinus Torvalds #include <asm/sim.h> 461da177e4SLinus Torvalds #include <asm/uaccess.h> 471da177e4SLinus Torvalds #include <asm/mmu_context.h> 481da177e4SLinus Torvalds #include <asm/mman.h> 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds /* Use this to get at 32-bit user passed pointers. */ 511da177e4SLinus Torvalds /* A() macro should be used for places where you e.g. 521da177e4SLinus Torvalds have some internal variable u32 and just want to get 531da177e4SLinus Torvalds rid of a compiler warning. AA() has to be used in 541da177e4SLinus Torvalds places where you want to convert a function argument 551da177e4SLinus Torvalds to 32bit pointer or when you e.g. access pt_regs 561da177e4SLinus Torvalds structure and want to consider 32bit registers only. 571da177e4SLinus Torvalds */ 581da177e4SLinus Torvalds #define A(__x) ((unsigned long)(__x)) 591da177e4SLinus Torvalds #define AA(__x) ((unsigned long)((int)__x)) 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds #ifdef __MIPSEB__ 621da177e4SLinus Torvalds #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) 631da177e4SLinus Torvalds #endif 641da177e4SLinus Torvalds #ifdef __MIPSEL__ 651da177e4SLinus Torvalds #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) 661da177e4SLinus Torvalds #endif 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds /* 691da177e4SLinus Torvalds * Revalidate the inode. This is required for proper NFS attribute caching. 701da177e4SLinus Torvalds */ 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf) 731da177e4SLinus Torvalds { 741da177e4SLinus Torvalds struct compat_stat tmp; 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev)) 771da177e4SLinus Torvalds return -EOVERFLOW; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds memset(&tmp, 0, sizeof(tmp)); 801da177e4SLinus Torvalds tmp.st_dev = new_encode_dev(stat->dev); 811da177e4SLinus Torvalds tmp.st_ino = stat->ino; 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; 1091da177e4SLinus Torvalds if (!(flags & MAP_ANONYMOUS)) { 1101da177e4SLinus Torvalds error = -EBADF; 1111da177e4SLinus Torvalds file = fget(fd); 1121da177e4SLinus Torvalds if (!file) 1131da177e4SLinus Torvalds goto out; 1141da177e4SLinus Torvalds } 1151da177e4SLinus Torvalds flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds down_write(¤t->mm->mmap_sem); 1181da177e4SLinus Torvalds error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); 1191da177e4SLinus Torvalds up_write(¤t->mm->mmap_sem); 1201da177e4SLinus Torvalds if (file) 1211da177e4SLinus Torvalds fput(file); 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds out: 1241da177e4SLinus Torvalds return error; 1251da177e4SLinus Torvalds } 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds asmlinkage int sys_truncate64(const char *path, unsigned int high, 1291da177e4SLinus Torvalds unsigned int low) 1301da177e4SLinus Torvalds { 1311da177e4SLinus Torvalds if ((int)high < 0) 1321da177e4SLinus Torvalds return -EINVAL; 1331da177e4SLinus Torvalds return sys_truncate(path, ((long) high << 32) | low); 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds asmlinkage int sys_ftruncate64(unsigned int fd, unsigned int high, 1371da177e4SLinus Torvalds unsigned int low) 1381da177e4SLinus Torvalds { 1391da177e4SLinus Torvalds if ((int)high < 0) 1401da177e4SLinus Torvalds return -EINVAL; 1411da177e4SLinus Torvalds return sys_ftruncate(fd, ((long) high << 32) | low); 1421da177e4SLinus Torvalds } 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds /* 1451da177e4SLinus Torvalds * sys_execve() executes a new program. 1461da177e4SLinus Torvalds */ 1471da177e4SLinus Torvalds asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs) 1481da177e4SLinus Torvalds { 1491da177e4SLinus Torvalds int error; 1501da177e4SLinus Torvalds char * filename; 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds filename = getname(compat_ptr(regs.regs[4])); 1531da177e4SLinus Torvalds error = PTR_ERR(filename); 1541da177e4SLinus Torvalds if (IS_ERR(filename)) 1551da177e4SLinus Torvalds goto out; 1561da177e4SLinus Torvalds error = compat_do_execve(filename, compat_ptr(regs.regs[5]), 1571da177e4SLinus Torvalds compat_ptr(regs.regs[6]), ®s); 1581da177e4SLinus Torvalds putname(filename); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds out: 1611da177e4SLinus Torvalds return error; 1621da177e4SLinus Torvalds } 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds struct dirent32 { 1651da177e4SLinus Torvalds unsigned int d_ino; 1661da177e4SLinus Torvalds unsigned int d_off; 1671da177e4SLinus Torvalds unsigned short d_reclen; 1681da177e4SLinus Torvalds char d_name[NAME_MAX + 1]; 1691da177e4SLinus Torvalds }; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds static void 1721da177e4SLinus Torvalds xlate_dirent(void *dirent64, void *dirent32, long n) 1731da177e4SLinus Torvalds { 1741da177e4SLinus Torvalds long off; 1751da177e4SLinus Torvalds struct dirent *dirp; 1761da177e4SLinus Torvalds struct dirent32 *dirp32; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds off = 0; 1791da177e4SLinus Torvalds while (off < n) { 1801da177e4SLinus Torvalds dirp = (struct dirent *)(dirent64 + off); 1811da177e4SLinus Torvalds dirp32 = (struct dirent32 *)(dirent32 + off); 1821da177e4SLinus Torvalds off += dirp->d_reclen; 1831da177e4SLinus Torvalds dirp32->d_ino = dirp->d_ino; 1841da177e4SLinus Torvalds dirp32->d_off = (unsigned int)dirp->d_off; 1851da177e4SLinus Torvalds dirp32->d_reclen = dirp->d_reclen; 1861da177e4SLinus Torvalds strncpy(dirp32->d_name, dirp->d_name, dirp->d_reclen - ((3 * 4) + 2)); 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds return; 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds asmlinkage long 1921da177e4SLinus Torvalds sys32_getdents(unsigned int fd, void * dirent32, unsigned int count) 1931da177e4SLinus Torvalds { 1941da177e4SLinus Torvalds long n; 1951da177e4SLinus Torvalds void *dirent64; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds dirent64 = (void *)((unsigned long)(dirent32 + (sizeof(long) - 1)) & ~(sizeof(long) - 1)); 1981da177e4SLinus Torvalds if ((n = sys_getdents(fd, dirent64, count - (dirent64 - dirent32))) < 0) 1991da177e4SLinus Torvalds return(n); 2001da177e4SLinus Torvalds xlate_dirent(dirent64, dirent32, n); 2011da177e4SLinus Torvalds return(n); 2021da177e4SLinus Torvalds } 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds asmlinkage int old_readdir(unsigned int fd, void * dirent, unsigned int count); 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds asmlinkage int 2071da177e4SLinus Torvalds sys32_readdir(unsigned int fd, void * dirent32, unsigned int count) 2081da177e4SLinus Torvalds { 2091da177e4SLinus Torvalds int n; 2101da177e4SLinus Torvalds struct dirent dirent64; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds if ((n = old_readdir(fd, &dirent64, count)) < 0) 2131da177e4SLinus Torvalds return(n); 2141da177e4SLinus Torvalds xlate_dirent(&dirent64, dirent32, dirent64.d_reclen); 2151da177e4SLinus Torvalds return(n); 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds asmlinkage int 2191da177e4SLinus Torvalds sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options) 2201da177e4SLinus Torvalds { 221b6e203d8SRalf Baechle return compat_sys_wait4(pid, stat_addr, options, NULL); 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds 224*54f2da75SRalf Baechle asmlinkage long 225*54f2da75SRalf Baechle sysn32_waitid(int which, compat_pid_t pid, 226*54f2da75SRalf Baechle siginfo_t __user *uinfo, int options, 227*54f2da75SRalf Baechle struct compat_rusage __user *uru) 228*54f2da75SRalf Baechle { 229*54f2da75SRalf Baechle struct rusage ru; 230*54f2da75SRalf Baechle long ret; 231*54f2da75SRalf Baechle mm_segment_t old_fs = get_fs(); 232*54f2da75SRalf Baechle 233*54f2da75SRalf Baechle set_fs (KERNEL_DS); 234*54f2da75SRalf Baechle ret = sys_waitid(which, pid, uinfo, options, 235*54f2da75SRalf Baechle uru ? (struct rusage __user *) &ru : NULL); 236*54f2da75SRalf Baechle set_fs (old_fs); 237*54f2da75SRalf Baechle 238*54f2da75SRalf Baechle if (ret < 0 || uinfo->si_signo == 0) 239*54f2da75SRalf Baechle return ret; 240*54f2da75SRalf Baechle 241*54f2da75SRalf Baechle if (uru) 242*54f2da75SRalf Baechle ret = put_compat_rusage(&ru, uru); 243*54f2da75SRalf Baechle return ret; 244*54f2da75SRalf Baechle } 245*54f2da75SRalf Baechle 2461da177e4SLinus Torvalds struct sysinfo32 { 2471da177e4SLinus Torvalds s32 uptime; 2481da177e4SLinus Torvalds u32 loads[3]; 2491da177e4SLinus Torvalds u32 totalram; 2501da177e4SLinus Torvalds u32 freeram; 2511da177e4SLinus Torvalds u32 sharedram; 2521da177e4SLinus Torvalds u32 bufferram; 2531da177e4SLinus Torvalds u32 totalswap; 2541da177e4SLinus Torvalds u32 freeswap; 2551da177e4SLinus Torvalds u16 procs; 2561da177e4SLinus Torvalds u32 totalhigh; 2571da177e4SLinus Torvalds u32 freehigh; 2581da177e4SLinus Torvalds u32 mem_unit; 2591da177e4SLinus Torvalds char _f[8]; 2601da177e4SLinus Torvalds }; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds asmlinkage int sys32_sysinfo(struct sysinfo32 *info) 2631da177e4SLinus Torvalds { 2641da177e4SLinus Torvalds struct sysinfo s; 2651da177e4SLinus Torvalds int ret, err; 2661da177e4SLinus Torvalds mm_segment_t old_fs = get_fs (); 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds set_fs (KERNEL_DS); 2691da177e4SLinus Torvalds ret = sys_sysinfo(&s); 2701da177e4SLinus Torvalds set_fs (old_fs); 2711da177e4SLinus Torvalds err = put_user (s.uptime, &info->uptime); 2721da177e4SLinus Torvalds err |= __put_user (s.loads[0], &info->loads[0]); 2731da177e4SLinus Torvalds err |= __put_user (s.loads[1], &info->loads[1]); 2741da177e4SLinus Torvalds err |= __put_user (s.loads[2], &info->loads[2]); 2751da177e4SLinus Torvalds err |= __put_user (s.totalram, &info->totalram); 2761da177e4SLinus Torvalds err |= __put_user (s.freeram, &info->freeram); 2771da177e4SLinus Torvalds err |= __put_user (s.sharedram, &info->sharedram); 2781da177e4SLinus Torvalds err |= __put_user (s.bufferram, &info->bufferram); 2791da177e4SLinus Torvalds err |= __put_user (s.totalswap, &info->totalswap); 2801da177e4SLinus Torvalds err |= __put_user (s.freeswap, &info->freeswap); 2811da177e4SLinus Torvalds err |= __put_user (s.procs, &info->procs); 2821da177e4SLinus Torvalds err |= __put_user (s.totalhigh, &info->totalhigh); 2831da177e4SLinus Torvalds err |= __put_user (s.freehigh, &info->freehigh); 2841da177e4SLinus Torvalds err |= __put_user (s.mem_unit, &info->mem_unit); 2851da177e4SLinus Torvalds if (err) 2861da177e4SLinus Torvalds return -EFAULT; 2871da177e4SLinus Torvalds return ret; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds #define RLIM_INFINITY32 0x7fffffff 2911da177e4SLinus Torvalds #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds struct rlimit32 { 2941da177e4SLinus Torvalds int rlim_cur; 2951da177e4SLinus Torvalds int rlim_max; 2961da177e4SLinus Torvalds }; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds #ifdef __MIPSEB__ 2991da177e4SLinus Torvalds asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, 3001da177e4SLinus Torvalds int length_hi, int length_lo) 3011da177e4SLinus Torvalds #endif 3021da177e4SLinus Torvalds #ifdef __MIPSEL__ 3031da177e4SLinus Torvalds asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, 3041da177e4SLinus Torvalds int length_lo, int length_hi) 3051da177e4SLinus Torvalds #endif 3061da177e4SLinus Torvalds { 3071da177e4SLinus Torvalds loff_t length; 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds return sys_truncate(path, length); 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds #ifdef __MIPSEB__ 3151da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, 3161da177e4SLinus Torvalds int length_hi, int length_lo) 3171da177e4SLinus Torvalds #endif 3181da177e4SLinus Torvalds #ifdef __MIPSEL__ 3191da177e4SLinus Torvalds asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, 3201da177e4SLinus Torvalds int length_lo, int length_hi) 3211da177e4SLinus Torvalds #endif 3221da177e4SLinus Torvalds { 3231da177e4SLinus Torvalds loff_t length; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds return sys_ftruncate(fd, length); 3281da177e4SLinus Torvalds } 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds static inline long 3311da177e4SLinus Torvalds get_tv32(struct timeval *o, struct compat_timeval *i) 3321da177e4SLinus Torvalds { 3331da177e4SLinus Torvalds return (!access_ok(VERIFY_READ, i, sizeof(*i)) || 3341da177e4SLinus Torvalds (__get_user(o->tv_sec, &i->tv_sec) | 3351da177e4SLinus Torvalds __get_user(o->tv_usec, &i->tv_usec))); 3361da177e4SLinus Torvalds } 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds static inline long 3391da177e4SLinus Torvalds put_tv32(struct compat_timeval *o, struct timeval *i) 3401da177e4SLinus Torvalds { 3411da177e4SLinus Torvalds return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || 3421da177e4SLinus Torvalds (__put_user(i->tv_sec, &o->tv_sec) | 3431da177e4SLinus Torvalds __put_user(i->tv_usec, &o->tv_usec))); 3441da177e4SLinus Torvalds } 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds extern struct timezone sys_tz; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds asmlinkage int 3491da177e4SLinus Torvalds sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz) 3501da177e4SLinus Torvalds { 3511da177e4SLinus Torvalds if (tv) { 3521da177e4SLinus Torvalds struct timeval ktv; 3531da177e4SLinus Torvalds do_gettimeofday(&ktv); 3541da177e4SLinus Torvalds if (put_tv32(tv, &ktv)) 3551da177e4SLinus Torvalds return -EFAULT; 3561da177e4SLinus Torvalds } 3571da177e4SLinus Torvalds if (tz) { 3581da177e4SLinus Torvalds if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) 3591da177e4SLinus Torvalds return -EFAULT; 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds return 0; 3621da177e4SLinus Torvalds } 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds static inline long get_ts32(struct timespec *o, struct compat_timeval *i) 3651da177e4SLinus Torvalds { 3661da177e4SLinus Torvalds long usec; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, i, sizeof(*i))) 3691da177e4SLinus Torvalds return -EFAULT; 3701da177e4SLinus Torvalds if (__get_user(o->tv_sec, &i->tv_sec)) 3711da177e4SLinus Torvalds return -EFAULT; 3721da177e4SLinus Torvalds if (__get_user(usec, &i->tv_usec)) 3731da177e4SLinus Torvalds return -EFAULT; 3741da177e4SLinus Torvalds o->tv_nsec = usec * 1000; 3751da177e4SLinus Torvalds return 0; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds asmlinkage int 3791da177e4SLinus Torvalds sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz) 3801da177e4SLinus Torvalds { 3811da177e4SLinus Torvalds struct timespec kts; 3821da177e4SLinus Torvalds struct timezone ktz; 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds if (tv) { 3851da177e4SLinus Torvalds if (get_ts32(&kts, tv)) 3861da177e4SLinus Torvalds return -EFAULT; 3871da177e4SLinus Torvalds } 3881da177e4SLinus Torvalds if (tz) { 3891da177e4SLinus Torvalds if (copy_from_user(&ktz, tz, sizeof(ktz))) 3901da177e4SLinus Torvalds return -EFAULT; 3911da177e4SLinus Torvalds } 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); 3941da177e4SLinus Torvalds } 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high, 3971da177e4SLinus Torvalds unsigned int offset_low, loff_t * result, 3981da177e4SLinus Torvalds unsigned int origin) 3991da177e4SLinus Torvalds { 4001da177e4SLinus Torvalds return sys_llseek(fd, offset_high, offset_low, result, origin); 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + 4041da177e4SLinus Torvalds lseek back to original location. They fail just like lseek does on 4051da177e4SLinus Torvalds non-seekable files. */ 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds asmlinkage ssize_t sys32_pread(unsigned int fd, char * buf, 4081da177e4SLinus Torvalds size_t count, u32 unused, u64 a4, u64 a5) 4091da177e4SLinus Torvalds { 4101da177e4SLinus Torvalds ssize_t ret; 4111da177e4SLinus Torvalds struct file * file; 4121da177e4SLinus Torvalds ssize_t (*read)(struct file *, char *, size_t, loff_t *); 4131da177e4SLinus Torvalds loff_t pos; 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds ret = -EBADF; 4161da177e4SLinus Torvalds file = fget(fd); 4171da177e4SLinus Torvalds if (!file) 4181da177e4SLinus Torvalds goto bad_file; 4191da177e4SLinus Torvalds if (!(file->f_mode & FMODE_READ)) 4201da177e4SLinus Torvalds goto out; 4211da177e4SLinus Torvalds pos = merge_64(a4, a5); 4221da177e4SLinus Torvalds ret = rw_verify_area(READ, file, &pos, count); 4231da177e4SLinus Torvalds if (ret) 4241da177e4SLinus Torvalds goto out; 4251da177e4SLinus Torvalds ret = -EINVAL; 4261da177e4SLinus Torvalds if (!file->f_op || !(read = file->f_op->read)) 4271da177e4SLinus Torvalds goto out; 4281da177e4SLinus Torvalds if (pos < 0) 4291da177e4SLinus Torvalds goto out; 4301da177e4SLinus Torvalds ret = -ESPIPE; 4311da177e4SLinus Torvalds if (!(file->f_mode & FMODE_PREAD)) 4321da177e4SLinus Torvalds goto out; 4331da177e4SLinus Torvalds ret = read(file, buf, count, &pos); 4341da177e4SLinus Torvalds if (ret > 0) 4351da177e4SLinus Torvalds dnotify_parent(file->f_dentry, DN_ACCESS); 4361da177e4SLinus Torvalds out: 4371da177e4SLinus Torvalds fput(file); 4381da177e4SLinus Torvalds bad_file: 4391da177e4SLinus Torvalds return ret; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char * buf, 4431da177e4SLinus Torvalds size_t count, u32 unused, u64 a4, u64 a5) 4441da177e4SLinus Torvalds { 4451da177e4SLinus Torvalds ssize_t ret; 4461da177e4SLinus Torvalds struct file * file; 4471da177e4SLinus Torvalds ssize_t (*write)(struct file *, const char *, size_t, loff_t *); 4481da177e4SLinus Torvalds loff_t pos; 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds ret = -EBADF; 4511da177e4SLinus Torvalds file = fget(fd); 4521da177e4SLinus Torvalds if (!file) 4531da177e4SLinus Torvalds goto bad_file; 4541da177e4SLinus Torvalds if (!(file->f_mode & FMODE_WRITE)) 4551da177e4SLinus Torvalds goto out; 4561da177e4SLinus Torvalds pos = merge_64(a4, a5); 4571da177e4SLinus Torvalds ret = rw_verify_area(WRITE, file, &pos, count); 4581da177e4SLinus Torvalds if (ret) 4591da177e4SLinus Torvalds goto out; 4601da177e4SLinus Torvalds ret = -EINVAL; 4611da177e4SLinus Torvalds if (!file->f_op || !(write = file->f_op->write)) 4621da177e4SLinus Torvalds goto out; 4631da177e4SLinus Torvalds if (pos < 0) 4641da177e4SLinus Torvalds goto out; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds ret = -ESPIPE; 4671da177e4SLinus Torvalds if (!(file->f_mode & FMODE_PWRITE)) 4681da177e4SLinus Torvalds goto out; 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds ret = write(file, buf, count, &pos); 4711da177e4SLinus Torvalds if (ret > 0) 4721da177e4SLinus Torvalds dnotify_parent(file->f_dentry, DN_MODIFY); 4731da177e4SLinus Torvalds out: 4741da177e4SLinus Torvalds fput(file); 4751da177e4SLinus Torvalds bad_file: 4761da177e4SLinus Torvalds return ret; 4771da177e4SLinus Torvalds } 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid, 4801da177e4SLinus Torvalds struct compat_timespec *interval) 4811da177e4SLinus Torvalds { 4821da177e4SLinus Torvalds struct timespec t; 4831da177e4SLinus Torvalds int ret; 4841da177e4SLinus Torvalds mm_segment_t old_fs = get_fs (); 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds set_fs (KERNEL_DS); 4871da177e4SLinus Torvalds ret = sys_sched_rr_get_interval(pid, &t); 4881da177e4SLinus Torvalds set_fs (old_fs); 4891da177e4SLinus Torvalds if (put_user (t.tv_sec, &interval->tv_sec) || 4901da177e4SLinus Torvalds __put_user (t.tv_nsec, &interval->tv_nsec)) 4911da177e4SLinus Torvalds return -EFAULT; 4921da177e4SLinus Torvalds return ret; 4931da177e4SLinus Torvalds } 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds struct msgbuf32 { s32 mtype; char mtext[1]; }; 4961da177e4SLinus Torvalds 4971da177e4SLinus Torvalds struct ipc_perm32 4981da177e4SLinus Torvalds { 4991da177e4SLinus Torvalds key_t key; 500202e5979SStephen Rothwell __compat_uid_t uid; 501202e5979SStephen Rothwell __compat_gid_t gid; 502202e5979SStephen Rothwell __compat_uid_t cuid; 503202e5979SStephen Rothwell __compat_gid_t cgid; 5041da177e4SLinus Torvalds compat_mode_t mode; 5051da177e4SLinus Torvalds unsigned short seq; 5061da177e4SLinus Torvalds }; 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds struct ipc64_perm32 { 5091da177e4SLinus Torvalds key_t key; 510202e5979SStephen Rothwell __compat_uid_t uid; 511202e5979SStephen Rothwell __compat_gid_t gid; 512202e5979SStephen Rothwell __compat_uid_t cuid; 513202e5979SStephen Rothwell __compat_gid_t cgid; 5141da177e4SLinus Torvalds compat_mode_t mode; 5151da177e4SLinus Torvalds unsigned short seq; 5161da177e4SLinus Torvalds unsigned short __pad1; 5171da177e4SLinus Torvalds unsigned int __unused1; 5181da177e4SLinus Torvalds unsigned int __unused2; 5191da177e4SLinus Torvalds }; 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds struct semid_ds32 { 5221da177e4SLinus Torvalds struct ipc_perm32 sem_perm; /* permissions .. see ipc.h */ 5231da177e4SLinus Torvalds compat_time_t sem_otime; /* last semop time */ 5241da177e4SLinus Torvalds compat_time_t sem_ctime; /* last change time */ 5251da177e4SLinus Torvalds u32 sem_base; /* ptr to first semaphore in array */ 5261da177e4SLinus Torvalds u32 sem_pending; /* pending operations to be processed */ 5271da177e4SLinus Torvalds u32 sem_pending_last; /* last pending operation */ 5281da177e4SLinus Torvalds u32 undo; /* undo requests on this array */ 5291da177e4SLinus Torvalds unsigned short sem_nsems; /* no. of semaphores in array */ 5301da177e4SLinus Torvalds }; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds struct semid64_ds32 { 5331da177e4SLinus Torvalds struct ipc64_perm32 sem_perm; 5341da177e4SLinus Torvalds compat_time_t sem_otime; 5351da177e4SLinus Torvalds compat_time_t sem_ctime; 5361da177e4SLinus Torvalds unsigned int sem_nsems; 5371da177e4SLinus Torvalds unsigned int __unused1; 5381da177e4SLinus Torvalds unsigned int __unused2; 5391da177e4SLinus Torvalds }; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds struct msqid_ds32 5421da177e4SLinus Torvalds { 5431da177e4SLinus Torvalds struct ipc_perm32 msg_perm; 5441da177e4SLinus Torvalds u32 msg_first; 5451da177e4SLinus Torvalds u32 msg_last; 5461da177e4SLinus Torvalds compat_time_t msg_stime; 5471da177e4SLinus Torvalds compat_time_t msg_rtime; 5481da177e4SLinus Torvalds compat_time_t msg_ctime; 5491da177e4SLinus Torvalds u32 wwait; 5501da177e4SLinus Torvalds u32 rwait; 5511da177e4SLinus Torvalds unsigned short msg_cbytes; 5521da177e4SLinus Torvalds unsigned short msg_qnum; 5531da177e4SLinus Torvalds unsigned short msg_qbytes; 5541da177e4SLinus Torvalds compat_ipc_pid_t msg_lspid; 5551da177e4SLinus Torvalds compat_ipc_pid_t msg_lrpid; 5561da177e4SLinus Torvalds }; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds struct msqid64_ds32 { 5591da177e4SLinus Torvalds struct ipc64_perm32 msg_perm; 5601da177e4SLinus Torvalds compat_time_t msg_stime; 5611da177e4SLinus Torvalds unsigned int __unused1; 5621da177e4SLinus Torvalds compat_time_t msg_rtime; 5631da177e4SLinus Torvalds unsigned int __unused2; 5641da177e4SLinus Torvalds compat_time_t msg_ctime; 5651da177e4SLinus Torvalds unsigned int __unused3; 5661da177e4SLinus Torvalds unsigned int msg_cbytes; 5671da177e4SLinus Torvalds unsigned int msg_qnum; 5681da177e4SLinus Torvalds unsigned int msg_qbytes; 5691da177e4SLinus Torvalds compat_pid_t msg_lspid; 5701da177e4SLinus Torvalds compat_pid_t msg_lrpid; 5711da177e4SLinus Torvalds unsigned int __unused4; 5721da177e4SLinus Torvalds unsigned int __unused5; 5731da177e4SLinus Torvalds }; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds struct shmid_ds32 { 5761da177e4SLinus Torvalds struct ipc_perm32 shm_perm; 5771da177e4SLinus Torvalds int shm_segsz; 5781da177e4SLinus Torvalds compat_time_t shm_atime; 5791da177e4SLinus Torvalds compat_time_t shm_dtime; 5801da177e4SLinus Torvalds compat_time_t shm_ctime; 5811da177e4SLinus Torvalds compat_ipc_pid_t shm_cpid; 5821da177e4SLinus Torvalds compat_ipc_pid_t shm_lpid; 5831da177e4SLinus Torvalds unsigned short shm_nattch; 5841da177e4SLinus Torvalds }; 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds struct shmid64_ds32 { 5871da177e4SLinus Torvalds struct ipc64_perm32 shm_perm; 5881da177e4SLinus Torvalds compat_size_t shm_segsz; 5891da177e4SLinus Torvalds compat_time_t shm_atime; 5901da177e4SLinus Torvalds compat_time_t shm_dtime; 5911da177e4SLinus Torvalds compat_time_t shm_ctime; 5921da177e4SLinus Torvalds compat_pid_t shm_cpid; 5931da177e4SLinus Torvalds compat_pid_t shm_lpid; 5941da177e4SLinus Torvalds unsigned int shm_nattch; 5951da177e4SLinus Torvalds unsigned int __unused1; 5961da177e4SLinus Torvalds unsigned int __unused2; 5971da177e4SLinus Torvalds }; 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds struct ipc_kludge32 { 6001da177e4SLinus Torvalds u32 msgp; 6011da177e4SLinus Torvalds s32 msgtyp; 6021da177e4SLinus Torvalds }; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds static int 6051da177e4SLinus Torvalds do_sys32_semctl(int first, int second, int third, void *uptr) 6061da177e4SLinus Torvalds { 6071da177e4SLinus Torvalds union semun fourth; 6081da177e4SLinus Torvalds u32 pad; 6091da177e4SLinus Torvalds int err, err2; 6101da177e4SLinus Torvalds struct semid64_ds s; 6111da177e4SLinus Torvalds mm_segment_t old_fs; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds if (!uptr) 6141da177e4SLinus Torvalds return -EINVAL; 6151da177e4SLinus Torvalds err = -EFAULT; 6161da177e4SLinus Torvalds if (get_user (pad, (u32 *)uptr)) 6171da177e4SLinus Torvalds return err; 6181da177e4SLinus Torvalds if ((third & ~IPC_64) == SETVAL) 6191da177e4SLinus Torvalds fourth.val = (int)pad; 6201da177e4SLinus Torvalds else 6211da177e4SLinus Torvalds fourth.__pad = (void *)A(pad); 6221da177e4SLinus Torvalds switch (third & ~IPC_64) { 6231da177e4SLinus Torvalds case IPC_INFO: 6241da177e4SLinus Torvalds case IPC_RMID: 6251da177e4SLinus Torvalds case IPC_SET: 6261da177e4SLinus Torvalds case SEM_INFO: 6271da177e4SLinus Torvalds case GETVAL: 6281da177e4SLinus Torvalds case GETPID: 6291da177e4SLinus Torvalds case GETNCNT: 6301da177e4SLinus Torvalds case GETZCNT: 6311da177e4SLinus Torvalds case GETALL: 6321da177e4SLinus Torvalds case SETVAL: 6331da177e4SLinus Torvalds case SETALL: 6341da177e4SLinus Torvalds err = sys_semctl (first, second, third, fourth); 6351da177e4SLinus Torvalds break; 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds case IPC_STAT: 6381da177e4SLinus Torvalds case SEM_STAT: 6391da177e4SLinus Torvalds fourth.__pad = &s; 6401da177e4SLinus Torvalds old_fs = get_fs(); 6411da177e4SLinus Torvalds set_fs(KERNEL_DS); 6421da177e4SLinus Torvalds err = sys_semctl(first, second, third | IPC_64, fourth); 6431da177e4SLinus Torvalds set_fs(old_fs); 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds if (third & IPC_64) { 6461da177e4SLinus Torvalds struct semid64_ds32 *usp64 = (struct semid64_ds32 *) A(pad); 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) { 6491da177e4SLinus Torvalds err = -EFAULT; 6501da177e4SLinus Torvalds break; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds err2 = __put_user(s.sem_perm.key, &usp64->sem_perm.key); 6531da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.uid, &usp64->sem_perm.uid); 6541da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.gid, &usp64->sem_perm.gid); 6551da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cuid, &usp64->sem_perm.cuid); 6561da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cgid, &usp64->sem_perm.cgid); 6571da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.mode, &usp64->sem_perm.mode); 6581da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.seq, &usp64->sem_perm.seq); 6591da177e4SLinus Torvalds err2 |= __put_user(s.sem_otime, &usp64->sem_otime); 6601da177e4SLinus Torvalds err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime); 6611da177e4SLinus Torvalds err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems); 6621da177e4SLinus Torvalds } else { 6631da177e4SLinus Torvalds struct semid_ds32 *usp32 = (struct semid_ds32 *) A(pad); 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) { 6661da177e4SLinus Torvalds err = -EFAULT; 6671da177e4SLinus Torvalds break; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds err2 = __put_user(s.sem_perm.key, &usp32->sem_perm.key); 6701da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.uid, &usp32->sem_perm.uid); 6711da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.gid, &usp32->sem_perm.gid); 6721da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cuid, &usp32->sem_perm.cuid); 6731da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.cgid, &usp32->sem_perm.cgid); 6741da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.mode, &usp32->sem_perm.mode); 6751da177e4SLinus Torvalds err2 |= __put_user(s.sem_perm.seq, &usp32->sem_perm.seq); 6761da177e4SLinus Torvalds err2 |= __put_user(s.sem_otime, &usp32->sem_otime); 6771da177e4SLinus Torvalds err2 |= __put_user(s.sem_ctime, &usp32->sem_ctime); 6781da177e4SLinus Torvalds err2 |= __put_user(s.sem_nsems, &usp32->sem_nsems); 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds if (err2) 6811da177e4SLinus Torvalds err = -EFAULT; 6821da177e4SLinus Torvalds break; 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds default: 6851da177e4SLinus Torvalds err = - EINVAL; 6861da177e4SLinus Torvalds break; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds return err; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds static int 6931da177e4SLinus Torvalds do_sys32_msgsnd (int first, int second, int third, void *uptr) 6941da177e4SLinus Torvalds { 6951da177e4SLinus Torvalds struct msgbuf32 *up = (struct msgbuf32 *)uptr; 6961da177e4SLinus Torvalds struct msgbuf *p; 6971da177e4SLinus Torvalds mm_segment_t old_fs; 6981da177e4SLinus Torvalds int err; 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds if (second < 0) 7011da177e4SLinus Torvalds return -EINVAL; 7021da177e4SLinus Torvalds p = kmalloc (second + sizeof (struct msgbuf) 7031da177e4SLinus Torvalds + 4, GFP_USER); 7041da177e4SLinus Torvalds if (!p) 7051da177e4SLinus Torvalds return -ENOMEM; 7061da177e4SLinus Torvalds err = get_user (p->mtype, &up->mtype); 7071da177e4SLinus Torvalds if (err) 7081da177e4SLinus Torvalds goto out; 7091da177e4SLinus Torvalds err |= __copy_from_user (p->mtext, &up->mtext, second); 7101da177e4SLinus Torvalds if (err) 7111da177e4SLinus Torvalds goto out; 7121da177e4SLinus Torvalds old_fs = get_fs (); 7131da177e4SLinus Torvalds set_fs (KERNEL_DS); 7141da177e4SLinus Torvalds err = sys_msgsnd (first, p, second, third); 7151da177e4SLinus Torvalds set_fs (old_fs); 7161da177e4SLinus Torvalds out: 7171da177e4SLinus Torvalds kfree (p); 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds return err; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds static int 7231da177e4SLinus Torvalds do_sys32_msgrcv (int first, int second, int msgtyp, int third, 7241da177e4SLinus Torvalds int version, void *uptr) 7251da177e4SLinus Torvalds { 7261da177e4SLinus Torvalds struct msgbuf32 *up; 7271da177e4SLinus Torvalds struct msgbuf *p; 7281da177e4SLinus Torvalds mm_segment_t old_fs; 7291da177e4SLinus Torvalds int err; 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds if (!version) { 7321da177e4SLinus Torvalds struct ipc_kludge32 *uipck = (struct ipc_kludge32 *)uptr; 7331da177e4SLinus Torvalds struct ipc_kludge32 ipck; 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds err = -EINVAL; 7361da177e4SLinus Torvalds if (!uptr) 7371da177e4SLinus Torvalds goto out; 7381da177e4SLinus Torvalds err = -EFAULT; 7391da177e4SLinus Torvalds if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32))) 7401da177e4SLinus Torvalds goto out; 7411da177e4SLinus Torvalds uptr = (void *)AA(ipck.msgp); 7421da177e4SLinus Torvalds msgtyp = ipck.msgtyp; 7431da177e4SLinus Torvalds } 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds if (second < 0) 7461da177e4SLinus Torvalds return -EINVAL; 7471da177e4SLinus Torvalds err = -ENOMEM; 7481da177e4SLinus Torvalds p = kmalloc (second + sizeof (struct msgbuf) + 4, GFP_USER); 7491da177e4SLinus Torvalds if (!p) 7501da177e4SLinus Torvalds goto out; 7511da177e4SLinus Torvalds old_fs = get_fs (); 7521da177e4SLinus Torvalds set_fs (KERNEL_DS); 7531da177e4SLinus Torvalds err = sys_msgrcv (first, p, second + 4, msgtyp, third); 7541da177e4SLinus Torvalds set_fs (old_fs); 7551da177e4SLinus Torvalds if (err < 0) 7561da177e4SLinus Torvalds goto free_then_out; 7571da177e4SLinus Torvalds up = (struct msgbuf32 *)uptr; 7581da177e4SLinus Torvalds if (put_user (p->mtype, &up->mtype) || 7591da177e4SLinus Torvalds __copy_to_user (&up->mtext, p->mtext, err)) 7601da177e4SLinus Torvalds err = -EFAULT; 7611da177e4SLinus Torvalds free_then_out: 7621da177e4SLinus Torvalds kfree (p); 7631da177e4SLinus Torvalds out: 7641da177e4SLinus Torvalds return err; 7651da177e4SLinus Torvalds } 7661da177e4SLinus Torvalds 7671da177e4SLinus Torvalds static int 7681da177e4SLinus Torvalds do_sys32_msgctl (int first, int second, void *uptr) 7691da177e4SLinus Torvalds { 7701da177e4SLinus Torvalds int err = -EINVAL, err2; 7711da177e4SLinus Torvalds struct msqid64_ds m; 7721da177e4SLinus Torvalds struct msqid_ds32 *up32 = (struct msqid_ds32 *)uptr; 7731da177e4SLinus Torvalds struct msqid64_ds32 *up64 = (struct msqid64_ds32 *)uptr; 7741da177e4SLinus Torvalds mm_segment_t old_fs; 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds switch (second & ~IPC_64) { 7771da177e4SLinus Torvalds case IPC_INFO: 7781da177e4SLinus Torvalds case IPC_RMID: 7791da177e4SLinus Torvalds case MSG_INFO: 7801da177e4SLinus Torvalds err = sys_msgctl (first, second, (struct msqid_ds *)uptr); 7811da177e4SLinus Torvalds break; 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds case IPC_SET: 7841da177e4SLinus Torvalds if (second & IPC_64) { 7851da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, up64, sizeof(*up64))) { 7861da177e4SLinus Torvalds err = -EFAULT; 7871da177e4SLinus Torvalds break; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds err = __get_user(m.msg_perm.uid, &up64->msg_perm.uid); 7901da177e4SLinus Torvalds err |= __get_user(m.msg_perm.gid, &up64->msg_perm.gid); 7911da177e4SLinus Torvalds err |= __get_user(m.msg_perm.mode, &up64->msg_perm.mode); 7921da177e4SLinus Torvalds err |= __get_user(m.msg_qbytes, &up64->msg_qbytes); 7931da177e4SLinus Torvalds } else { 7941da177e4SLinus Torvalds if (!access_ok(VERIFY_READ, up32, sizeof(*up32))) { 7951da177e4SLinus Torvalds err = -EFAULT; 7961da177e4SLinus Torvalds break; 7971da177e4SLinus Torvalds } 7981da177e4SLinus Torvalds err = __get_user(m.msg_perm.uid, &up32->msg_perm.uid); 7991da177e4SLinus Torvalds err |= __get_user(m.msg_perm.gid, &up32->msg_perm.gid); 8001da177e4SLinus Torvalds err |= __get_user(m.msg_perm.mode, &up32->msg_perm.mode); 8011da177e4SLinus Torvalds err |= __get_user(m.msg_qbytes, &up32->msg_qbytes); 8021da177e4SLinus Torvalds } 8031da177e4SLinus Torvalds if (err) 8041da177e4SLinus Torvalds break; 8051da177e4SLinus Torvalds old_fs = get_fs(); 8061da177e4SLinus Torvalds set_fs(KERNEL_DS); 8071da177e4SLinus Torvalds err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); 8081da177e4SLinus Torvalds set_fs(old_fs); 8091da177e4SLinus Torvalds break; 8101da177e4SLinus Torvalds 8111da177e4SLinus Torvalds case IPC_STAT: 8121da177e4SLinus Torvalds case MSG_STAT: 8131da177e4SLinus Torvalds old_fs = get_fs(); 8141da177e4SLinus Torvalds set_fs(KERNEL_DS); 8151da177e4SLinus Torvalds err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); 8161da177e4SLinus Torvalds set_fs(old_fs); 8171da177e4SLinus Torvalds if (second & IPC_64) { 8181da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { 8191da177e4SLinus Torvalds err = -EFAULT; 8201da177e4SLinus Torvalds break; 8211da177e4SLinus Torvalds } 8221da177e4SLinus Torvalds err2 = __put_user(m.msg_perm.key, &up64->msg_perm.key); 8231da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.uid, &up64->msg_perm.uid); 8241da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.gid, &up64->msg_perm.gid); 8251da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cuid, &up64->msg_perm.cuid); 8261da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cgid, &up64->msg_perm.cgid); 8271da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.mode, &up64->msg_perm.mode); 8281da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.seq, &up64->msg_perm.seq); 8291da177e4SLinus Torvalds err2 |= __put_user(m.msg_stime, &up64->msg_stime); 8301da177e4SLinus Torvalds err2 |= __put_user(m.msg_rtime, &up64->msg_rtime); 8311da177e4SLinus Torvalds err2 |= __put_user(m.msg_ctime, &up64->msg_ctime); 8321da177e4SLinus Torvalds err2 |= __put_user(m.msg_cbytes, &up64->msg_cbytes); 8331da177e4SLinus Torvalds err2 |= __put_user(m.msg_qnum, &up64->msg_qnum); 8341da177e4SLinus Torvalds err2 |= __put_user(m.msg_qbytes, &up64->msg_qbytes); 8351da177e4SLinus Torvalds err2 |= __put_user(m.msg_lspid, &up64->msg_lspid); 8361da177e4SLinus Torvalds err2 |= __put_user(m.msg_lrpid, &up64->msg_lrpid); 8371da177e4SLinus Torvalds if (err2) 8381da177e4SLinus Torvalds err = -EFAULT; 8391da177e4SLinus Torvalds } else { 8401da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { 8411da177e4SLinus Torvalds err = -EFAULT; 8421da177e4SLinus Torvalds break; 8431da177e4SLinus Torvalds } 8441da177e4SLinus Torvalds err2 = __put_user(m.msg_perm.key, &up32->msg_perm.key); 8451da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.uid, &up32->msg_perm.uid); 8461da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.gid, &up32->msg_perm.gid); 8471da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cuid, &up32->msg_perm.cuid); 8481da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.cgid, &up32->msg_perm.cgid); 8491da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.mode, &up32->msg_perm.mode); 8501da177e4SLinus Torvalds err2 |= __put_user(m.msg_perm.seq, &up32->msg_perm.seq); 8511da177e4SLinus Torvalds err2 |= __put_user(m.msg_stime, &up32->msg_stime); 8521da177e4SLinus Torvalds err2 |= __put_user(m.msg_rtime, &up32->msg_rtime); 8531da177e4SLinus Torvalds err2 |= __put_user(m.msg_ctime, &up32->msg_ctime); 8541da177e4SLinus Torvalds err2 |= __put_user(m.msg_cbytes, &up32->msg_cbytes); 8551da177e4SLinus Torvalds err2 |= __put_user(m.msg_qnum, &up32->msg_qnum); 8561da177e4SLinus Torvalds err2 |= __put_user(m.msg_qbytes, &up32->msg_qbytes); 8571da177e4SLinus Torvalds err2 |= __put_user(m.msg_lspid, &up32->msg_lspid); 8581da177e4SLinus Torvalds err2 |= __put_user(m.msg_lrpid, &up32->msg_lrpid); 8591da177e4SLinus Torvalds if (err2) 8601da177e4SLinus Torvalds err = -EFAULT; 8611da177e4SLinus Torvalds } 8621da177e4SLinus Torvalds break; 8631da177e4SLinus Torvalds } 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds return err; 8661da177e4SLinus Torvalds } 8671da177e4SLinus Torvalds 8681da177e4SLinus Torvalds static int 8691da177e4SLinus Torvalds do_sys32_shmat (int first, int second, int third, int version, void *uptr) 8701da177e4SLinus Torvalds { 8711da177e4SLinus Torvalds unsigned long raddr; 8721da177e4SLinus Torvalds u32 *uaddr = (u32 *)A((u32)third); 8731da177e4SLinus Torvalds int err = -EINVAL; 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds if (version == 1) 8761da177e4SLinus Torvalds return err; 8771da177e4SLinus Torvalds err = do_shmat (first, uptr, second, &raddr); 8781da177e4SLinus Torvalds if (err) 8791da177e4SLinus Torvalds return err; 8801da177e4SLinus Torvalds err = put_user (raddr, uaddr); 8811da177e4SLinus Torvalds return err; 8821da177e4SLinus Torvalds } 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds struct shm_info32 { 8851da177e4SLinus Torvalds int used_ids; 8861da177e4SLinus Torvalds u32 shm_tot, shm_rss, shm_swp; 8871da177e4SLinus Torvalds u32 swap_attempts, swap_successes; 8881da177e4SLinus Torvalds }; 8891da177e4SLinus Torvalds 8901da177e4SLinus Torvalds static int 8911da177e4SLinus Torvalds do_sys32_shmctl (int first, int second, void *uptr) 8921da177e4SLinus Torvalds { 8931da177e4SLinus Torvalds struct shmid64_ds32 *up64 = (struct shmid64_ds32 *)uptr; 8941da177e4SLinus Torvalds struct shmid_ds32 *up32 = (struct shmid_ds32 *)uptr; 8951da177e4SLinus Torvalds struct shm_info32 *uip = (struct shm_info32 *)uptr; 8961da177e4SLinus Torvalds int err = -EFAULT, err2; 8971da177e4SLinus Torvalds struct shmid64_ds s64; 8981da177e4SLinus Torvalds mm_segment_t old_fs; 8991da177e4SLinus Torvalds struct shm_info si; 9001da177e4SLinus Torvalds struct shmid_ds s; 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds switch (second & ~IPC_64) { 9031da177e4SLinus Torvalds case IPC_INFO: 9041da177e4SLinus Torvalds second = IPC_INFO; /* So that we don't have to translate it */ 9051da177e4SLinus Torvalds case IPC_RMID: 9061da177e4SLinus Torvalds case SHM_LOCK: 9071da177e4SLinus Torvalds case SHM_UNLOCK: 9081da177e4SLinus Torvalds err = sys_shmctl(first, second, (struct shmid_ds *)uptr); 9091da177e4SLinus Torvalds break; 9101da177e4SLinus Torvalds case IPC_SET: 9111da177e4SLinus Torvalds if (second & IPC_64) { 9121da177e4SLinus Torvalds err = get_user(s.shm_perm.uid, &up64->shm_perm.uid); 9131da177e4SLinus Torvalds err |= get_user(s.shm_perm.gid, &up64->shm_perm.gid); 9141da177e4SLinus Torvalds err |= get_user(s.shm_perm.mode, &up64->shm_perm.mode); 9151da177e4SLinus Torvalds } else { 9161da177e4SLinus Torvalds err = get_user(s.shm_perm.uid, &up32->shm_perm.uid); 9171da177e4SLinus Torvalds err |= get_user(s.shm_perm.gid, &up32->shm_perm.gid); 9181da177e4SLinus Torvalds err |= get_user(s.shm_perm.mode, &up32->shm_perm.mode); 9191da177e4SLinus Torvalds } 9201da177e4SLinus Torvalds if (err) 9211da177e4SLinus Torvalds break; 9221da177e4SLinus Torvalds old_fs = get_fs(); 9231da177e4SLinus Torvalds set_fs(KERNEL_DS); 9241da177e4SLinus Torvalds err = sys_shmctl(first, second & ~IPC_64, &s); 9251da177e4SLinus Torvalds set_fs(old_fs); 9261da177e4SLinus Torvalds break; 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds case IPC_STAT: 9291da177e4SLinus Torvalds case SHM_STAT: 9301da177e4SLinus Torvalds old_fs = get_fs(); 9311da177e4SLinus Torvalds set_fs(KERNEL_DS); 9321da177e4SLinus Torvalds err = sys_shmctl(first, second | IPC_64, (void *) &s64); 9331da177e4SLinus Torvalds set_fs(old_fs); 9341da177e4SLinus Torvalds if (err < 0) 9351da177e4SLinus Torvalds break; 9361da177e4SLinus Torvalds if (second & IPC_64) { 9371da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { 9381da177e4SLinus Torvalds err = -EFAULT; 9391da177e4SLinus Torvalds break; 9401da177e4SLinus Torvalds } 9411da177e4SLinus Torvalds err2 = __put_user(s64.shm_perm.key, &up64->shm_perm.key); 9421da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.uid, &up64->shm_perm.uid); 9431da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.gid, &up64->shm_perm.gid); 9441da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cuid, &up64->shm_perm.cuid); 9451da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cgid, &up64->shm_perm.cgid); 9461da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.mode, &up64->shm_perm.mode); 9471da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.seq, &up64->shm_perm.seq); 9481da177e4SLinus Torvalds err2 |= __put_user(s64.shm_atime, &up64->shm_atime); 9491da177e4SLinus Torvalds err2 |= __put_user(s64.shm_dtime, &up64->shm_dtime); 9501da177e4SLinus Torvalds err2 |= __put_user(s64.shm_ctime, &up64->shm_ctime); 9511da177e4SLinus Torvalds err2 |= __put_user(s64.shm_segsz, &up64->shm_segsz); 9521da177e4SLinus Torvalds err2 |= __put_user(s64.shm_nattch, &up64->shm_nattch); 9531da177e4SLinus Torvalds err2 |= __put_user(s64.shm_cpid, &up64->shm_cpid); 9541da177e4SLinus Torvalds err2 |= __put_user(s64.shm_lpid, &up64->shm_lpid); 9551da177e4SLinus Torvalds } else { 9561da177e4SLinus Torvalds if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { 9571da177e4SLinus Torvalds err = -EFAULT; 9581da177e4SLinus Torvalds break; 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds err2 = __put_user(s64.shm_perm.key, &up32->shm_perm.key); 9611da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.uid, &up32->shm_perm.uid); 9621da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.gid, &up32->shm_perm.gid); 9631da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cuid, &up32->shm_perm.cuid); 9641da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.cgid, &up32->shm_perm.cgid); 9651da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.mode, &up32->shm_perm.mode); 9661da177e4SLinus Torvalds err2 |= __put_user(s64.shm_perm.seq, &up32->shm_perm.seq); 9671da177e4SLinus Torvalds err2 |= __put_user(s64.shm_atime, &up32->shm_atime); 9681da177e4SLinus Torvalds err2 |= __put_user(s64.shm_dtime, &up32->shm_dtime); 9691da177e4SLinus Torvalds err2 |= __put_user(s64.shm_ctime, &up32->shm_ctime); 9701da177e4SLinus Torvalds err2 |= __put_user(s64.shm_segsz, &up32->shm_segsz); 9711da177e4SLinus Torvalds err2 |= __put_user(s64.shm_nattch, &up32->shm_nattch); 9721da177e4SLinus Torvalds err2 |= __put_user(s64.shm_cpid, &up32->shm_cpid); 9731da177e4SLinus Torvalds err2 |= __put_user(s64.shm_lpid, &up32->shm_lpid); 9741da177e4SLinus Torvalds } 9751da177e4SLinus Torvalds if (err2) 9761da177e4SLinus Torvalds err = -EFAULT; 9771da177e4SLinus Torvalds break; 9781da177e4SLinus Torvalds 9791da177e4SLinus Torvalds case SHM_INFO: 9801da177e4SLinus Torvalds old_fs = get_fs(); 9811da177e4SLinus Torvalds set_fs(KERNEL_DS); 9821da177e4SLinus Torvalds err = sys_shmctl(first, second, (void *)&si); 9831da177e4SLinus Torvalds set_fs(old_fs); 9841da177e4SLinus Torvalds if (err < 0) 9851da177e4SLinus Torvalds break; 9861da177e4SLinus Torvalds err2 = put_user(si.used_ids, &uip->used_ids); 9871da177e4SLinus Torvalds err2 |= __put_user(si.shm_tot, &uip->shm_tot); 9881da177e4SLinus Torvalds err2 |= __put_user(si.shm_rss, &uip->shm_rss); 9891da177e4SLinus Torvalds err2 |= __put_user(si.shm_swp, &uip->shm_swp); 9901da177e4SLinus Torvalds err2 |= __put_user(si.swap_attempts, &uip->swap_attempts); 9911da177e4SLinus Torvalds err2 |= __put_user (si.swap_successes, &uip->swap_successes); 9921da177e4SLinus Torvalds if (err2) 9931da177e4SLinus Torvalds err = -EFAULT; 9941da177e4SLinus Torvalds break; 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds default: 9971da177e4SLinus Torvalds err = -EINVAL; 9981da177e4SLinus Torvalds break; 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds return err; 10021da177e4SLinus Torvalds } 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems, 10051da177e4SLinus Torvalds const struct compat_timespec *timeout32) 10061da177e4SLinus Torvalds { 10071da177e4SLinus Torvalds struct compat_timespec t32; 10081da177e4SLinus Torvalds struct timespec *t64 = compat_alloc_user_space(sizeof(*t64)); 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds if (copy_from_user(&t32, timeout32, sizeof(t32))) 10111da177e4SLinus Torvalds return -EFAULT; 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds if (put_user(t32.tv_sec, &t64->tv_sec) || 10141da177e4SLinus Torvalds put_user(t32.tv_nsec, &t64->tv_nsec)) 10151da177e4SLinus Torvalds return -EFAULT; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds return sys_semtimedop(semid, tsems, nsems, t64); 10181da177e4SLinus Torvalds } 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds asmlinkage long 10211da177e4SLinus Torvalds sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth) 10221da177e4SLinus Torvalds { 10231da177e4SLinus Torvalds int version, err; 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds version = call >> 16; /* hack for backward compatibility */ 10261da177e4SLinus Torvalds call &= 0xffff; 10271da177e4SLinus Torvalds 10281da177e4SLinus Torvalds switch (call) { 10291da177e4SLinus Torvalds case SEMOP: 10301da177e4SLinus Torvalds /* struct sembuf is the same on 32 and 64bit :)) */ 10311da177e4SLinus Torvalds err = sys_semtimedop (first, (struct sembuf *)AA(ptr), second, 10321da177e4SLinus Torvalds NULL); 10331da177e4SLinus Torvalds break; 10341da177e4SLinus Torvalds case SEMTIMEDOP: 10351da177e4SLinus Torvalds err = sys32_semtimedop (first, (struct sembuf *)AA(ptr), second, 10361da177e4SLinus Torvalds (const struct compat_timespec __user *)AA(fifth)); 10371da177e4SLinus Torvalds break; 10381da177e4SLinus Torvalds case SEMGET: 10391da177e4SLinus Torvalds err = sys_semget (first, second, third); 10401da177e4SLinus Torvalds break; 10411da177e4SLinus Torvalds case SEMCTL: 10421da177e4SLinus Torvalds err = do_sys32_semctl (first, second, third, 10431da177e4SLinus Torvalds (void *)AA(ptr)); 10441da177e4SLinus Torvalds break; 10451da177e4SLinus Torvalds 10461da177e4SLinus Torvalds case MSGSND: 10471da177e4SLinus Torvalds err = do_sys32_msgsnd (first, second, third, 10481da177e4SLinus Torvalds (void *)AA(ptr)); 10491da177e4SLinus Torvalds break; 10501da177e4SLinus Torvalds case MSGRCV: 10511da177e4SLinus Torvalds err = do_sys32_msgrcv (first, second, fifth, third, 10521da177e4SLinus Torvalds version, (void *)AA(ptr)); 10531da177e4SLinus Torvalds break; 10541da177e4SLinus Torvalds case MSGGET: 10551da177e4SLinus Torvalds err = sys_msgget ((key_t) first, second); 10561da177e4SLinus Torvalds break; 10571da177e4SLinus Torvalds case MSGCTL: 10581da177e4SLinus Torvalds err = do_sys32_msgctl (first, second, (void *)AA(ptr)); 10591da177e4SLinus Torvalds break; 10601da177e4SLinus Torvalds 10611da177e4SLinus Torvalds case SHMAT: 10621da177e4SLinus Torvalds err = do_sys32_shmat (first, second, third, 10631da177e4SLinus Torvalds version, (void *)AA(ptr)); 10641da177e4SLinus Torvalds break; 10651da177e4SLinus Torvalds case SHMDT: 10661da177e4SLinus Torvalds err = sys_shmdt ((char *)A(ptr)); 10671da177e4SLinus Torvalds break; 10681da177e4SLinus Torvalds case SHMGET: 10691da177e4SLinus Torvalds err = sys_shmget (first, (unsigned)second, third); 10701da177e4SLinus Torvalds break; 10711da177e4SLinus Torvalds case SHMCTL: 10721da177e4SLinus Torvalds err = do_sys32_shmctl (first, second, (void *)AA(ptr)); 10731da177e4SLinus Torvalds break; 10741da177e4SLinus Torvalds default: 10751da177e4SLinus Torvalds err = -EINVAL; 10761da177e4SLinus Torvalds break; 10771da177e4SLinus Torvalds } 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds return err; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds asmlinkage long sys32_shmat(int shmid, char __user *shmaddr, 10831da177e4SLinus Torvalds int shmflg, int32_t *addr) 10841da177e4SLinus Torvalds { 10851da177e4SLinus Torvalds unsigned long raddr; 10861da177e4SLinus Torvalds int err; 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvalds err = do_shmat(shmid, shmaddr, shmflg, &raddr); 10891da177e4SLinus Torvalds if (err) 10901da177e4SLinus Torvalds return err; 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds return put_user(raddr, addr); 10931da177e4SLinus Torvalds } 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds struct sysctl_args32 10961da177e4SLinus Torvalds { 10971da177e4SLinus Torvalds compat_caddr_t name; 10981da177e4SLinus Torvalds int nlen; 10991da177e4SLinus Torvalds compat_caddr_t oldval; 11001da177e4SLinus Torvalds compat_caddr_t oldlenp; 11011da177e4SLinus Torvalds compat_caddr_t newval; 11021da177e4SLinus Torvalds compat_size_t newlen; 11031da177e4SLinus Torvalds unsigned int __unused[4]; 11041da177e4SLinus Torvalds }; 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds #ifdef CONFIG_SYSCTL 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvalds asmlinkage long sys32_sysctl(struct sysctl_args32 *args) 11091da177e4SLinus Torvalds { 11101da177e4SLinus Torvalds struct sysctl_args32 tmp; 11111da177e4SLinus Torvalds int error; 11121da177e4SLinus Torvalds size_t oldlen, *oldlenp = NULL; 11131da177e4SLinus Torvalds unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7; 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds if (copy_from_user(&tmp, args, sizeof(tmp))) 11161da177e4SLinus Torvalds return -EFAULT; 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds if (tmp.oldval && tmp.oldlenp) { 11191da177e4SLinus Torvalds /* Duh, this is ugly and might not work if sysctl_args 11201da177e4SLinus Torvalds is in read-only memory, but do_sysctl does indirectly 11211da177e4SLinus Torvalds a lot of uaccess in both directions and we'd have to 11221da177e4SLinus Torvalds basically copy the whole sysctl.c here, and 11231da177e4SLinus Torvalds glibc's __sysctl uses rw memory for the structure 11241da177e4SLinus Torvalds anyway. */ 11251da177e4SLinus Torvalds if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) || 11261da177e4SLinus Torvalds put_user(oldlen, (size_t *)addr)) 11271da177e4SLinus Torvalds return -EFAULT; 11281da177e4SLinus Torvalds oldlenp = (size_t *)addr; 11291da177e4SLinus Torvalds } 11301da177e4SLinus Torvalds 11311da177e4SLinus Torvalds lock_kernel(); 11321da177e4SLinus Torvalds error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval), 11331da177e4SLinus Torvalds oldlenp, (void *)A(tmp.newval), tmp.newlen); 11341da177e4SLinus Torvalds unlock_kernel(); 11351da177e4SLinus Torvalds if (oldlenp) { 11361da177e4SLinus Torvalds if (!error) { 11371da177e4SLinus Torvalds if (get_user(oldlen, (size_t *)addr) || 11381da177e4SLinus Torvalds put_user(oldlen, (u32 *)A(tmp.oldlenp))) 11391da177e4SLinus Torvalds error = -EFAULT; 11401da177e4SLinus Torvalds } 11411da177e4SLinus Torvalds copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds return error; 11441da177e4SLinus Torvalds } 11451da177e4SLinus Torvalds 11461da177e4SLinus Torvalds #endif /* CONFIG_SYSCTL */ 11471da177e4SLinus Torvalds 11481da177e4SLinus Torvalds asmlinkage long sys32_newuname(struct new_utsname * name) 11491da177e4SLinus Torvalds { 11501da177e4SLinus Torvalds int ret = 0; 11511da177e4SLinus Torvalds 11521da177e4SLinus Torvalds down_read(&uts_sem); 11531da177e4SLinus Torvalds if (copy_to_user(name,&system_utsname,sizeof *name)) 11541da177e4SLinus Torvalds ret = -EFAULT; 11551da177e4SLinus Torvalds up_read(&uts_sem); 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds if (current->personality == PER_LINUX32 && !ret) 11581da177e4SLinus Torvalds if (copy_to_user(name->machine, "mips\0\0\0", 8)) 11591da177e4SLinus Torvalds ret = -EFAULT; 11601da177e4SLinus Torvalds 11611da177e4SLinus Torvalds return ret; 11621da177e4SLinus Torvalds } 11631da177e4SLinus Torvalds 11641da177e4SLinus Torvalds asmlinkage int sys32_personality(unsigned long personality) 11651da177e4SLinus Torvalds { 11661da177e4SLinus Torvalds int ret; 11671da177e4SLinus Torvalds if (current->personality == PER_LINUX32 && personality == PER_LINUX) 11681da177e4SLinus Torvalds personality = PER_LINUX32; 11691da177e4SLinus Torvalds ret = sys_personality(personality); 11701da177e4SLinus Torvalds if (ret == PER_LINUX32) 11711da177e4SLinus Torvalds ret = PER_LINUX; 11721da177e4SLinus Torvalds return ret; 11731da177e4SLinus Torvalds } 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds /* ustat compatibility */ 11761da177e4SLinus Torvalds struct ustat32 { 11771da177e4SLinus Torvalds compat_daddr_t f_tfree; 11781da177e4SLinus Torvalds compat_ino_t f_tinode; 11791da177e4SLinus Torvalds char f_fname[6]; 11801da177e4SLinus Torvalds char f_fpack[6]; 11811da177e4SLinus Torvalds }; 11821da177e4SLinus Torvalds 11831da177e4SLinus Torvalds extern asmlinkage long sys_ustat(dev_t dev, struct ustat * ubuf); 11841da177e4SLinus Torvalds 11851da177e4SLinus Torvalds asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32) 11861da177e4SLinus Torvalds { 11871da177e4SLinus Torvalds int err; 11881da177e4SLinus Torvalds struct ustat tmp; 11891da177e4SLinus Torvalds struct ustat32 tmp32; 11901da177e4SLinus Torvalds mm_segment_t old_fs = get_fs(); 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds set_fs(KERNEL_DS); 11931da177e4SLinus Torvalds err = sys_ustat(dev, &tmp); 11941da177e4SLinus Torvalds set_fs (old_fs); 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds if (err) 11971da177e4SLinus Torvalds goto out; 11981da177e4SLinus Torvalds 11991da177e4SLinus Torvalds memset(&tmp32,0,sizeof(struct ustat32)); 12001da177e4SLinus Torvalds tmp32.f_tfree = tmp.f_tfree; 12011da177e4SLinus Torvalds tmp32.f_tinode = tmp.f_tinode; 12021da177e4SLinus Torvalds 12031da177e4SLinus Torvalds err = copy_to_user(ubuf32,&tmp32,sizeof(struct ustat32)) ? -EFAULT : 0; 12041da177e4SLinus Torvalds 12051da177e4SLinus Torvalds out: 12061da177e4SLinus Torvalds return err; 12071da177e4SLinus Torvalds } 12081da177e4SLinus Torvalds 12091da177e4SLinus Torvalds /* Handle adjtimex compatibility. */ 12101da177e4SLinus Torvalds 12111da177e4SLinus Torvalds struct timex32 { 12121da177e4SLinus Torvalds u32 modes; 12131da177e4SLinus Torvalds s32 offset, freq, maxerror, esterror; 12141da177e4SLinus Torvalds s32 status, constant, precision, tolerance; 12151da177e4SLinus Torvalds struct compat_timeval time; 12161da177e4SLinus Torvalds s32 tick; 12171da177e4SLinus Torvalds s32 ppsfreq, jitter, shift, stabil; 12181da177e4SLinus Torvalds s32 jitcnt, calcnt, errcnt, stbcnt; 12191da177e4SLinus Torvalds s32 :32; s32 :32; s32 :32; s32 :32; 12201da177e4SLinus Torvalds s32 :32; s32 :32; s32 :32; s32 :32; 12211da177e4SLinus Torvalds s32 :32; s32 :32; s32 :32; s32 :32; 12221da177e4SLinus Torvalds }; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds extern int do_adjtimex(struct timex *); 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds asmlinkage int sys32_adjtimex(struct timex32 *utp) 12271da177e4SLinus Torvalds { 12281da177e4SLinus Torvalds struct timex txc; 12291da177e4SLinus Torvalds int ret; 12301da177e4SLinus Torvalds 12311da177e4SLinus Torvalds memset(&txc, 0, sizeof(struct timex)); 12321da177e4SLinus Torvalds 12331da177e4SLinus Torvalds if (get_user(txc.modes, &utp->modes) || 12341da177e4SLinus Torvalds __get_user(txc.offset, &utp->offset) || 12351da177e4SLinus Torvalds __get_user(txc.freq, &utp->freq) || 12361da177e4SLinus Torvalds __get_user(txc.maxerror, &utp->maxerror) || 12371da177e4SLinus Torvalds __get_user(txc.esterror, &utp->esterror) || 12381da177e4SLinus Torvalds __get_user(txc.status, &utp->status) || 12391da177e4SLinus Torvalds __get_user(txc.constant, &utp->constant) || 12401da177e4SLinus Torvalds __get_user(txc.precision, &utp->precision) || 12411da177e4SLinus Torvalds __get_user(txc.tolerance, &utp->tolerance) || 12421da177e4SLinus Torvalds __get_user(txc.time.tv_sec, &utp->time.tv_sec) || 12431da177e4SLinus Torvalds __get_user(txc.time.tv_usec, &utp->time.tv_usec) || 12441da177e4SLinus Torvalds __get_user(txc.tick, &utp->tick) || 12451da177e4SLinus Torvalds __get_user(txc.ppsfreq, &utp->ppsfreq) || 12461da177e4SLinus Torvalds __get_user(txc.jitter, &utp->jitter) || 12471da177e4SLinus Torvalds __get_user(txc.shift, &utp->shift) || 12481da177e4SLinus Torvalds __get_user(txc.stabil, &utp->stabil) || 12491da177e4SLinus Torvalds __get_user(txc.jitcnt, &utp->jitcnt) || 12501da177e4SLinus Torvalds __get_user(txc.calcnt, &utp->calcnt) || 12511da177e4SLinus Torvalds __get_user(txc.errcnt, &utp->errcnt) || 12521da177e4SLinus Torvalds __get_user(txc.stbcnt, &utp->stbcnt)) 12531da177e4SLinus Torvalds return -EFAULT; 12541da177e4SLinus Torvalds 12551da177e4SLinus Torvalds ret = do_adjtimex(&txc); 12561da177e4SLinus Torvalds 12571da177e4SLinus Torvalds if (put_user(txc.modes, &utp->modes) || 12581da177e4SLinus Torvalds __put_user(txc.offset, &utp->offset) || 12591da177e4SLinus Torvalds __put_user(txc.freq, &utp->freq) || 12601da177e4SLinus Torvalds __put_user(txc.maxerror, &utp->maxerror) || 12611da177e4SLinus Torvalds __put_user(txc.esterror, &utp->esterror) || 12621da177e4SLinus Torvalds __put_user(txc.status, &utp->status) || 12631da177e4SLinus Torvalds __put_user(txc.constant, &utp->constant) || 12641da177e4SLinus Torvalds __put_user(txc.precision, &utp->precision) || 12651da177e4SLinus Torvalds __put_user(txc.tolerance, &utp->tolerance) || 12661da177e4SLinus Torvalds __put_user(txc.time.tv_sec, &utp->time.tv_sec) || 12671da177e4SLinus Torvalds __put_user(txc.time.tv_usec, &utp->time.tv_usec) || 12681da177e4SLinus Torvalds __put_user(txc.tick, &utp->tick) || 12691da177e4SLinus Torvalds __put_user(txc.ppsfreq, &utp->ppsfreq) || 12701da177e4SLinus Torvalds __put_user(txc.jitter, &utp->jitter) || 12711da177e4SLinus Torvalds __put_user(txc.shift, &utp->shift) || 12721da177e4SLinus Torvalds __put_user(txc.stabil, &utp->stabil) || 12731da177e4SLinus Torvalds __put_user(txc.jitcnt, &utp->jitcnt) || 12741da177e4SLinus Torvalds __put_user(txc.calcnt, &utp->calcnt) || 12751da177e4SLinus Torvalds __put_user(txc.errcnt, &utp->errcnt) || 12761da177e4SLinus Torvalds __put_user(txc.stbcnt, &utp->stbcnt)) 12771da177e4SLinus Torvalds ret = -EFAULT; 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds return ret; 12801da177e4SLinus Torvalds } 12811da177e4SLinus Torvalds 12821da177e4SLinus Torvalds asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, 12831da177e4SLinus Torvalds s32 count) 12841da177e4SLinus Torvalds { 12851da177e4SLinus Torvalds mm_segment_t old_fs = get_fs(); 12861da177e4SLinus Torvalds int ret; 12871da177e4SLinus Torvalds off_t of; 12881da177e4SLinus Torvalds 12891da177e4SLinus Torvalds if (offset && get_user(of, offset)) 12901da177e4SLinus Torvalds return -EFAULT; 12911da177e4SLinus Torvalds 12921da177e4SLinus Torvalds set_fs(KERNEL_DS); 12931da177e4SLinus Torvalds ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); 12941da177e4SLinus Torvalds set_fs(old_fs); 12951da177e4SLinus Torvalds 12961da177e4SLinus Torvalds if (offset && put_user(of, offset)) 12971da177e4SLinus Torvalds return -EFAULT; 12981da177e4SLinus Torvalds 12991da177e4SLinus Torvalds return ret; 13001da177e4SLinus Torvalds } 13011da177e4SLinus Torvalds 13021da177e4SLinus Torvalds asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, 13031da177e4SLinus Torvalds size_t count) 13041da177e4SLinus Torvalds { 13051da177e4SLinus Torvalds return sys_readahead(fd, merge_64(a2, a3), count); 13061da177e4SLinus Torvalds } 13071da177e4SLinus Torvalds 13081da177e4SLinus Torvalds /* Argument list sizes for sys_socketcall */ 13091da177e4SLinus Torvalds #define AL(x) ((x) * sizeof(unsigned int)) 13101da177e4SLinus Torvalds static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), 13111da177e4SLinus Torvalds AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), 13121da177e4SLinus Torvalds AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)}; 13131da177e4SLinus Torvalds #undef AL 13141da177e4SLinus Torvalds 13151da177e4SLinus Torvalds /* 13161da177e4SLinus Torvalds * System call vectors. 13171da177e4SLinus Torvalds * 13181da177e4SLinus Torvalds * Argument checking cleaned up. Saved 20% in size. 13191da177e4SLinus Torvalds * This function doesn't need to set the kernel lock because 13201da177e4SLinus Torvalds * it is set by the callees. 13211da177e4SLinus Torvalds */ 13221da177e4SLinus Torvalds 13231da177e4SLinus Torvalds asmlinkage long sys32_socketcall(int call, unsigned int *args32) 13241da177e4SLinus Torvalds { 13251da177e4SLinus Torvalds unsigned int a[6]; 13261da177e4SLinus Torvalds unsigned int a0,a1; 13271da177e4SLinus Torvalds int err; 13281da177e4SLinus Torvalds 13291da177e4SLinus Torvalds extern asmlinkage long sys_socket(int family, int type, int protocol); 13301da177e4SLinus Torvalds extern asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen); 13311da177e4SLinus Torvalds extern asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen); 13321da177e4SLinus Torvalds extern asmlinkage long sys_listen(int fd, int backlog); 13331da177e4SLinus Torvalds extern asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen); 13341da177e4SLinus Torvalds extern asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); 13351da177e4SLinus Torvalds extern asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); 13361da177e4SLinus Torvalds extern asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec); 13371da177e4SLinus Torvalds extern asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags); 13381da177e4SLinus Torvalds extern asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags, 13391da177e4SLinus Torvalds struct sockaddr __user *addr, int addr_len); 13401da177e4SLinus Torvalds extern asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags); 13411da177e4SLinus Torvalds extern asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags, 13421da177e4SLinus Torvalds struct sockaddr __user *addr, int __user *addr_len); 13431da177e4SLinus Torvalds extern asmlinkage long sys_shutdown(int fd, int how); 13441da177e4SLinus Torvalds extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen); 13451da177e4SLinus Torvalds extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int *optlen); 13461da177e4SLinus Torvalds extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags); 13471da177e4SLinus Torvalds extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags); 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds 13501da177e4SLinus Torvalds if(call<1||call>SYS_RECVMSG) 13511da177e4SLinus Torvalds return -EINVAL; 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds /* copy_from_user should be SMP safe. */ 13541da177e4SLinus Torvalds if (copy_from_user(a, args32, socketcall_nargs[call])) 13551da177e4SLinus Torvalds return -EFAULT; 13561da177e4SLinus Torvalds 13571da177e4SLinus Torvalds a0=a[0]; 13581da177e4SLinus Torvalds a1=a[1]; 13591da177e4SLinus Torvalds 13601da177e4SLinus Torvalds switch(call) 13611da177e4SLinus Torvalds { 13621da177e4SLinus Torvalds case SYS_SOCKET: 13631da177e4SLinus Torvalds err = sys_socket(a0,a1,a[2]); 13641da177e4SLinus Torvalds break; 13651da177e4SLinus Torvalds case SYS_BIND: 13661da177e4SLinus Torvalds err = sys_bind(a0,(struct sockaddr __user *)A(a1), a[2]); 13671da177e4SLinus Torvalds break; 13681da177e4SLinus Torvalds case SYS_CONNECT: 13691da177e4SLinus Torvalds err = sys_connect(a0, (struct sockaddr __user *)A(a1), a[2]); 13701da177e4SLinus Torvalds break; 13711da177e4SLinus Torvalds case SYS_LISTEN: 13721da177e4SLinus Torvalds err = sys_listen(a0,a1); 13731da177e4SLinus Torvalds break; 13741da177e4SLinus Torvalds case SYS_ACCEPT: 13751da177e4SLinus Torvalds err = sys_accept(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 13761da177e4SLinus Torvalds break; 13771da177e4SLinus Torvalds case SYS_GETSOCKNAME: 13781da177e4SLinus Torvalds err = sys_getsockname(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 13791da177e4SLinus Torvalds break; 13801da177e4SLinus Torvalds case SYS_GETPEERNAME: 13811da177e4SLinus Torvalds err = sys_getpeername(a0, (struct sockaddr __user *)A(a1), (int __user *)A(a[2])); 13821da177e4SLinus Torvalds break; 13831da177e4SLinus Torvalds case SYS_SOCKETPAIR: 13841da177e4SLinus Torvalds err = sys_socketpair(a0,a1, a[2], (int __user *)A(a[3])); 13851da177e4SLinus Torvalds break; 13861da177e4SLinus Torvalds case SYS_SEND: 13871da177e4SLinus Torvalds err = sys_send(a0, (void __user *)A(a1), a[2], a[3]); 13881da177e4SLinus Torvalds break; 13891da177e4SLinus Torvalds case SYS_SENDTO: 13901da177e4SLinus Torvalds err = sys_sendto(a0,(void __user *)A(a1), a[2], a[3], 13911da177e4SLinus Torvalds (struct sockaddr __user *)A(a[4]), a[5]); 13921da177e4SLinus Torvalds break; 13931da177e4SLinus Torvalds case SYS_RECV: 13941da177e4SLinus Torvalds err = sys_recv(a0, (void __user *)A(a1), a[2], a[3]); 13951da177e4SLinus Torvalds break; 13961da177e4SLinus Torvalds case SYS_RECVFROM: 13971da177e4SLinus Torvalds err = sys_recvfrom(a0, (void __user *)A(a1), a[2], a[3], 13981da177e4SLinus Torvalds (struct sockaddr __user *)A(a[4]), (int __user *)A(a[5])); 13991da177e4SLinus Torvalds break; 14001da177e4SLinus Torvalds case SYS_SHUTDOWN: 14011da177e4SLinus Torvalds err = sys_shutdown(a0,a1); 14021da177e4SLinus Torvalds break; 14031da177e4SLinus Torvalds case SYS_SETSOCKOPT: 14041da177e4SLinus Torvalds err = sys_setsockopt(a0, a1, a[2], (char __user *)A(a[3]), a[4]); 14051da177e4SLinus Torvalds break; 14061da177e4SLinus Torvalds case SYS_GETSOCKOPT: 14071da177e4SLinus Torvalds err = sys_getsockopt(a0, a1, a[2], (char __user *)A(a[3]), (int __user *)A(a[4])); 14081da177e4SLinus Torvalds break; 14091da177e4SLinus Torvalds case SYS_SENDMSG: 14101da177e4SLinus Torvalds err = sys_sendmsg(a0, (struct msghdr __user *) A(a1), a[2]); 14111da177e4SLinus Torvalds break; 14121da177e4SLinus Torvalds case SYS_RECVMSG: 14131da177e4SLinus Torvalds err = sys_recvmsg(a0, (struct msghdr __user *) A(a1), a[2]); 14141da177e4SLinus Torvalds break; 14151da177e4SLinus Torvalds default: 14161da177e4SLinus Torvalds err = -EINVAL; 14171da177e4SLinus Torvalds break; 14181da177e4SLinus Torvalds } 14191da177e4SLinus Torvalds return err; 14201da177e4SLinus Torvalds } 1421