]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/powerpc/kernel/signal_64.c
Merge branch 'v28-timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-omap-h63xx.git] / arch / powerpc / kernel / signal_64.c
index 93ebfb6944b6e9ff5e9a49e1c6ae039f582857ca..c6a8f2326b6f246fc077b25c2b7b1d9460f9e6cc 100644 (file)
@@ -122,7 +122,7 @@ static long setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
         * VMX data.
         */
        if (current->thread.used_vsr) {
-               flush_vsx_to_thread(current);
+               __giveup_vsx(current);
                v_regs += ELF_NVRREG;
                err |= copy_vsx_to_user(v_regs, current);
                /* set MSR_VSX in the MSR value in the frame to
@@ -235,8 +235,6 @@ static long restore_sigcontext(struct pt_regs *regs, sigset_t *set, int sig,
        else
                for (i = 0; i < 32 ; i++)
                        current->thread.fpr[i][TS_VSRLOWOFFSET] = 0;
-
-#else
 #endif
        return err;
 }
@@ -267,6 +265,13 @@ static long setup_trampoline(unsigned int syscall, unsigned int __user *tramp)
        return err;
 }
 
+/*
+ * Userspace code may pass a ucontext which doesn't include VSX added
+ * at the end.  We need to check for this case.
+ */
+#define UCONTEXTSIZEWITHOUTVSX \
+               (sizeof(struct ucontext) - 32*sizeof(long))
+
 /*
  * Handle {get,set,swap}_context operations
  */
@@ -276,13 +281,34 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
 {
        unsigned char tmp;
        sigset_t set;
+       unsigned long new_msr = 0;
 
-       /* Context size is for future use. Right now, we only make sure
-        * we are passed something we understand
+       if (new_ctx &&
+           __get_user(new_msr, &new_ctx->uc_mcontext.gp_regs[PT_MSR]))
+               return -EFAULT;
+       /*
+        * Check that the context is not smaller than the original
+        * size (with VMX but without VSX)
         */
-       if (ctx_size < sizeof(struct ucontext))
+       if (ctx_size < UCONTEXTSIZEWITHOUTVSX)
                return -EINVAL;
-
+       /*
+        * If the new context state sets the MSR VSX bits but
+        * it doesn't provide VSX state.
+        */
+       if ((ctx_size < sizeof(struct ucontext)) &&
+           (new_msr & MSR_VSX))
+               return -EINVAL;
+#ifdef CONFIG_VSX
+       /*
+        * If userspace doesn't provide enough room for VSX data,
+        * but current thread has used VSX, we don't have anywhere
+        * to store the full context back into.
+        */
+       if ((ctx_size < sizeof(struct ucontext)) &&
+           (current->thread.used_vsr && old_ctx))
+               return -EINVAL;
+#endif
        if (old_ctx != NULL) {
                if (!access_ok(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
                    || setup_sigcontext(&old_ctx->uc_mcontext, regs, 0, NULL, 0)