]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
x86_64, traps: Rework bad_iret
authorAndy Lutomirski <luto@amacapital.net>
Sun, 23 Nov 2014 02:00:33 +0000 (18:00 -0800)
committerWilly Tarreau <w@1wt.eu>
Sat, 13 Dec 2014 14:16:12 +0000 (15:16 +0100)
commit1f4495612dce156f9ca8a33d8b9de134f9329be2
treedd2812926e7f86deb8bd4954259d0edaba55342f
parent70443551ff6483f8d7a6f3457504e12c03270099
x86_64, traps: Rework bad_iret

It's possible for iretq to userspace to fail.  This can happen because
of a bad CS, SS, or RIP.

Historically, we've handled it by fixing up an exception from iretq to
land at bad_iret, which pretends that the failed iret frame was really
the hardware part of #GP(0) from userspace.  To make this work, there's
an extra fixup to fudge the gs base into a usable state.

This is suboptimal because it loses the original exception.  It's also
buggy because there's no guarantee that we were on the kernel stack to
begin with.  For example, if the failing iret happened on return from an
NMI, then we'll end up executing general_protection on the NMI stack.
This is bad for several reasons, the most immediate of which is that
general_protection, as a non-paranoid idtentry, will try to deliver
signals and/or schedule from the wrong stack.

This patch throws out bad_iret entirely.  As a replacement, it augments
the existing swapgs fudge into a full-blown iret fixup, mostly written
in C.  It's should be clearer and more correct.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit b645af2d5905c4e32399005b867987919cbfc3ae)
[wt: notes for backport to 2.6.32:
  - _ASM_EXTABLE was open-coded.
  - removed unneeded CFI_ENDPROC
  - removed __visible (introduced in 2.6.37-rc1, not needed here)
/wt]
Signed-off-by: Willy Tarreau <w@1wt.eu>
arch/x86/kernel/entry_64.S
arch/x86/kernel/traps.c