CHROMIUM: x86: need compat version of sys_prctl
authorOlof Johansson <olofj@chromium.org>
Fri, 17 Aug 2012 08:20:53 +0000 (01:20 -0700)
committerGerrit <chrome-bot@google.com>
Fri, 17 Aug 2012 14:18:41 +0000 (07:18 -0700)
Since PR_SET_PTRACER_ANY is the equvalent of (unsigned long)-1, it
needs to be sign extended for 32-bit compat.

Powerpc was the only arch that did any kind of compat handling for prctl,
so move that code to generic location and add the PR_SET_PTRACER check
as needed for the yama module.

BUG=chromium-os:33531
TEST=run security_ptraceRestrictions

Change-Id: I2c034025de8d71b5c317318cee2e079a38461e6d
Signed-off-by: Olof Johansson <olofj@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/30672
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
arch/powerpc/kernel/sys_ppc32.c
arch/x86/syscalls/syscall_32.tbl
kernel/compat.c

index 81c5706..7f5de20 100644 (file)
@@ -209,20 +209,6 @@ out:
        return error;
 }
 
-/* Note: it is necessary to treat option as an unsigned int, 
- * 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_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
-{
-       return sys_prctl((int)option,
-                        (unsigned long) arg2,
-                        (unsigned long) arg3,
-                        (unsigned long) arg4,
-                        (unsigned long) arg5);
-}
-
 /* Note: it is necessary to treat pid as an unsigned int, 
  * 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)
index 29f9f05..eda4e00 100644 (file)
 169    i386    nfsservctl
 170    i386    setresgid               sys_setresgid16
 171    i386    getresgid               sys_getresgid16
-172    i386    prctl                   sys_prctl
+172    i386    prctl                   sys_prctl                       compat_sys_prctl
 173    i386    rt_sigreturn            ptregs_rt_sigreturn             stub32_rt_sigreturn
 174    i386    rt_sigaction            sys_rt_sigaction                sys32_rt_sigaction
 175    i386    rt_sigprocmask          sys_rt_sigprocmask
index d2c67aa..54a6f32 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/posix-timers.h>
 #include <linux/times.h>
 #include <linux/ptrace.h>
+#include <linux/prctl.h>
 #include <linux/gfp.h>
 
 #include <asm/uaccess.h>
@@ -1223,6 +1224,28 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
        return 0;
 }
 
+/* Note: it is necessary to treat option as an unsigned int,
+ * with the corresponding cast to a signed int to ensure 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_prctl(u32 option, u32 arg2, u32 arg3,
+                                u32 arg4, u32 arg5)
+{
+       unsigned long a2 = arg2;
+
+       /* PR_SET_PTRACER_ANY is -1, so can't do an unsigned extension */
+       if (option == PR_SET_PTRACER && arg2 == (u32) PR_SET_PTRACER_ANY)
+               a2 = PR_SET_PTRACER_ANY;
+
+       return sys_prctl((int)option,
+                        (unsigned long) a2,
+                        (unsigned long) arg3,
+                        (unsigned long) arg4,
+                        (unsigned long) arg5);
+}
+
 /*
  * Allocate user-space memory for the duration of a single system call,
  * in order to marshall parameters inside a compat thunk.