linux-kernel-test/arch/x86
Alexander van Heukelum dc4c2a0aed i386: fix/simplify espfix stack switching, move it into assembly
The espfix code triggers if we have a protected mode userspace
application with a 16-bit stack. On returning to userspace, with iret,
the CPU doesn't restore the high word of the stack pointer. This is an
"official" bug, and the work-around used in the kernel is to temporarily
switch to a 32-bit stack segment/pointer pair where the high word of the
pointer is equal to the high word of the userspace stackpointer.

The current implementation uses THREAD_SIZE to determine the cut-off,
but there is no good reason not to use the more natural 64kb... However,
implementing this by simply substituting THREAD_SIZE with 65536 in
patch_espfix_desc crashed the test application. patch_espfix_desc tries
to do what is described above, but gets it subtly wrong if the userspace
stack pointer is just below a multiple of THREAD_SIZE: an overflow
occurs to bit 13... With a bit of luck, when the kernelspace
stackpointer is just below a 64kb-boundary, the overflow then ripples
trough to bit 16 and userspace will see its stack pointer changed by
65536.

This patch moves all espfix code into entry_32.S. Selecting a 16-bit
cut-off simplifies the code. The game with changing the limit dynamically
is removed too. It complicates matters and I see no value in it. Changing
only the top 16-bit word of ESP is one instruction and it also implies
that only two bytes of the ESPFIX GDT entry need to be changed and this
can be implemented in just a handful simple to understand instructions.
As a side effect, the operation to compute the original ESP from the
ESPFIX ESP and the GDT entry simplifies a bit too, and the remaining
three instructions have been expanded inline in entry_32.S.

impact: can now reliably run userspace with ESP=xxxxfffc on 16-bit
stack segment

Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-17 21:35:09 -07:00
..
boot x86, boot: use .code16gcc instead of .code16 2009-06-16 17:47:32 -07:00
configs Merge branch 'x86-kbuild-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-10 15:30:41 -07:00
crypto crypto: aes-ni - Add support for more modes 2009-06-02 14:04:16 +10:00
ia32 Merge branch 'core/signal' into perfcounters/core 2009-04-30 21:16:49 +02:00
include/asm x86: msr.h linux/types.h is only required for __KERNEL__ 2009-06-17 18:56:01 +02:00
kernel i386: fix/simplify espfix stack switching, move it into assembly 2009-06-17 21:35:09 -07:00
kvm KVM: Add VT-x machine check support 2009-06-10 12:27:08 +03:00
lguest lguest: PAE support 2009-06-12 22:27:08 +09:30
lib x86: MSR: add methods for writing of an MSR on several CPUs 2009-06-10 12:18:43 +02:00
math-emu
mm Merge branch 'linus' into x86/urgent 2009-06-17 08:59:10 +02:00
oprofile Merge branch 'linus' into perfcounters/core 2009-06-11 17:55:42 +02:00
pci Merge branch 'irq-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-10 15:25:41 -07:00
power x86: unify power/cpu_(32|64).c 2009-06-12 21:32:31 +02:00
vdso Merge branch 'linus' into perfcounters/core 2009-06-11 17:55:42 +02:00
video
xen Merge branch 'x86-xen-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-10 16:16:27 -07:00
Kbuild x86: standardize Kbuild rules 2009-04-16 18:09:02 +02:00
Kconfig Merge branch 'linus' into x86/mce3 2009-06-11 23:31:52 +02:00
Kconfig.cpu Revert "x86, bts: reenable ptrace branch trace support" 2009-06-11 00:32:00 +02:00
Kconfig.debug Merge branch 'tracing-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-10 19:53:40 -07:00
Makefile Merge branch 'x86-kbuild-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2009-06-10 15:30:41 -07:00
Makefile_32.cpu