Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert x86 sigcontext cleanups

This reverts commits 9a036b93a344 ("x86/signal/64: Remove 'fs' and 'gs'
from sigcontext") and c6f2062935c8 ("x86/signal/64: Fix SS handling for
signals delivered to 64-bit programs").

They were cleanups, but they break dosemu by changing the signal return
behavior (and removing 'fs' and 'gs' from the sigcontext struct - while
not actually changing any behavior - causes build problems).

Reported-and-tested-by: Stas Sergeev <stsp@list.ru>
Acked-by: Andy Lutomirski <luto@amacapital.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+17 -36
+3 -3
arch/x86/include/asm/sigcontext.h
··· 57 57 unsigned long ip; 58 58 unsigned long flags; 59 59 unsigned short cs; 60 - unsigned short __pad2; /* Was called gs, but was always zero. */ 61 - unsigned short __pad1; /* Was called fs, but was always zero. */ 62 - unsigned short ss; 60 + unsigned short gs; 61 + unsigned short fs; 62 + unsigned short __pad0; 63 63 unsigned long err; 64 64 unsigned long trapno; 65 65 unsigned long oldmask;
+3 -18
arch/x86/include/uapi/asm/sigcontext.h
··· 177 177 __u64 rip; 178 178 __u64 eflags; /* RFLAGS */ 179 179 __u16 cs; 180 - 181 - /* 182 - * Prior to 2.5.64 ("[PATCH] x86-64 updates for 2.5.64-bk3"), 183 - * Linux saved and restored fs and gs in these slots. This 184 - * was counterproductive, as fsbase and gsbase were never 185 - * saved, so arch_prctl was presumably unreliable. 186 - * 187 - * If these slots are ever needed for any other purpose, there 188 - * is some risk that very old 64-bit binaries could get 189 - * confused. I doubt that many such binaries still work, 190 - * though, since the same patch in 2.5.64 also removed the 191 - * 64-bit set_thread_area syscall, so it appears that there is 192 - * no TLS API that works in both pre- and post-2.5.64 kernels. 193 - */ 194 - __u16 __pad2; /* Was gs. */ 195 - __u16 __pad1; /* Was fs. */ 196 - 197 - __u16 ss; 180 + __u16 gs; 181 + __u16 fs; 182 + __u16 __pad0; 198 183 __u64 err; 199 184 __u64 trapno; 200 185 __u64 oldmask;
+11 -15
arch/x86/kernel/signal.c
··· 93 93 COPY(r15); 94 94 #endif /* CONFIG_X86_64 */ 95 95 96 + #ifdef CONFIG_X86_32 96 97 COPY_SEG_CPL3(cs); 97 98 COPY_SEG_CPL3(ss); 99 + #else /* !CONFIG_X86_32 */ 100 + /* Kernel saves and restores only the CS segment register on signals, 101 + * which is the bare minimum needed to allow mixed 32/64-bit code. 102 + * App's signal handler can save/restore other segments if needed. */ 103 + COPY_SEG_CPL3(cs); 104 + #endif /* CONFIG_X86_32 */ 98 105 99 106 get_user_ex(tmpflags, &sc->flags); 100 107 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); ··· 161 154 #else /* !CONFIG_X86_32 */ 162 155 put_user_ex(regs->flags, &sc->flags); 163 156 put_user_ex(regs->cs, &sc->cs); 164 - put_user_ex(0, &sc->__pad2); 165 - put_user_ex(0, &sc->__pad1); 166 - put_user_ex(regs->ss, &sc->ss); 157 + put_user_ex(0, &sc->gs); 158 + put_user_ex(0, &sc->fs); 167 159 #endif /* CONFIG_X86_32 */ 168 160 169 161 put_user_ex(fpstate, &sc->fpstate); ··· 457 451 458 452 regs->sp = (unsigned long)frame; 459 453 460 - /* 461 - * Set up the CS and SS registers to run signal handlers in 462 - * 64-bit mode, even if the handler happens to be interrupting 463 - * 32-bit or 16-bit code. 464 - * 465 - * SS is subtle. In 64-bit mode, we don't need any particular 466 - * SS descriptor, but we do need SS to be valid. It's possible 467 - * that the old SS is entirely bogus -- this can happen if the 468 - * signal we're trying to deliver is #GP or #SS caused by a bad 469 - * SS value. 470 - */ 454 + /* Set up the CS register to run signal handlers in 64-bit mode, 455 + even if the handler happens to be interrupting 32-bit code. */ 471 456 regs->cs = __USER_CS; 472 - regs->ss = __USER_DS; 473 457 474 458 return 0; 475 459 }