arm64: sanitize copy_thread(), switch to generic fork/vfork/clone
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 21 Oct 2012 19:56:52 +0000 (15:56 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 29 Nov 2012 03:36:33 +0000 (22:36 -0500)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/arm64/Kconfig
arch/arm64/include/asm/syscalls.h
arch/arm64/include/asm/unistd.h
arch/arm64/include/asm/unistd32.h
arch/arm64/kernel/process.c
arch/arm64/kernel/sys.c
arch/arm64/kernel/sys_compat.c

index 20b688c81956149cfe8e93a540b9b40c42ff2ac3..4b03c56ec3294e249f788a723b62827698cf9cf5 100644 (file)
@@ -33,6 +33,7 @@ config ARM64
        select RTC_LIB
        select SPARSE_IRQ
        select SYSCTL_EXCEPTION_TRACE
+       select CLONE_BACKWARDS
        help
          ARM 64-bit (AArch64) Linux support.
 
index a1b00cd6f78635b3babdab3d499a5e44e9320504..010ec127dc5b7cbc93ea7e7a210676dd1b8376c5 100644 (file)
@@ -31,6 +31,8 @@ asmlinkage long sys_sigaltstack_wrapper(const stack_t __user *uss,
  * AArch64 sys_clone implementation has a different prototype than the generic
  * one (additional TLS value argument).
  */
+asmlinkage long sys_clone(unsigned long, unsigned long, void __user *, int,
+              void __user *);
 #define sys_clone      sys_clone
 
 #include <asm-generic/syscalls.h>
index 43064a8bd99e4df93f6211fe3774e52c4e55fb5b..d69aeea6da1e83fd6fc36c435007f0104ba96af0 100644 (file)
@@ -24,6 +24,9 @@
 #define __ARCH_WANT_SYS_SIGPROCMASK
 #define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
 #define __ARCH_WANT_COMPAT_SYS_SENDFILE
+#define __ARCH_WANT_SYS_FORK
+#define __ARCH_WANT_SYS_VFORK
 #endif
 #define __ARCH_WANT_SYS_EXECVE
+#define __ARCH_WANT_SYS_CLONE
 #include <uapi/asm/unistd.h>
index d9850cf9870ded8f0fa945f1d3d543ba939579e1..30127cb11adef08fabb85234cc6d8f2344e7a117 100644 (file)
@@ -23,7 +23,7 @@
 
 __SYSCALL(0,   sys_restart_syscall)
 __SYSCALL(1,   sys_exit)
-__SYSCALL(2,   compat_sys_fork)
+__SYSCALL(2,   sys_fork)
 __SYSCALL(3,   sys_read)
 __SYSCALL(4,   sys_write)
 __SYSCALL(5,   compat_sys_open)
@@ -211,7 +211,7 @@ __SYSCALL(186, compat_sys_sigaltstack_wrapper)
 __SYSCALL(187, compat_sys_sendfile)
 __SYSCALL(188, sys_ni_syscall)                 /* 188 reserved */
 __SYSCALL(189, sys_ni_syscall)                 /* 189 reserved */
-__SYSCALL(190, compat_sys_vfork)
+__SYSCALL(190, sys_vfork)
 __SYSCALL(191, compat_sys_getrlimit)           /* SuS compliant getrlimit */
 __SYSCALL(192, sys_mmap_pgoff)
 __SYSCALL(193, compat_sys_truncate64_wrapper)
index 8a5f3341861e579bd7434393b23b82b6291bb19a..5a1335caf6f1ea9cc01f2056b116472f9a71bf55 100644 (file)
@@ -235,15 +235,15 @@ asmlinkage void ret_from_fork(void) asm("ret_from_fork");
 
 int copy_thread(unsigned long clone_flags, unsigned long stack_start,
                unsigned long stk_sz, struct task_struct *p,
-               struct pt_regs *regs)
+               struct pt_regs *unused)
 {
        struct pt_regs *childregs = task_pt_regs(p);
        unsigned long tls = p->thread.tp_value;
 
        memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
 
-       if (likely(regs)) {
-               *childregs = *regs;
+       if (likely(!(p->flags & PF_KTHREAD))) {
+               *childregs = *current_pt_regs();
                childregs->regs[0] = 0;
                if (is_compat_thread(task_thread_info(p))) {
                        if (stack_start)
@@ -266,7 +266,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
                 * for the new thread.
                 */
                if (clone_flags & CLONE_SETTLS)
-                       tls = regs->regs[3];
+                       tls = childregs->regs[3];
        } else {
                memset(childregs, 0, sizeof(struct pt_regs));
                childregs->pstate = PSR_MODE_EL1h;
index 4364df85050e79f7e838745531f01d7b30a82b8c..8292a9b090f8d72ab570eaa4e24a4cb9739c252c 100644 (file)
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 
-/*
- * Clone a task - this clones the calling program thread.
- */
-asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp,
-                         int __user *parent_tidptr, unsigned long tls_val,
-                         int __user *child_tidptr)
-{
-       return do_fork(clone_flags, newsp, current_pt_regs(), 0,
-                       parent_tidptr, child_tidptr);
-}
-
 asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
                         unsigned long prot, unsigned long flags,
                         unsigned long fd, off_t off)
index 6fabc1912da0eaf6b3b0c9f0cbad4cf98fca9c74..f7b05edf8ce36c925196b59dcf4c03ac12259b73 100644 (file)
 #include <asm/cacheflush.h>
 #include <asm/unistd32.h>
 
-asmlinkage int compat_sys_fork(void)
-{
-       return do_fork(SIGCHLD, 0, current_pt_regs(), 0, NULL, NULL);
-}
-
-asmlinkage int compat_sys_vfork(void)
-{
-       return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
-                      current_pt_regs(), 0, NULL, NULL);
-}
-
 asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
                                                struct compat_timespec __user *interval)
 {