0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include <linux/kernel.h>
0025 #include <linux/sched.h>
0026 #include <linux/fs.h>
0027 #include <linux/file.h>
0028 #include <linux/signal.h>
0029 #include <linux/syscalls.h>
0030 #include <linux/times.h>
0031 #include <linux/utsname.h>
0032 #include <linux/mm.h>
0033 #include <linux/uio.h>
0034 #include <linux/poll.h>
0035 #include <linux/personality.h>
0036 #include <linux/stat.h>
0037 #include <linux/rwsem.h>
0038 #include <linux/compat.h>
0039 #include <linux/vfs.h>
0040 #include <linux/ptrace.h>
0041 #include <linux/highuid.h>
0042 #include <linux/sysctl.h>
0043 #include <linux/slab.h>
0044 #include <linux/sched/task.h>
0045 #include <asm/mman.h>
0046 #include <asm/types.h>
0047 #include <linux/uaccess.h>
0048 #include <linux/atomic.h>
0049 #include <asm/vgtod.h>
0050 #include <asm/ia32.h>
0051
0052 #define AA(__x) ((unsigned long)(__x))
0053
0054 SYSCALL_DEFINE3(ia32_truncate64, const char __user *, filename,
0055 unsigned long, offset_low, unsigned long, offset_high)
0056 {
0057 return ksys_truncate(filename,
0058 ((loff_t) offset_high << 32) | offset_low);
0059 }
0060
0061 SYSCALL_DEFINE3(ia32_ftruncate64, unsigned int, fd,
0062 unsigned long, offset_low, unsigned long, offset_high)
0063 {
0064 return ksys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
0065 }
0066
0067
0068 SYSCALL_DEFINE5(ia32_pread64, unsigned int, fd, char __user *, ubuf,
0069 u32, count, u32, poslo, u32, poshi)
0070 {
0071 return ksys_pread64(fd, ubuf, count,
0072 ((loff_t)AA(poshi) << 32) | AA(poslo));
0073 }
0074
0075 SYSCALL_DEFINE5(ia32_pwrite64, unsigned int, fd, const char __user *, ubuf,
0076 u32, count, u32, poslo, u32, poshi)
0077 {
0078 return ksys_pwrite64(fd, ubuf, count,
0079 ((loff_t)AA(poshi) << 32) | AA(poslo));
0080 }
0081
0082
0083
0084
0085
0086
0087 SYSCALL_DEFINE6(ia32_fadvise64_64, int, fd, __u32, offset_low,
0088 __u32, offset_high, __u32, len_low, __u32, len_high,
0089 int, advice)
0090 {
0091 return ksys_fadvise64_64(fd,
0092 (((u64)offset_high)<<32) | offset_low,
0093 (((u64)len_high)<<32) | len_low,
0094 advice);
0095 }
0096
0097 SYSCALL_DEFINE4(ia32_readahead, int, fd, unsigned int, off_lo,
0098 unsigned int, off_hi, size_t, count)
0099 {
0100 return ksys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
0101 }
0102
0103 SYSCALL_DEFINE6(ia32_sync_file_range, int, fd, unsigned int, off_low,
0104 unsigned int, off_hi, unsigned int, n_low,
0105 unsigned int, n_hi, int, flags)
0106 {
0107 return ksys_sync_file_range(fd,
0108 ((u64)off_hi << 32) | off_low,
0109 ((u64)n_hi << 32) | n_low, flags);
0110 }
0111
0112 SYSCALL_DEFINE5(ia32_fadvise64, int, fd, unsigned int, offset_lo,
0113 unsigned int, offset_hi, size_t, len, int, advice)
0114 {
0115 return ksys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
0116 len, advice);
0117 }
0118
0119 SYSCALL_DEFINE6(ia32_fallocate, int, fd, int, mode,
0120 unsigned int, offset_lo, unsigned int, offset_hi,
0121 unsigned int, len_lo, unsigned int, len_hi)
0122 {
0123 return ksys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
0124 ((u64)len_hi << 32) | len_lo);
0125 }
0126
0127 #ifdef CONFIG_IA32_EMULATION
0128
0129
0130
0131
0132 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
0133 {
0134 typeof(ubuf->st_uid) uid = 0;
0135 typeof(ubuf->st_gid) gid = 0;
0136 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
0137 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
0138 if (!user_write_access_begin(ubuf, sizeof(struct stat64)))
0139 return -EFAULT;
0140 unsafe_put_user(huge_encode_dev(stat->dev), &ubuf->st_dev, Efault);
0141 unsafe_put_user(stat->ino, &ubuf->__st_ino, Efault);
0142 unsafe_put_user(stat->ino, &ubuf->st_ino, Efault);
0143 unsafe_put_user(stat->mode, &ubuf->st_mode, Efault);
0144 unsafe_put_user(stat->nlink, &ubuf->st_nlink, Efault);
0145 unsafe_put_user(uid, &ubuf->st_uid, Efault);
0146 unsafe_put_user(gid, &ubuf->st_gid, Efault);
0147 unsafe_put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev, Efault);
0148 unsafe_put_user(stat->size, &ubuf->st_size, Efault);
0149 unsafe_put_user(stat->atime.tv_sec, &ubuf->st_atime, Efault);
0150 unsafe_put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec, Efault);
0151 unsafe_put_user(stat->mtime.tv_sec, &ubuf->st_mtime, Efault);
0152 unsafe_put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec, Efault);
0153 unsafe_put_user(stat->ctime.tv_sec, &ubuf->st_ctime, Efault);
0154 unsafe_put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec, Efault);
0155 unsafe_put_user(stat->blksize, &ubuf->st_blksize, Efault);
0156 unsafe_put_user(stat->blocks, &ubuf->st_blocks, Efault);
0157 user_access_end();
0158 return 0;
0159 Efault:
0160 user_write_access_end();
0161 return -EFAULT;
0162 }
0163
0164 COMPAT_SYSCALL_DEFINE2(ia32_stat64, const char __user *, filename,
0165 struct stat64 __user *, statbuf)
0166 {
0167 struct kstat stat;
0168 int ret = vfs_stat(filename, &stat);
0169
0170 if (!ret)
0171 ret = cp_stat64(statbuf, &stat);
0172 return ret;
0173 }
0174
0175 COMPAT_SYSCALL_DEFINE2(ia32_lstat64, const char __user *, filename,
0176 struct stat64 __user *, statbuf)
0177 {
0178 struct kstat stat;
0179 int ret = vfs_lstat(filename, &stat);
0180 if (!ret)
0181 ret = cp_stat64(statbuf, &stat);
0182 return ret;
0183 }
0184
0185 COMPAT_SYSCALL_DEFINE2(ia32_fstat64, unsigned int, fd,
0186 struct stat64 __user *, statbuf)
0187 {
0188 struct kstat stat;
0189 int ret = vfs_fstat(fd, &stat);
0190 if (!ret)
0191 ret = cp_stat64(statbuf, &stat);
0192 return ret;
0193 }
0194
0195 COMPAT_SYSCALL_DEFINE4(ia32_fstatat64, unsigned int, dfd,
0196 const char __user *, filename,
0197 struct stat64 __user *, statbuf, int, flag)
0198 {
0199 struct kstat stat;
0200 int error;
0201
0202 error = vfs_fstatat(dfd, filename, &stat, flag);
0203 if (error)
0204 return error;
0205 return cp_stat64(statbuf, &stat);
0206 }
0207
0208
0209
0210
0211
0212
0213
0214 struct mmap_arg_struct32 {
0215 unsigned int addr;
0216 unsigned int len;
0217 unsigned int prot;
0218 unsigned int flags;
0219 unsigned int fd;
0220 unsigned int offset;
0221 };
0222
0223 COMPAT_SYSCALL_DEFINE1(ia32_mmap, struct mmap_arg_struct32 __user *, arg)
0224 {
0225 struct mmap_arg_struct32 a;
0226
0227 if (copy_from_user(&a, arg, sizeof(a)))
0228 return -EFAULT;
0229
0230 if (a.offset & ~PAGE_MASK)
0231 return -EINVAL;
0232
0233 return ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
0234 a.offset>>PAGE_SHIFT);
0235 }
0236
0237
0238
0239
0240 COMPAT_SYSCALL_DEFINE5(ia32_clone, unsigned long, clone_flags,
0241 unsigned long, newsp, int __user *, parent_tidptr,
0242 unsigned long, tls_val, int __user *, child_tidptr)
0243 {
0244 struct kernel_clone_args args = {
0245 .flags = (clone_flags & ~CSIGNAL),
0246 .pidfd = parent_tidptr,
0247 .child_tid = child_tidptr,
0248 .parent_tid = parent_tidptr,
0249 .exit_signal = (clone_flags & CSIGNAL),
0250 .stack = newsp,
0251 .tls = tls_val,
0252 };
0253
0254 return kernel_clone(&args);
0255 }
0256 #endif