On Thu, Aug 13, 2015 at 8:43 AM, Andy Lutomirski <l...@amacapital.net> wrote:
>
> I'm trying to fix it without reverting.  If that doesn't work, then we
> revert.  Yesterday, I thought I had a reasonably clean fix, but it
> turned out that it only solved half of the problem.

The thing is, I actually think that the current situation is crazy.

Especially given that we don't restore any of the other segment
registers on x86-64 (except CS, of course)

So how about this "alternate" minimal patch instead. The difference is:

 - we actually leave the

        regs->ss = __USER_DS;

   in __setup_rt_frame, to guarantee that when we take a signal, we do
take it with a valid SS

 - but it removes all the other games with SS (and treats it exactly
the same as FS/GS).

   So now we don't play games with the actual sigcontext, and
hopefully dosemu is happier.

Hmm? That actually makes the code look better, and doesn't
re-introduce that annoying CONFIG_X86_32 case (because it now does it
in obviously the same place as fs/gs).

So the code is cleaner, and closer to what we used to do.

Stas, can you test this one too? I, like Luto, don't actually have a
dosemu test-case.

                      Linus
 arch/x86/include/asm/sigcontext.h      | 2 +-
 arch/x86/include/uapi/asm/sigcontext.h | 3 +--
 arch/x86/kernel/signal.c               | 4 ++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/sigcontext.h 
b/arch/x86/include/asm/sigcontext.h
index 6fe6b182c998..2cefce9b52bd 100644
--- a/arch/x86/include/asm/sigcontext.h
+++ b/arch/x86/include/asm/sigcontext.h
@@ -59,7 +59,7 @@ struct sigcontext {
        unsigned short cs;
        unsigned short __pad2;  /* Was called gs, but was always zero. */
        unsigned short __pad1;  /* Was called fs, but was always zero. */
-       unsigned short ss;
+       unsigned short __pad0;
        unsigned long err;
        unsigned long trapno;
        unsigned long oldmask;
diff --git a/arch/x86/include/uapi/asm/sigcontext.h 
b/arch/x86/include/uapi/asm/sigcontext.h
index 0e8a973de9ee..d99bbc2d4b0b 100644
--- a/arch/x86/include/uapi/asm/sigcontext.h
+++ b/arch/x86/include/uapi/asm/sigcontext.h
@@ -193,8 +193,7 @@ struct sigcontext {
         */
        __u16 __pad2;           /* Was gs. */
        __u16 __pad1;           /* Was fs. */
-
-       __u16 ss;
+       __u16 __pad0;           /* Not ss. */
        __u64 err;
        __u64 trapno;
        __u64 oldmask;
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 206996c1669d..e955f0cd9b9d 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -77,6 +77,7 @@ int restore_sigcontext(struct pt_regs *regs, struct 
sigcontext __user *sc)
                COPY_SEG(fs);
                COPY_SEG(es);
                COPY_SEG(ds);
+               COPY_SEG_CPL3(ss);
 #endif /* CONFIG_X86_32 */
 
                COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
@@ -94,7 +95,6 @@ int restore_sigcontext(struct pt_regs *regs, struct 
sigcontext __user *sc)
 #endif /* CONFIG_X86_64 */
 
                COPY_SEG_CPL3(cs);
-               COPY_SEG_CPL3(ss);
 
                get_user_ex(tmpflags, &sc->flags);
                regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & 
FIX_EFLAGS);
@@ -156,7 +156,7 @@ int setup_sigcontext(struct sigcontext __user *sc, void 
__user *fpstate,
                put_user_ex(regs->cs, &sc->cs);
                put_user_ex(0, &sc->__pad2);
                put_user_ex(0, &sc->__pad1);
-               put_user_ex(regs->ss, &sc->ss);
+               put_user_ex(0, &sc->__pad0);
 #endif /* CONFIG_X86_32 */
 
                put_user_ex(fpstate, &sc->fpstate);

Reply via email to