OSDN Git Service

Revert "x86/signal/64: Re-add support for SS in the 64-bit signal context"
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 6 Jul 2017 08:17:03 +0000 (16:17 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 24 Apr 2018 05:05:09 +0000 (13:05 +0800)
This reverts commit 6c25da5ad55d48c41b8909bc1f4e3cd5d85bb499.

Conflcts:
arch/x86/kernel/signal.c
tools/testing/selftests/x86/Makefile

arch/x86/include/asm/sighandling.h
arch/x86/include/uapi/asm/sigcontext.h
arch/x86/include/uapi/asm/ucontext.h
arch/x86/kernel/signal.c

index 452c88b..89db467 100644 (file)
@@ -13,6 +13,7 @@
                         X86_EFLAGS_CF | X86_EFLAGS_RF)
 
 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc);
 int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
                     struct pt_regs *regs, unsigned long mask);
 
index 62d4111..702c404 100644 (file)
@@ -256,7 +256,7 @@ struct sigcontext_64 {
        __u16                           cs;
        __u16                           gs;
        __u16                           fs;
-       __u16                           ss;
+       __u16                           __pad0;
        __u64                           err;
        __u64                           trapno;
        __u64                           oldmask;
@@ -368,10 +368,7 @@ struct sigcontext {
         */
        __u16                           gs;
        __u16                           fs;
-       union {
-               __u16                   ss;     /* If UC_SIGCONTEXT_SS */
-               __u16                   __pad0; /* Alias name for old (!UC_SIGCONTEXT_SS) user-space */
-       };
+       __u16                           __pad0;
        __u64                           err;
        __u64                           trapno;
        __u64                           oldmask;
index e3d1ec9..b7c29c8 100644 (file)
@@ -1,54 +1,11 @@
 #ifndef _ASM_X86_UCONTEXT_H
 #define _ASM_X86_UCONTEXT_H
 
-/*
- * Indicates the presence of extended state information in the memory
- * layout pointed by the fpstate pointer in the ucontext's sigcontext
- * struct (uc_mcontext).
- */
-#define UC_FP_XSTATE   0x1
-
-#ifdef __x86_64__
-/*
- * UC_SIGCONTEXT_SS will be set when delivering 64-bit or x32 signals on
- * kernels that save SS in the sigcontext.  All kernels that set
- * UC_SIGCONTEXT_SS will correctly restore at least the low 32 bits of esp
- * regardless of SS (i.e. they implement espfix).
- *
- * Kernels that set UC_SIGCONTEXT_SS will also set UC_STRICT_RESTORE_SS
- * when delivering a signal that came from 64-bit code.
- *
- * Sigreturn restores SS as follows:
- *
- * if (saved SS is valid || UC_STRICT_RESTORE_SS is set ||
- *     saved CS is not 64-bit)
- *         new SS = saved SS  (will fail IRET and signal if invalid)
- * else
- *         new SS = a flat 32-bit data segment
- *
- * This behavior serves three purposes:
- *
- * - Legacy programs that construct a 64-bit sigcontext from scratch
- *   with zero or garbage in the SS slot (e.g. old CRIU) and call
- *   sigreturn will still work.
- *
- * - Old DOSEMU versions sometimes catch a signal from a segmented
- *   context, delete the old SS segment (with modify_ldt), and change
- *   the saved CS to a 64-bit segment.  These DOSEMU versions expect
- *   sigreturn to send them back to 64-bit mode without killing them,
- *   despite the fact that the SS selector when the signal was raised is
- *   no longer valid.  UC_STRICT_RESTORE_SS will be clear, so the kernel
- *   will fix up SS for these DOSEMU versions.
- *
- * - Old and new programs that catch a signal and return without
- *   modifying the saved context will end up in exactly the state they
- *   started in, even if they were running in a segmented context when
- *   the signal was raised..  Old kernels would lose track of the
- *   previous SS value.
- */
-#define UC_SIGCONTEXT_SS       0x2
-#define UC_STRICT_RESTORE_SS   0x4
-#endif
+#define UC_FP_XSTATE   0x1     /* indicates the presence of extended state
+                                * information in the memory layout pointed
+                                * by the fpstate pointer in the ucontext's
+                                * sigcontext struct (uc_mcontext).
+                                */
 
 #include <asm-generic/ucontext.h>
 
index 763af1d..c63de8d 100644 (file)
@@ -91,9 +91,7 @@ static void force_valid_ss(struct pt_regs *regs)
 }
 #endif
 
-static int restore_sigcontext(struct pt_regs *regs,
-                             struct sigcontext __user *sc,
-                             unsigned long uc_flags)
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
 {
        unsigned long buf_val;
        void __user *buf;
@@ -126,18 +124,15 @@ static int restore_sigcontext(struct pt_regs *regs,
                COPY(r15);
 #endif /* CONFIG_X86_64 */
 
+#ifdef CONFIG_X86_32
                COPY_SEG_CPL3(cs);
                COPY_SEG_CPL3(ss);
-
-#ifdef CONFIG_X86_64
-               /*
-                * Fix up SS if needed for the benefit of old DOSEMU and
-                * CRIU.
-                */
-               if (unlikely(!(uc_flags & UC_STRICT_RESTORE_SS) &&
-                            user_64bit_mode(regs)))
-                       force_valid_ss(regs);
-#endif
+#else /* !CONFIG_X86_32 */
+               /* Kernel saves and restores only the CS segment register on signals,
+                * which is the bare minimum needed to allow mixed 32/64-bit code.
+                * App's signal handler can save/restore other segments if needed. */
+               COPY_SEG_CPL3(cs);
+#endif /* CONFIG_X86_32 */
 
                get_user_ex(tmpflags, &sc->flags);
                regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
@@ -200,7 +195,6 @@ int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
                put_user_ex(regs->cs, &sc->cs);
                put_user_ex(0, &sc->gs);
                put_user_ex(0, &sc->fs);
-               put_user_ex(regs->ss, &sc->ss);
 #endif /* CONFIG_X86_32 */
 
                put_user_ex(fpstate, &sc->fpstate);
@@ -438,21 +432,6 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
        return 0;
 }
 #else /* !CONFIG_X86_32 */
-static unsigned long frame_uc_flags(struct pt_regs *regs)
-{
-       unsigned long flags;
-
-       if (boot_cpu_has(X86_FEATURE_XSAVE))
-               flags = UC_FP_XSTATE | UC_SIGCONTEXT_SS;
-       else
-               flags = UC_SIGCONTEXT_SS;
-
-       if (likely(user_64bit_mode(regs)))
-               flags |= UC_STRICT_RESTORE_SS;
-
-       return flags;
-}
-
 static int __setup_rt_frame(int sig, struct ksignal *ksig,
                            sigset_t *set, struct pt_regs *regs)
 {
@@ -472,7 +451,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
 
        put_user_try {
                /* Create the ucontext.  */
-               put_user_ex(frame_uc_flags(regs), &frame->uc.uc_flags);
+               if (boot_cpu_has(X86_FEATURE_XSAVE))
+                       put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
+               else
+                       put_user_ex(0, &frame->uc.uc_flags);
                put_user_ex(0, &frame->uc.uc_link);
                save_altstack_ex(&frame->uc.uc_stack, regs->sp);
 
@@ -554,7 +536,10 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
 
        put_user_try {
                /* Create the ucontext.  */
-               put_user_ex(frame_uc_flags(regs), &frame->uc.uc_flags);
+               if (boot_cpu_has(X86_FEATURE_XSAVE))
+                       put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
+               else
+                       put_user_ex(0, &frame->uc.uc_flags);
                put_user_ex(0, &frame->uc.uc_link);
                compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
                put_user_ex(0, &frame->uc.uc__pad0);
@@ -616,11 +601,7 @@ asmlinkage unsigned long sys_sigreturn(void)
 
        set_current_blocked(&set);
 
-       /*
-        * x86_32 has no uc_flags bits relevant to restore_sigcontext.
-        * Save a few cycles by skipping the __get_user.
-        */
-       if (restore_sigcontext(regs, &frame->sc, 0))
+       if (restore_sigcontext(regs, &frame->sc))
                goto badframe;
        return regs->ax;
 
@@ -636,19 +617,16 @@ asmlinkage long sys_rt_sigreturn(void)
        struct pt_regs *regs = current_pt_regs();
        struct rt_sigframe __user *frame;
        sigset_t set;
-       unsigned long uc_flags;
 
        frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
        if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
                goto badframe;
        if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
                goto badframe;
-       if (__get_user(uc_flags, &frame->uc.uc_flags))
-               goto badframe;
 
        set_current_blocked(&set);
 
-       if (restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
+       if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
                goto badframe;
 
        if (restore_altstack(&frame->uc.uc_stack))
@@ -858,7 +836,6 @@ asmlinkage long sys32_x32_rt_sigreturn(void)
        struct pt_regs *regs = current_pt_regs();
        struct rt_sigframe_x32 __user *frame;
        sigset_t set;
-       unsigned long uc_flags;
 
        frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
 
@@ -866,12 +843,10 @@ asmlinkage long sys32_x32_rt_sigreturn(void)
                goto badframe;
        if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
                goto badframe;
-       if (__get_user(uc_flags, &frame->uc.uc_flags))
-               goto badframe;
 
        set_current_blocked(&set);
 
-       if (restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
+       if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
                goto badframe;
 
        if (compat_restore_altstack(&frame->uc.uc_stack))