convert sendfile{,64} to COMPAT_SYSCALL_DEFINE
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 24 Feb 2013 07:17:03 +0000 (02:17 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 4 Mar 2013 03:58:46 +0000 (22:58 -0500)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
20 files changed:
arch/mips/kernel/linux32.c
arch/mips/kernel/scall64-n32.S
arch/mips/kernel/scall64-o32.S
arch/parisc/kernel/sys_parisc32.c
arch/parisc/kernel/syscall_table.S
arch/powerpc/include/asm/systbl.h
arch/powerpc/kernel/sys_ppc32.c
arch/s390/kernel/compat_linux.c
arch/s390/kernel/compat_linux.h
arch/s390/kernel/compat_wrapper.S
arch/s390/kernel/syscalls.S
arch/sparc/kernel/sys32.S
arch/sparc/kernel/systbls_64.S
arch/x86/ia32/sys_ia32.c
arch/x86/include/asm/sys_ia32.h
arch/x86/syscalls/syscall_32.tbl
fs/compat.c
fs/read_write.c
fs/read_write.h
include/linux/compat.h

index 8eeee1c860c08cd5ea0228e8387668cc2aaa0cc5..b0cc2a7df59f3a1194464f796b00438d587272e4 100644 (file)
@@ -226,26 +226,6 @@ SYSCALL_DEFINE1(32_personality, unsigned long, personality)
        return ret;
 }
 
-SYSCALL_DEFINE4(32_sendfile, long, out_fd, long, in_fd,
-       compat_off_t __user *, offset, s32, count)
-{
-       mm_segment_t old_fs = get_fs();
-       int ret;
-       off_t of;
-
-       if (offset && get_user(of, offset))
-               return -EFAULT;
-
-       set_fs(KERNEL_DS);
-       ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
-       set_fs(old_fs);
-
-       if (offset && put_user(of, offset))
-               return -EFAULT;
-
-       return ret;
-}
-
 asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
                                   size_t count)
 {
index 693d60b0855fad227de008303d67fc332983fc00..9b4df498fc5b55b2c2e94a1457d8b4b8875512ec 100644 (file)
@@ -143,7 +143,7 @@ EXPORT(sysn32_call_table)
        PTR     compat_sys_setitimer
        PTR     sys_alarm
        PTR     sys_getpid
-       PTR     sys_32_sendfile
+       PTR     compat_sys_sendfile
        PTR     sys_socket                      /* 6040 */
        PTR     sys_connect
        PTR     sys_accept
index af8887f779f1d96577200ca3ad15dd06d4381b57..c1a70e80575156473a34b681b7a88aa059a36944 100644 (file)
@@ -399,7 +399,7 @@ sys_call_table:
        PTR     sys_capget
        PTR     sys_capset                      /* 4205 */
        PTR     compat_sys_sigaltstack
-       PTR     sys_32_sendfile
+       PTR     compat_sys_sendfile
        PTR     sys_ni_syscall
        PTR     sys_ni_syscall
        PTR     sys_mips_mmap2                  /* 4210 */
index 051c8b90231f14a7bcd7305cb3592c729f326ed5..035ab3f94814045325c93f4c6629c57019da4606 100644 (file)
@@ -60,25 +60,6 @@ asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
     return -ENOSYS;
 }
 
-/* Note: it is necessary to treat out_fd and in_fd as unsigned ints, with the
- * corresponding cast to a signed int to insure that the proper conversion
- * (sign extension) between the register representation of a signed int (msr in
- * 32-bit mode) and the register representation of a signed int (msr in 64-bit
- * mode) is performed.
- */
-asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd,
-                              compat_off_t __user *offset, compat_size_t count)
-{
-       return compat_sys_sendfile((int)out_fd, (int)in_fd, offset, count);
-}
-
-asmlinkage long sys32_sendfile64(u32 out_fd, u32 in_fd,
-                                compat_loff_t __user *offset, compat_size_t count)
-{
-       return sys_sendfile64((int)out_fd, (int)in_fd,
-                               (loff_t __user *)offset, count);
-}
-
 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
 {
         union semun u;
index f57dc137b8dd883843c86c7f2f0e837360386fcf..f232672a9e20fbc9048b0d3c246ac8190a14ae4e 100644 (file)
        ENTRY_SAME(madvise)
        ENTRY_SAME(clone_wrapper)       /* 120 */
        ENTRY_SAME(setdomainname)
-       ENTRY_DIFF(sendfile)
+       ENTRY_COMP(sendfile)
        /* struct sockaddr... */
        ENTRY_SAME(recvfrom)
        /* struct timex contains longs */
        ENTRY_SAME(gettid)
        ENTRY_OURS(readahead)
        ENTRY_SAME(tkill)
-       ENTRY_DIFF(sendfile64)
+       ENTRY_COMP(sendfile64)
        ENTRY_COMP(futex)               /* 210 */
        ENTRY_COMP(sched_setaffinity)
        ENTRY_COMP(sched_getaffinity)
index 535b6d8a41ccae912590c0ec14d2fb355f0f4800..634db7d2dc923a6901e9470a1394a987dc908be6 100644 (file)
@@ -190,7 +190,7 @@ SYSCALL_SPU(getcwd)
 SYSCALL_SPU(capget)
 SYSCALL_SPU(capset)
 COMPAT_SYS(sigaltstack)
-SYSX_SPU(sys_sendfile,compat_sys_sendfile_wrapper,sys_sendfile)
+COMPAT_SYS_SPU(sendfile)
 SYSCALL(ni_syscall)
 SYSCALL(ni_syscall)
 PPC_SYS(vfork)
@@ -230,7 +230,7 @@ COMPAT_SYS_SPU(sched_setaffinity)
 COMPAT_SYS_SPU(sched_getaffinity)
 SYSCALL(ni_syscall)
 SYSCALL(ni_syscall)
-SYSX(sys_ni_syscall,compat_sys_sendfile64_wrapper,sys_sendfile64)
+SYS32ONLY(sendfile64)
 COMPAT_SYS_SPU(io_setup)
 SYSCALL_SPU(io_destroy)
 COMPAT_SYS_SPU(io_getevents)
index d0bafc0cdf069d91c58eb112113497a5ab256f76..6e7c2509bd2d579f0e1d9d4661e6d89241591592 100644 (file)
@@ -128,24 +128,6 @@ long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t pt
 }
 #endif
 
-/* Note: it is necessary to treat out_fd and in_fd as unsigned ints, 
- * with the corresponding cast to a signed int to insure that the 
- * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
- * and the register representation of a signed int (msr in 64-bit mode) is performed.
- */
-asmlinkage long compat_sys_sendfile_wrapper(u32 out_fd, u32 in_fd,
-                                           compat_off_t __user *offset, u32 count)
-{
-       return compat_sys_sendfile((int)out_fd, (int)in_fd, offset, count);
-}
-
-asmlinkage long compat_sys_sendfile64_wrapper(u32 out_fd, u32 in_fd,
-                                             compat_loff_t __user *offset, u32 count)
-{
-       return sys_sendfile((int)out_fd, (int)in_fd,
-                           (off_t __user *)offset, count);
-}
-
 unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
                          unsigned long prot, unsigned long flags,
                          unsigned long fd, unsigned long pgoff)
index 19f26de27fae8e6fe808e798c565048e510c0d88..fbd29c70a297bb863c396835693e98dd77846c18 100644 (file)
@@ -373,48 +373,6 @@ asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 coun
        return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
 }
 
-asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, size_t count)
-{
-       mm_segment_t old_fs = get_fs();
-       int ret;
-       off_t of;
-       
-       if (offset && get_user(of, offset))
-               return -EFAULT;
-               
-       set_fs(KERNEL_DS);
-       ret = sys_sendfile(out_fd, in_fd,
-                          offset ? (off_t __force __user *) &of : NULL, count);
-       set_fs(old_fs);
-       
-       if (offset && put_user(of, offset))
-               return -EFAULT;
-               
-       return ret;
-}
-
-asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
-                               compat_loff_t __user *offset, s32 count)
-{
-       mm_segment_t old_fs = get_fs();
-       int ret;
-       loff_t lof;
-       
-       if (offset && get_user(lof, offset))
-               return -EFAULT;
-               
-       set_fs(KERNEL_DS);
-       ret = sys_sendfile64(out_fd, in_fd,
-                            offset ? (loff_t __force __user *) &lof : NULL,
-                            count);
-       set_fs(old_fs);
-       
-       if (offset && put_user(lof, offset))
-               return -EFAULT;
-               
-       return ret;
-}
-
 struct stat64_emu31 {
        unsigned long long  st_dev;
        unsigned int    __pad1;
index 00d92a5a6f6c05377968ebc5cd0aace6d3305c45..bce0b7aec8f9b6c5f8b70f068fd0a8f44e61a070 100644 (file)
@@ -106,10 +106,6 @@ long sys32_pread64(unsigned int fd, char __user *ubuf, size_t count,
 long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
                    size_t count, u32 poshi, u32 poslo);
 compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count);
-long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset,
-                   size_t count);
-long sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset,
-                     s32 count);
 long sys32_stat64(const char __user * filename, struct stat64_emu31 __user * statbuf);
 long sys32_lstat64(const char __user * filename,
                   struct stat64_emu31 __user * statbuf);
index 626cc6f0f446ae3193974a061f76b0b111774533..a1dda9c67efeef4c146706bc71afed10150fa02a 100644 (file)
@@ -666,13 +666,6 @@ ENTRY(sys32_capset_wrapper)
        llgtr   %r3,%r3                 # const cap_user_data_t
        jg      sys_capset              # branch to system call
 
-ENTRY(sys32_sendfile_wrapper)
-       lgfr    %r2,%r2                 # int
-       lgfr    %r3,%r3                 # int
-       llgtr   %r4,%r4                 # __kernel_off_emu31_t *
-       llgfr   %r5,%r5                 # size_t
-       jg      sys32_sendfile          # branch to system call
-
 #sys32_vfork_wrapper                   # done in vfork_glue
 
 ENTRY(sys32_truncate64_wrapper)
@@ -1348,13 +1341,6 @@ ENTRY(sys32_readahead_wrapper)
        lgfr    %r5,%r5                 # s32
        jg      sys32_readahead         # branch to system call
 
-ENTRY(sys32_sendfile64_wrapper)
-       lgfr    %r2,%r2                 # int
-       lgfr    %r3,%r3                 # int
-       llgtr   %r4,%r4                 # compat_loff_t *
-       lgfr    %r5,%r5                 # s32
-       jg      sys32_sendfile64        # branch to system call
-
 ENTRY(sys_tkill_wrapper)
        lgfr    %r2,%r2                 # pid_t
        lgfr    %r3,%r3                 # int
index 2695bb89699ed707049abc9345dbc0b641e2a554..5f3f7fbc54655deef2194f1109a651490e565742 100644 (file)
@@ -195,7 +195,7 @@ SYSCALL(sys_getcwd,sys_getcwd,sys32_getcwd_wrapper)
 SYSCALL(sys_capget,sys_capget,sys32_capget_wrapper)
 SYSCALL(sys_capset,sys_capset,sys32_capset_wrapper)            /* 185 */
 SYSCALL(sys_sigaltstack,sys_sigaltstack,compat_sys_sigaltstack)
-SYSCALL(sys_sendfile,sys_sendfile64,sys32_sendfile_wrapper)
+SYSCALL(sys_sendfile,sys_sendfile64,compat_sys_sendfile)
 NI_SYSCALL                                                     /* streams1 */
 NI_SYSCALL                                                     /* streams2 */
 SYSCALL(sys_vfork,sys_vfork,sys_vfork)                         /* 190 */
@@ -231,7 +231,7 @@ SYSCALL(sys_madvise,sys_madvise,sys32_madvise_wrapper)
 SYSCALL(sys_getdents64,sys_getdents64,sys32_getdents64_wrapper)        /* 220 */
 SYSCALL(sys_fcntl64,sys_ni_syscall,compat_sys_fcntl64_wrapper)
 SYSCALL(sys_readahead,sys_readahead,sys32_readahead_wrapper)
-SYSCALL(sys_sendfile64,sys_ni_syscall,sys32_sendfile64_wrapper)
+SYSCALL(sys_sendfile64,sys_ni_syscall,compat_sys_sendfile64)
 SYSCALL(sys_setxattr,sys_setxattr,sys32_setxattr_wrapper)
 SYSCALL(sys_lsetxattr,sys_lsetxattr,sys32_lsetxattr_wrapper)   /* 225 */
 SYSCALL(sys_fsetxattr,sys_fsetxattr,sys32_fsetxattr_wrapper)
index 240a3cecc11e620dccf6c941bcd6fd08fcd793be..6c65d69c6635eaf85674eadb0d356338c45732ff 100644 (file)
@@ -46,7 +46,6 @@ SIGN1(sys32_io_submit, compat_sys_io_submit, %o1)
 SIGN1(sys32_mq_open, compat_sys_mq_open, %o1)
 SIGN1(sys32_select, compat_sys_select, %o0)
 SIGN3(sys32_futex, compat_sys_futex, %o1, %o2, %o5)
-SIGN2(sys32_sendfile, compat_sys_sendfile, %o0, %o1)
 SIGN1(sys32_recvfrom, compat_sys_recvfrom, %o0)
 SIGN1(sys32_recvmsg, compat_sys_recvmsg, %o0)
 SIGN1(sys32_sendmsg, compat_sys_sendmsg, %o0)
index 088134834dab4fd0da1293c8a3b20cb0c7a9813d..a1444d0d08eec7e69e50778e627e2d990e0572e9 100644 (file)
@@ -25,7 +25,7 @@ sys_call_table32:
 /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16
 /*25*/ .word sys32_vmsplice, compat_sys_ptrace, sys_alarm, compat_sys_sigaltstack, sys_pause
 /*30*/ .word compat_sys_utime, sys_lchown, sys_fchown, sys_access, sys_nice
-       .word sys_chown, sys_sync, sys_kill, compat_sys_newstat, sys32_sendfile
+       .word sys_chown, sys_sync, sys_kill, compat_sys_newstat, compat_sys_sendfile
 /*40*/ .word compat_sys_newlstat, sys_dup, sys_sparc_pipe, compat_sys_times, sys_getuid
        .word sys_umount, sys_setgid16, sys_getgid16, sys_signal, sys_geteuid16
 /*50*/ .word sys_getegid16, sys_acct, sys_nis_syscall, sys_getgid, compat_sys_ioctl
index ad7a20cbc69932cdc97e2c334fffd418000f2ffd..ad6ca047272257a6ae21fc9ce34a706ca4667411 100644 (file)
@@ -194,26 +194,6 @@ asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
 }
 
 
-asmlinkage long sys32_sendfile(int out_fd, int in_fd,
-                              compat_off_t __user *offset, s32 count)
-{
-       mm_segment_t old_fs = get_fs();
-       int ret;
-       off_t of;
-
-       if (offset && get_user(of, offset))
-               return -EFAULT;
-
-       set_fs(KERNEL_DS);
-       ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
-                          count);
-       set_fs(old_fs);
-
-       if (offset && put_user(of, offset))
-               return -EFAULT;
-       return ret;
-}
-
 /*
  * Some system calls that need sign extended arguments. This could be
  * done by a generic wrapper.
index 8459efc39686681e20c5cca85e86445b11b75b7d..6d944e4bb5247f5877d674304befc36d74a380fe 100644 (file)
@@ -41,7 +41,6 @@ asmlinkage long sys32_pread(unsigned int, char __user *, u32, u32, u32);
 asmlinkage long sys32_pwrite(unsigned int, const char __user *, u32, u32, u32);
 
 asmlinkage long sys32_personality(unsigned long);
-asmlinkage long sys32_sendfile(int, int, compat_off_t __user *, s32);
 
 long sys32_kill(int, int);
 long sys32_fadvise64_64(int, __u32, __u32, __u32, __u32, int);
index e6d55f0064dfd75c9c46f1d44a0b1a1ab1d1a8ca..6a00b1257d68903b3cd45d783f0637da06027a95 100644 (file)
 184    i386    capget                  sys_capget
 185    i386    capset                  sys_capset
 186    i386    sigaltstack             sys_sigaltstack                 compat_sys_sigaltstack
-187    i386    sendfile                sys_sendfile                    sys32_sendfile
+187    i386    sendfile                sys_sendfile                    compat_sys_sendfile
 188    i386    getpmsg
 189    i386    putpmsg
 190    i386    vfork                   sys_vfork                       stub32_vfork
index cc09312f9aede4ef940f7cc53a5437dd25616b5e..2ae2a98891cd82436ed1c18af5fb3c7a5981f0ec 100644 (file)
@@ -1718,25 +1718,3 @@ COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
        return do_handle_open(mountdirfd, handle, flags);
 }
 #endif
-
-#ifdef __ARCH_WANT_COMPAT_SYS_SENDFILE
-asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
-                                   compat_off_t __user *offset, compat_size_t count)
-{
-       loff_t pos;
-       off_t off;
-       ssize_t ret;
-
-       if (offset) {
-               if (unlikely(get_user(off, offset)))
-                       return -EFAULT;
-               pos = off;
-               ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
-               if (unlikely(put_user(pos, offset)))
-                       return -EFAULT;
-               return ret;
-       }
-
-       return do_sendfile(out_fd, in_fd, NULL, count, 0);
-}
-#endif /* __ARCH_WANT_COMPAT_SYS_SENDFILE */
index dcfd58d95f44757e2496f57aa3430c3989efa75b..f738e4dccfab143d22981249165c216482895c1c 100644 (file)
@@ -853,8 +853,8 @@ SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
        return ret;
 }
 
-ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
-                   loff_t max)
+static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
+                          size_t count, loff_t max)
 {
        struct fd in, out;
        struct inode *in_inode, *out_inode;
@@ -978,3 +978,43 @@ SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset, si
 
        return do_sendfile(out_fd, in_fd, NULL, count, 0);
 }
+
+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
+               compat_off_t __user *, offset, compat_size_t, count)
+{
+       loff_t pos;
+       off_t off;
+       ssize_t ret;
+
+       if (offset) {
+               if (unlikely(get_user(off, offset)))
+                       return -EFAULT;
+               pos = off;
+               ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
+               if (unlikely(put_user(pos, offset)))
+                       return -EFAULT;
+               return ret;
+       }
+
+       return do_sendfile(out_fd, in_fd, NULL, count, 0);
+}
+
+COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
+               compat_loff_t __user *, offset, compat_size_t, count)
+{
+       loff_t pos;
+       ssize_t ret;
+
+       if (offset) {
+               if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
+                       return -EFAULT;
+               ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
+               if (unlikely(put_user(pos, offset)))
+                       return -EFAULT;
+               return ret;
+       }
+
+       return do_sendfile(out_fd, in_fd, NULL, count, 0);
+}
+#endif
index d3e00ef674203930b0a0d190fb6b10a0d12b6032..d07b954c6e0c39afc06f99b40eb5bbcb2f0cc60b 100644 (file)
@@ -12,5 +12,3 @@ ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
                unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn);
 ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
                unsigned long nr_segs, loff_t *ppos, io_fn_t fn);
-ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
-                   loff_t max);
index 110132527e4c52ca67fa9fec119563af6642e483..ad299afcd488d2e9b2b5bd97d02e250c479e7089 100644 (file)
@@ -670,6 +670,8 @@ asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid,
 
 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
                                    compat_off_t __user *offset, compat_size_t count);
+asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
+                                   compat_loff_t __user *offset, compat_size_t count);
 asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
                                       compat_stack_t __user *uoss_ptr);