improve sys_newuname() for compat architectures
authorChristoph Hellwig <hch@lst.de>
Wed, 10 Mar 2010 23:21:19 +0000 (15:21 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 12 Mar 2010 23:52:32 +0000 (15:52 -0800)
On an architecture that supports 32-bit compat we need to override the
reported machine in uname with the 32-bit value.  Instead of doing this
separately in every architecture introduce a COMPAT_UTS_MACHINE define in
<asm/compat.h> and apply it directly in sys_newuname().

Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Hirokazu Takata <takata@linux-m32r.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
28 files changed:
arch/ia64/include/asm/compat.h
arch/mips/include/asm/compat.h
arch/mips/kernel/linux32.c
arch/mips/kernel/scall64-n32.S
arch/mips/kernel/scall64-o32.S
arch/parisc/include/asm/compat.h
arch/parisc/kernel/sys_parisc.c
arch/parisc/kernel/syscall_table.S
arch/powerpc/include/asm/compat.h
arch/powerpc/include/asm/syscalls.h
arch/powerpc/include/asm/systbl.h
arch/powerpc/kernel/syscalls.c
arch/s390/include/asm/compat.h
arch/s390/kernel/compat_wrapper.S
arch/s390/kernel/entry.h
arch/s390/kernel/sys_s390.c
arch/s390/kernel/syscalls.S
arch/sparc/include/asm/compat.h
arch/sparc/kernel/sys_sparc_64.c
arch/sparc/kernel/systbls.h
arch/sparc/kernel/systbls_64.S
arch/um/sys-x86_64/syscall_table.c
arch/um/sys-x86_64/syscalls.c
arch/x86/include/asm/compat.h
arch/x86/include/asm/syscalls.h
arch/x86/include/asm/unistd_64.h
arch/x86/kernel/sys_x86_64.c
kernel/sys.c

index dfcf75b8426d8bde81dd8b7fda51ad5f12df137c..f90edc85b50933a9df52391d041ad9f8b1a8ee66 100644 (file)
@@ -5,7 +5,8 @@
  */
 #include <linux/types.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "i686\0\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index f58aed354bfd3a50095e30cbb879045b57f85410..613f6912dfc1d024b2aa6b28fb4215ba8b251552 100644 (file)
@@ -8,7 +8,8 @@
 #include <asm/page.h>
 #include <asm/ptrace.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "mips\0\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index bde79ef602e6e84dbdf48c2de52e02907f52eb16..a39d0597a37583df6e24d0e09f6ce63f7a96617a 100644 (file)
@@ -249,22 +249,6 @@ SYSCALL_DEFINE5(n32_msgrcv, int, msqid, u32, msgp, size_t, msgsz,
 }
 #endif
 
-SYSCALL_DEFINE1(32_newuname, struct new_utsname __user *, name)
-{
-       int ret = 0;
-
-       down_read(&uts_sem);
-       if (copy_to_user(name, utsname(), sizeof *name))
-               ret = -EFAULT;
-       up_read(&uts_sem);
-
-       if (current->personality == PER_LINUX32 && !ret)
-               if (copy_to_user(name->machine, "mips\0\0\0", 8))
-                       ret = -EFAULT;
-
-       return ret;
-}
-
 SYSCALL_DEFINE1(32_personality, unsigned long, personality)
 {
        int ret;
index 66b5a48676ddd8cc6d99d35d793142147f461ac4..44337ba03717a573119659fcc94fec11c9564b61 100644 (file)
@@ -181,7 +181,7 @@ EXPORT(sysn32_call_table)
        PTR     sys_exit
        PTR     compat_sys_wait4
        PTR     sys_kill                        /* 6060 */
-       PTR     sys_32_newuname
+       PTR     sys_newuname
        PTR     sys_semget
        PTR     sys_semop
        PTR     sys_n32_semctl
index 515f9eab2b28814b30b7544a9a95aa9c8ba17abb..813689ef23847c6a2db230ebd6dcae60e0ff79f6 100644 (file)
@@ -325,7 +325,7 @@ sys_call_table:
        PTR     sys32_sigreturn
        PTR     sys32_clone                     /* 4120 */
        PTR     sys_setdomainname
-       PTR     sys_32_newuname
+       PTR     sys_newuname
        PTR     sys_ni_syscall                  /* sys_modify_ldt */
        PTR     compat_sys_adjtimex
        PTR     sys_mprotect                    /* 4125 */
index 7f32611a7a5ebc1fe64e36716db7748df21c5070..02b77baa5da69f04729013cd9b6402ffc2dc3c39 100644 (file)
@@ -7,7 +7,8 @@
 #include <linux/sched.h>
 #include <linux/thread_info.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ                 100
+#define COMPAT_UTS_MACHINE     "parisc\0\0"
 
 typedef u32    compat_size_t;
 typedef s32    compat_ssize_t;
index 9147391afb03ef0590ae7a9167919c408dbd82e7..c9b932260f4713969cc8df8c51a9813110fb622f 100644 (file)
@@ -234,18 +234,3 @@ long parisc_personality(unsigned long personality)
 
        return err;
 }
-
-long parisc_newuname(struct new_utsname __user *name)
-{
-       int err = sys_newuname(name);
-
-#ifdef CONFIG_COMPAT
-       if (!err && personality(current->personality) == PER_LINUX32) {
-               if (__put_user(0, name->machine + 6) ||
-                   __put_user(0, name->machine + 7))
-                       err = -EFAULT;
-       }
-#endif
-
-       return err;
-}
index de5f6dab48b70564b72349e0aa2106d9b80937eb..3d52c978738faeb7bf83cda9998263875f81bced 100644 (file)
        ENTRY_SAME(socketpair)
        ENTRY_SAME(setpgid)
        ENTRY_SAME(send)
-       ENTRY_OURS(newuname)
+       ENTRY_SAME(newuname)
        ENTRY_SAME(umask)               /* 60 */
        ENTRY_SAME(chroot)
        ENTRY_COMP(ustat)
index 4774c2f92232b8ce98177d555b4d2c592dc076e5..396d21a800587f0c8a740714a3277a743d2618cc 100644 (file)
@@ -7,7 +7,8 @@
 #include <linux/types.h>
 #include <linux/sched.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "ppc\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index 23bb74e7f946f0dc17d4c159cdeec9b729205af3..4084e567d28ef0d41b4bc2834270bd80c7e1eaa4 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/types.h>
 #include <asm/signal.h>
 
-struct new_utsname;
 struct pt_regs;
 struct rtas_args;
 struct sigaction;
@@ -38,7 +37,6 @@ asmlinkage long sys_rt_sigaction(int sig,
 asmlinkage long ppc64_personality(unsigned long personality);
 asmlinkage int ppc_rtas(struct rtas_args __user *uargs);
 asmlinkage time_t sys64_time(time_t __user * tloc);
-asmlinkage long ppc_newuname(struct new_utsname __user * name);
 
 asmlinkage long sys_rt_sigsuspend(sigset_t __user *unewset,
                size_t sigsetsize);
index 07d2d19ab5e9a59696dff7659d31cefb04343616..a5ee345b6a5cc27134bb42742641048aeba48eb6 100644 (file)
@@ -125,7 +125,7 @@ SYSCALL_SPU(fsync)
 SYS32ONLY(sigreturn)
 PPC_SYS(clone)
 COMPAT_SYS_SPU(setdomainname)
-PPC_SYS_SPU(newuname)
+SYSCALL_SPU(newuname)
 SYSCALL(ni_syscall)
 COMPAT_SYS_SPU(adjtimex)
 SYSCALL_SPU(mprotect)
index 5251221e7a5a60fa24ebe8b94073ebed729986ce..69d3c5d50a54a2295d33fa4e94b629ea0b09f4a7 100644 (file)
@@ -132,19 +132,6 @@ static inline int override_machine(char __user *mach)
        return 0;
 }
 
-long ppc_newuname(struct new_utsname __user * name)
-{
-       int err = 0;
-
-       down_read(&uts_sem);
-       if (copy_to_user(name, utsname(), sizeof(*name)))
-               err = -EFAULT;
-       up_read(&uts_sem);
-       if (!err)
-               err = override_machine(name->machine);
-       return err;
-}
-
 int sys_uname(struct old_utsname __user *name)
 {
        int err = 0;
index 01a08020bc0e2bb3757e783ca51ee35478bbbc52..104f2007f097720b339e469d37b7732c120c8168 100644 (file)
@@ -35,7 +35,8 @@
 
 extern long psw32_user_bits;
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "s390\0\0\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index 30de2d0e52bb421e41efabd67cdbc677bb7e5539..672ce52341b451c1dc22ecf27629f7026197c86d 100644 (file)
@@ -547,7 +547,7 @@ sys32_setdomainname_wrapper:
        .globl  sys32_newuname_wrapper
 sys32_newuname_wrapper:
        llgtr   %r2,%r2                 # struct new_utsname *
-       jg      sys_s390_newuname       # branch to system call
+       jg      sys_newuname            # branch to system call
 
        .globl  compat_sys_adjtimex_wrapper
 compat_sys_adjtimex_wrapper:
index 15fd68b196c089f2b881f74df55843deab43fb8b..eb15c12ec158c329146ded2d797cb907a186d4a5 100644 (file)
@@ -24,7 +24,6 @@ int __cpuinit start_secondary(void *cpuvoid);
 void __init startup_init(void);
 void die(const char * str, struct pt_regs * regs, long err);
 
-struct new_utsname;
 struct s390_mmap_arg_struct;
 struct fadvise64_64_args;
 struct old_sigaction;
@@ -32,7 +31,6 @@ struct old_sigaction;
 long sys_mmap2(struct s390_mmap_arg_struct __user  *arg);
 long sys_s390_ipc(uint call, int first, unsigned long second,
             unsigned long third, void __user *ptr);
-long sys_s390_newuname(struct new_utsname __user *name);
 long sys_s390_personality(unsigned long personality);
 long sys_s390_fadvise64(int fd, u32 offset_high, u32 offset_low,
                    size_t len, int advice);
index b8b78092ab7ca859c2a317e067839abc6ab3be14..7b6b0f81a28308cf9f72c43126307c035cc83bf4 100644 (file)
@@ -131,17 +131,6 @@ SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
 }
 
 #ifdef CONFIG_64BIT
-SYSCALL_DEFINE1(s390_newuname, struct new_utsname __user *, name)
-{
-       int ret = sys_newuname(name);
-
-       if (personality(current->personality) == PER_LINUX32 && !ret) {
-               ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
-               if (ret) ret = -EFAULT;
-       }
-       return ret;
-}
-
 SYSCALL_DEFINE1(s390_personality, unsigned long, personality)
 {
        int ret;
index 990ac8b321c83c54707404fcf66d1eff22d234d5..201ce6bed34ec2587fd4bf04d80bfd0de351e5e1 100644 (file)
@@ -130,7 +130,7 @@ SYSCALL(sys_fsync,sys_fsync,sys32_fsync_wrapper)
 SYSCALL(sys_sigreturn,sys_sigreturn,sys32_sigreturn)
 SYSCALL(sys_clone,sys_clone,sys_clone_wrapper)                 /* 120 */
 SYSCALL(sys_setdomainname,sys_setdomainname,sys32_setdomainname_wrapper)
-SYSCALL(sys_newuname,sys_s390_newuname,sys32_newuname_wrapper)
+SYSCALL(sys_newuname,sys_newuname,sys32_newuname_wrapper)
 NI_SYSCALL                                                     /* modify_ldt for i386 */
 SYSCALL(sys_adjtimex,sys_adjtimex,compat_sys_adjtimex_wrapper)
 SYSCALL(sys_mprotect,sys_mprotect,sys32_mprotect_wrapper)      /* 125 */
index 0e706257918f35397b10657be3b95538ef23e45b..5016f76ea98a6f38510d3dc5a8593a1d871d4f53 100644 (file)
@@ -5,7 +5,8 @@
  */
 #include <linux/types.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "sparc\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index 45410e939628191bdfe7f8a7dd36d6232de1b8dd..3d435c42e6db58d62df3c5193a081816d6c7639a 100644 (file)
@@ -510,17 +510,6 @@ out:
        return err;
 }
 
-SYSCALL_DEFINE1(sparc64_newuname, struct new_utsname __user *, name)
-{
-       int ret = sys_newuname(name);
-       
-       if (current->personality == PER_LINUX32 && !ret) {
-               ret = (copy_to_user(name->machine, "sparc\0\0", 8)
-                      ? -EFAULT : 0);
-       }
-       return ret;
-}
-
 SYSCALL_DEFINE1(sparc64_personality, unsigned long, personality)
 {
        int ret;
index 2c331c37e74896c60b84109af062e407887f0d85..118759cd7342d0549389cc43a1d78ac261fc879b 100644 (file)
@@ -6,15 +6,12 @@
 #include <asm/utrap.h>
 #include <asm/signal.h>
 
-struct new_utsname;
-
 extern asmlinkage unsigned long sys_getpagesize(void);
 extern asmlinkage long sparc_pipe(struct pt_regs *regs);
 extern asmlinkage long sys_sparc_ipc(unsigned int call, int first,
                               unsigned long second,
                               unsigned long third,
                               void __user *ptr, long fifth);
-extern asmlinkage long sparc64_newuname(struct new_utsname __user *name);
 extern asmlinkage long sparc64_personality(unsigned long personality);
 extern asmlinkage long sys64_munmap(unsigned long addr, size_t len);
 extern asmlinkage unsigned long sys64_mremap(unsigned long addr,
index 30ca2b1d3a17c5d49d8839c567d457674b69fe4e..9db058dd039e5d0361e1276523e6a59f4cef8452 100644 (file)
@@ -55,7 +55,7 @@ sys_call_table32:
 /*170*/        .word sys32_lsetxattr, sys32_fsetxattr, sys_getxattr, sys_lgetxattr, compat_sys_getdents
        .word sys_setsid, sys_fchdir, sys32_fgetxattr, sys_listxattr, sys_llistxattr
 /*180*/        .word sys32_flistxattr, sys_removexattr, sys_lremovexattr, compat_sys_sigpending, sys_ni_syscall
-       .word sys32_setpgid, sys32_fremovexattr, sys32_tkill, sys32_exit_group, sys_sparc64_newuname
+       .word sys32_setpgid, sys32_fremovexattr, sys32_tkill, sys32_exit_group, sys_newuname
 /*190*/        .word sys32_init_module, sys_sparc64_personality, sys_remap_file_pages, sys32_epoll_create, sys32_epoll_ctl
        .word sys32_epoll_wait, sys32_ioprio_set, sys_getppid, sys32_sigaction, sys_sgetmask
 /*200*/        .word sys32_ssetmask, sys_sigsuspend, compat_sys_newlstat, sys_uselib, compat_sys_old_readdir
@@ -130,7 +130,7 @@ sys_call_table:
 /*170*/        .word sys_lsetxattr, sys_fsetxattr, sys_getxattr, sys_lgetxattr, sys_getdents
        .word sys_setsid, sys_fchdir, sys_fgetxattr, sys_listxattr, sys_llistxattr
 /*180*/        .word sys_flistxattr, sys_removexattr, sys_lremovexattr, sys_nis_syscall, sys_ni_syscall
-       .word sys_setpgid, sys_fremovexattr, sys_tkill, sys_exit_group, sys_sparc64_newuname
+       .word sys_setpgid, sys_fremovexattr, sys_tkill, sys_exit_group, sys_newuname
 /*190*/        .word sys_init_module, sys_sparc64_personality, sys_remap_file_pages, sys_epoll_create, sys_epoll_ctl
        .word sys_epoll_wait, sys_ioprio_set, sys_getppid, sys_nis_syscall, sys_sgetmask
 /*200*/        .word sys_ssetmask, sys_nis_syscall, sys_newlstat, sys_uselib, sys_nis_syscall
index dd21d69715e62abc7bacc3fde820466f9320cf44..47d469e7e7ceb06d6b4ab32b2c42c83ccbd8cdcf 100644 (file)
 
 /* On UML we call it this way ("old" means it's not mmap2) */
 #define sys_mmap old_mmap
-/*
- * On x86-64 sys_uname is actually sys_newuname plus a compatibility trick.
- * See arch/x86_64/kernel/sys_x86_64.c
- */
-#define sys_uname sys_uname64
 
 #define stub_clone sys_clone
 #define stub_fork sys_fork
index f1199fd34d383db5018f349ab811aaea5eb71197..f3d82bb6e15a410b5e706617526efe9d56a42243 100644 (file)
 #include "asm/uaccess.h"
 #include "os.h"
 
-asmlinkage long sys_uname64(struct new_utsname __user * name)
-{
-       int err;
-
-       down_read(&uts_sem);
-       err = copy_to_user(name, utsname(), sizeof (*name));
-       up_read(&uts_sem);
-
-       if (personality(current->personality) == PER_LINUX32)
-               err |= copy_to_user(&name->machine, "i686", 5);
-
-       return err ? -EFAULT : 0;
-}
-
 long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr)
 {
        unsigned long *ptr = addr, tmp;
index 9a9c7bdc923dee66a411bdae3f30065e9e4ee09f..306160e58b48772ccef1f65c803a3a3813ff5d1e 100644 (file)
@@ -8,7 +8,8 @@
 #include <linux/sched.h>
 #include <asm/user32.h>
 
-#define COMPAT_USER_HZ 100
+#define COMPAT_USER_HZ         100
+#define COMPAT_UTS_MACHINE     "i686\0\0"
 
 typedef u32            compat_size_t;
 typedef s32            compat_ssize_t;
index 50f6a569f0d14bd82e668c98e9785528fe08c4f6..47cd606c353757acf3742901c8fddde005c7fc53 100644 (file)
@@ -68,11 +68,8 @@ int sys_vm86(unsigned long, unsigned long, struct pt_regs *);
 long sys_arch_prctl(int, unsigned long);
 
 /* kernel/sys_x86_64.c */
-struct new_utsname;
-
 asmlinkage long sys_mmap(unsigned long, unsigned long, unsigned long,
                         unsigned long, unsigned long, unsigned long);
-asmlinkage long sys_uname(struct new_utsname __user *);
 
 #endif /* CONFIG_X86_32 */
 #endif /* _ASM_X86_SYSCALLS_H */
index 4843f7ba754a6a8b2674da68ecc14af3058b9d44..83e2d6dc50380ea806ddd0bde444b9fed1d8eaf0 100644 (file)
@@ -146,7 +146,7 @@ __SYSCALL(__NR_wait4, sys_wait4)
 #define __NR_kill                              62
 __SYSCALL(__NR_kill, sys_kill)
 #define __NR_uname                             63
-__SYSCALL(__NR_uname, sys_uname)
+__SYSCALL(__NR_uname, sys_newuname)
 
 #define __NR_semget                            64
 __SYSCALL(__NR_semget, sys_semget)
index 8aa2057efd12618aa20874b8a71fc40527cc6819..ff14a5044ce6ec66366f95acbffef82c732d23c5 100644 (file)
@@ -209,15 +209,3 @@ bottomup:
 
        return addr;
 }
-
-
-SYSCALL_DEFINE1(uname, struct new_utsname __user *, name)
-{
-       int err;
-       down_read(&uts_sem);
-       err = copy_to_user(name, utsname(), sizeof(*name));
-       up_read(&uts_sem);
-       if (personality(current->personality) == PER_LINUX32)
-               err |= copy_to_user(&name->machine, "i686", 5);
-       return err ? -EFAULT : 0;
-}
index 9814e43fb23b7539354ffc1cf685256ccdb4decf..e483eb5530e407c43cd86e732202562ca885ec8b 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/task_io_accounting_ops.h>
 #include <linux/seccomp.h>
 #include <linux/cpu.h>
+#include <linux/personality.h>
 #include <linux/ptrace.h>
 #include <linux/fs_struct.h>
 
@@ -1114,6 +1115,15 @@ out:
 
 DECLARE_RWSEM(uts_sem);
 
+#ifdef COMPAT_UTS_MACHINE
+#define override_architecture(name) \
+       (current->personality == PER_LINUX32 && \
+        copy_to_user(name->machine, COMPAT_UTS_MACHINE, \
+                     sizeof(COMPAT_UTS_MACHINE)))
+#else
+#define override_architecture(name)    0
+#endif
+
 SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
 {
        int errno = 0;
@@ -1122,6 +1132,9 @@ SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
        if (copy_to_user(name, utsname(), sizeof *name))
                errno = -EFAULT;
        up_read(&uts_sem);
+
+       if (!errno && override_architecture(name))
+               errno = -EFAULT;
        return errno;
 }