18 #include <linux/stddef.h>
19 #include <linux/kernel.h>
20 #include <linux/linkage.h>
22 #include <linux/errno.h>
23 #include <linux/time.h>
25 #include <linux/fcntl.h>
35 #include <linux/ctype.h>
39 #include <linux/personality.h>
44 #include <linux/signal.h>
45 #include <linux/poll.h>
47 #include <linux/eventpoll.h>
49 #include <linux/slab.h>
52 #include <asm/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/ioctls.h>
66 ret = vprintk(fmt, ap);
78 struct compat_utimbuf __user *
t)
114 get_user(tv[1].tv_sec, &t[1].tv_sec) ||
115 get_user(tv[1].tv_nsec, &t[1].tv_usec))
117 if (tv[0].tv_nsec >= 1000000 || tv[0].tv_nsec < 0 ||
118 tv[1].tv_nsec >= 1000000 || tv[1].tv_nsec < 0)
135 if (!old_valid_dev(stat->
dev) || !old_valid_dev(stat->
rdev))
139 tmp.st_dev = old_encode_dev(stat->
dev);
141 if (
sizeof(
tmp.st_ino) <
sizeof(stat->
ino) &&
tmp.st_ino != stat->
ino)
149 tmp.st_rdev = old_encode_dev(stat->
rdev);
154 tmp.st_atime_nsec = stat->
atime.tv_nsec;
156 tmp.st_mtime_nsec = stat->
mtime.tv_nsec;
158 tmp.st_ctime_nsec = stat->
ctime.tv_nsec;
173 return cp_compat_stat(&stat, statbuf);
185 return cp_compat_stat(&stat, statbuf);
188 #ifndef __ARCH_WANT_STAT64
199 return cp_compat_stat(&stat, statbuf);
210 error = cp_compat_stat(&stat, statbuf);
217 if (
sizeof ubuf->f_blocks == 4) {
223 if (kbuf->
f_files != 0xffffffffffffffffULL
224 && (kbuf->
f_files & 0xffffffff00000000ULL))
226 if (kbuf->
f_ffree != 0xffffffffffffffffULL
227 && (kbuf->
f_ffree & 0xffffffff00000000ULL))
257 error = put_compat_statfs(buf, &tmp);
266 error = put_compat_statfs(buf, &tmp);
272 if (
sizeof ubuf->f_blocks == 4) {
278 if (kbuf->
f_files != 0xffffffffffffffffULL
279 && (kbuf->
f_files & 0xffffffff00000000ULL))
281 if (kbuf->
f_ffree != 0xffffffffffffffffULL
282 && (kbuf->
f_ffree & 0xffffffff00000000ULL))
308 if (sz !=
sizeof(*buf))
313 error = put_compat_statfs64(buf, &tmp);
322 if (sz !=
sizeof(*buf))
327 error = put_compat_statfs64(buf, &tmp);
338 struct compat_ustat tmp;
344 memset(&tmp, 0,
sizeof(
struct compat_ustat));
376 #ifndef HAVE_ARCH_GET_COMPAT_FLOCK64
390 #ifndef HAVE_ARCH_PUT_COMPAT_FLOCK64
415 ret = get_compat_flock(&f, compat_ptr(arg));
420 ret =
sys_fcntl(fd, cmd, (
unsigned long)&f);
422 if (cmd ==
F_GETLK && ret == 0) {
439 ret = put_compat_flock(&f, compat_ptr(arg));
446 ret = get_compat_flock64(&f, compat_ptr(arg));
462 ret = put_compat_flock64(&f, compat_ptr(arg));
503 unsigned long min_nr,
530 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
533 const struct compat_iovec __user *uvector,
unsigned long nr_segs,
534 unsigned long fast_segs,
struct iovec *fast_pointer,
535 struct iovec **ret_pointer)
538 struct iovec *iov = *ret_pointer = fast_pointer;
553 if (nr_segs > fast_segs) {
571 for (seg = 0; seg < nr_segs; seg++) {
602 copy_iocb(
long nr,
u32 __user *ptr32,
struct iocb __user * __user *ptr64)
607 for (i = 0; i <
nr; ++
i) {
610 if (
put_user(compat_ptr(uptr), ptr64 + i))
616 #define MAX_AIO_SUBMITS (PAGE_SIZE/sizeof(struct iocb *))
621 struct iocb __user * __user *iocb64;
631 ret = copy_iocb(nr, iocb, iocb64);
666 static void *do_ncp_super_data_conv(
void *raw_data)
668 int version = *(
unsigned int *)raw_data;
681 }
else if (version == 4) {
695 }
else if (version != 5) {
736 static int do_nfs4_super_data_conv(
void *raw_data)
768 #define NCPFS_NAME "ncpfs"
769 #define NFS4_NAME "nfs4"
772 const char __user * dir_name,
773 const char __user *
type,
unsigned long flags,
774 const void __user *
data)
777 unsigned long data_page;
787 retval = PTR_ERR(dir);
801 if (kernel_type && data_page) {
803 do_ncp_super_data_conv((
void *)data_page);
805 if (do_nfs4_super_data_conv((
void *) data_page))
811 flags, (
void*)data_page);
837 static int compat_fillonedir(
void *__buf,
const char *
name,
int namlen,
847 if (
sizeof(d_ino) <
sizeof(ino) && d_ino != ino) {
854 (
unsigned long)(dirent->
d_name + namlen + 1) -
855 (
unsigned long)dirent))
873 struct fd f = fdget(fd);
904 static int compat_filldir(
void *__buf,
const char *name,
int namlen,
905 loff_t offset,
u64 ino,
unsigned int d_type)
914 if (reclen > buf->
count)
917 if (
sizeof(d_ino) <
sizeof(ino) && d_ino != ino) {
935 if (
__put_user(d_type, (
char __user *) dirent + reclen - 1))
938 dirent = (
void __user *)dirent + reclen;
940 buf->
count -= reclen;
975 error = count - buf.
count;
981 #ifndef __ARCH_OMIT_COMPAT_SYS_GETDENTS64
990 static int compat_filldir64(
void * __buf,
const char * name,
int namlen, loff_t offset,
991 u64 ino,
unsigned int d_type)
1000 if (reclen > buf->
count)
1023 dirent = (
void __user *)dirent + reclen;
1025 buf->
count -= reclen;
1061 error = count - buf.
count;
1069 const struct compat_iovec __user *uvector,
1070 unsigned long nr_segs, loff_t *
pos)
1074 struct iovec *iov = iovstack;
1100 fn = file->
f_op->read;
1101 fnv = file->
f_op->aio_read;
1104 fnv = file->
f_op->aio_write;
1114 if (iov != iovstack)
1116 if ((ret + (type ==
READ)) > 0) {
1118 fsnotify_access(file);
1120 fsnotify_modify(file);
1125 static size_t compat_readv(
struct file *file,
1126 const struct compat_iovec __user *vec,
1127 unsigned long vlen, loff_t *pos)
1135 if (!file->
f_op || (!file->
f_op->aio_read && !file->
f_op->read))
1138 ret = compat_do_readv_writev(
READ, file, vec, vlen, pos);
1151 struct fd f = fdget(fd);
1157 pos = f.
file->f_pos;
1158 ret = compat_readv(f.
file, vec, vlen, &pos);
1166 unsigned long vlen, loff_t pos)
1178 ret = compat_readv(f.
file, vec, vlen, &pos);
1185 unsigned long vlen,
u32 pos_low,
u32 pos_high)
1187 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1191 static size_t compat_writev(
struct file *file,
1192 const struct compat_iovec __user *vec,
1193 unsigned long vlen, loff_t *pos)
1201 if (!file->
f_op || (!file->
f_op->aio_write && !file->
f_op->write))
1204 ret = compat_do_readv_writev(
WRITE, file, vec, vlen, pos);
1217 struct fd f = fdget(fd);
1223 pos = f.
file->f_pos;
1224 ret = compat_writev(f.
file, vec, vlen, &pos);
1232 unsigned long vlen, loff_t pos)
1244 ret = compat_writev(f.
file, vec, vlen, &pos);
1251 unsigned long vlen,
u32 pos_low,
u32 pos_high)
1253 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1259 unsigned int nr_segs,
unsigned int flags)
1262 struct iovec __user *iov;
1266 for (i = 0; i < nr_segs; i++) {
1267 struct compat_iovec v;
1268 if (
get_user(v.iov_base, &iov32[i].iov_base) ||
1269 get_user(v.iov_len, &iov32[i].iov_len) ||
1297 #define __COMPAT_NFDBITS (8 * sizeof(compat_ulong_t))
1299 static int poll_select_copy_remaining(
struct timespec *end_time,
void __user *
p,
1315 ts = timespec_sub(*end_time, ts);
1355 int compat_get_fd_set(
unsigned long nr,
compat_ulong_t __user *ufdset,
1356 unsigned long *fdset)
1372 *fdset++ = h << 32 |
l;
1388 int compat_set_fd_set(
unsigned long nr,
compat_ulong_t __user *ufdset,
1389 unsigned long *fdset)
1455 if (size >
sizeof(stack_fds) / 6) {
1461 fds.
in = (
unsigned long *) bits;
1462 fds.
out = (
unsigned long *) (bits + size);
1463 fds.
ex = (
unsigned long *) (bits + 2*size);
1464 fds.
res_in = (
unsigned long *) (bits + 3*size);
1465 fds.
res_out = (
unsigned long *) (bits + 4*size);
1466 fds.
res_ex = (
unsigned long *) (bits + 5*size);
1468 if ((ret = compat_get_fd_set(n, inp, fds.
in)) ||
1469 (ret = compat_get_fd_set(n, outp, fds.
out)) ||
1470 (ret = compat_get_fd_set(n, exp, fds.
ex)))
1472 zero_fd_set(n, fds.
res_in);
1474 zero_fd_set(n, fds.
res_ex);
1487 if (compat_set_fd_set(n, inp, fds.
res_in) ||
1488 compat_set_fd_set(n, outp, fds.
res_out) ||
1489 compat_set_fd_set(n, exp, fds.
res_ex))
1492 if (bits != stack_fds)
1518 ret = poll_select_copy_remaining(&end_time, tvp, 1, ret);
1538 compat_ptr(a.
exp), compat_ptr(a.
tvp));
1546 compat_sigset_t ss32;
1562 if (sigsetsize !=
sizeof(compat_sigset_t))
1573 ret = poll_select_copy_remaining(&end_time, tsp, 0, ret);
1584 set_restore_sigmask();
1607 return do_compat_pselect(n, inp, outp, exp, tsp, compat_ptr(up),
1613 const compat_sigset_t __user *sigmask,
compat_size_t sigsetsize)
1615 compat_sigset_t ss32;
1631 if (sigsetsize !=
sizeof(compat_sigset_t))
1644 if (ret == -
EINTR) {
1653 set_restore_sigmask();
1659 ret = poll_select_copy_remaining(&end_time, tsp, 0, ret);
1666 asmlinkage long compat_sys_epoll_pwait(
int epfd,
1667 struct compat_epoll_event __user *
events,
1668 int maxevents,
int timeout,
1669 const compat_sigset_t __user *sigmask,
1673 compat_sigset_t csigmask;
1681 if (sigsetsize !=
sizeof(compat_sigset_t))
1699 if (err == -
EINTR) {
1702 set_restore_sigmask();
1712 #ifdef CONFIG_SIGNALFD
1714 asmlinkage long compat_sys_signalfd4(
int ufd,
1715 const compat_sigset_t __user *sigmask,
1718 compat_sigset_t ss32;
1722 if (sigsetsize !=
sizeof(compat_sigset_t))
1735 const compat_sigset_t __user *sigmask,
1738 return compat_sys_signalfd4(ufd, sigmask, sigsetsize, 0);
1742 #ifdef CONFIG_TIMERFD
1744 asmlinkage long compat_sys_timerfd_settime(
int ufd,
int flags,
1745 const struct compat_itimerspec __user *utmr,
1746 struct compat_itimerspec __user *otmr)
1765 asmlinkage long compat_sys_timerfd_gettime(
int ufd,
1766 struct compat_itimerspec __user *otmr)
1783 #ifdef CONFIG_FHANDLE
1789 compat_sys_open_by_handle_at(
int mountdirfd,
1796 #ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
1797 asmlinkage long compat_sys_sendfile(
int out_fd,
int in_fd,