x86: add missing verify_cpu to 32bit wakeup
PATCH 1/1 x86: add missing verify_cpu to 32bit wakeup
Some BIOSes will reset the Intel XD_DISABLE MSR bit when resuming from S3, which can interact poorly with ebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hit verify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to call verify_cpu() to handle this situation.
--- arch/x86/kernel/acpi/realmode/wakeup.S | 4 ++++ arch/x86/kernel/verify_cpu.S | 1 + 2 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/kernel/acpi/realmode/wakeup.S +4 -0
@@ -94,6 +94,9 @@ wakeup_code: /* Do any other stuff... */ #ifndef CONFIG_64BIT + /* Recheck NX bit overrides (64bit path does this in trampoline) */ + call verify_cpu + /* This could also be done in C code... */ movl pmode_cr3, %eax movl %eax, %cr3
@@ -117,6 +120,7 @@ wakeup_code: movl pmode_cr0, %eax movl %eax, %cr0 jmp pmode_return +# include "../../verify_cpu.S" #else pushw $0 pushw trampoline_segment
arch/x86/kernel/verify_cpu.S +1 -0
@@ -20,6 +20,7 @@ * arch/x86/boot/compressed/head_64.S: Boot cpu verification * arch/x86/kernel/trampoline_64.S: secondary processor verification * arch/x86/kernel/head_32.S: processor startup + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume * * verify_cpu, returns the status of longmode and SSE in register %eax. * 0: Success 1: Failure
Signature · 5 lines
1.7.4.1 -- Kees Cook Ubuntu Security Team
H. Peter Anvin
reviewerQuoted 9 lines · Kees Cook
Some BIOSes will reset the Intel
XD_DISABLEMSR bit when resuming from S3, which can interact poorly withebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hitverify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to callverify_cpu()to handle this situation.
For S3, we should save/restore MISC_ENABLE instead... in fact, we already save it, we just restore it too late.
-hpa
Hi,
Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Kees Cook
Some BIOSes will reset the Intel
XD_DISABLEMSR bit when resuming from S3, which can interact poorly withebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hitverify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to callverify_cpu()to handle this situation.
Quoted 2 lines
For S3, we should save/restore
MISC_ENABLEinstead... in fact, we already save it, we just restore it too late.
Given that MISC_ENABLE may not be available for a given CPU, it seems that it's basically the same detection code as in verify_cpu() already. Since this bit is the only part that is needed that early, I think the patch is good the way it is (especially since it balances the 64bit path which already calls this logic). I don't think doing the full early MISC_ENABLE save/restore this early is worth it. Thoughts?
-Kees
Signature · 2 lines
Kees Cook Ubuntu Security Team
H. Peter Anvin
reviewerQuoted 11 lines · Kees Cook
Quoted 3 lines
For S3, we should save/restore
MISC_ENABLEinstead... in fact, we already save it, we just restore it too late.Given that
MISC_ENABLEmay not be available for a given CPU, it seems that it's basically the same detection code as inverify_cpu()already. Since this bit is the only part that is needed that early, I think the patch is good the way it is (especially since it balances the 64bit path which already calls this logic). I don't think doing the full earlyMISC_ENABLEsave/restore this early is worth it. Thoughts?
We already save it, including if it exists, so we should just restore it early, and then we don't have to do it again.
-hpa
Hi!
Quoted 10 lines
Some BIOSes will reset the Intel
XD_DISABLEMSR bit when resuming from S3, which can interact poorly withebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hitverify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to callverify_cpu()to handle this situation.
Quoted 2 lines
Signed-off-by Kees Cook <[email protected]>
Looks ok to me, but I'm not sure it is stable material.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
Quoted 10 lines · Pavel Machek
Quoted 10 lines
Some BIOSes will reset the Intel
XD_DISABLEMSR bit when resuming from S3, which can interact poorly withebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hitverify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to callverify_cpu()to handle this situation.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Kees Cook <[email protected]>Looks ok to me, but I'm not sure it is stable material.
Well, I figured anything that shipped with ebba638ae723d8a8fc2f7abce5ec18b688b791d7 should get it, since it is a regression in the 32bit PAE with BIOS-disabled NX corner-case.
-Kees
Signature · 2 lines
Kees Cook Ubuntu Security Team
H. Peter Anvin
reviewerQuoted 5 lines · Kees Cook
Well, I figured anything that shipped with
ebba638ae723d8a8fc2f7abce5ec18b688b791d7should get it, since it is a regression in the 32bit PAE with BIOS-disabled NX corner-case.
Yes, but let's do the early restore... it's both more complete and simpler.
-hpa
Quoted 13 lines · Kees Cook
Hi Pavel,
Quoted 10 lines · Pavel Machek
Quoted 10 lines
Some BIOSes will reset the Intel
XD_DISABLEMSR bit when resuming from S3, which can interact poorly withebba638ae723d8a8fc2f7abce5ec18b688b791d7. In 32bit PAE mode, this can lead to a fault when EFER is restored by the kernel wakeup routines, due to it setting the NX bit for a CPU that (thanks to the BIOS reset) now incorrectly thinks it lacks the NX feature. 64bit wakeup already handled this through its common call path that would hitverify_cpu(). 32bit has a separate path for restoring CPU state on S3 wakeup, and needed to callverify_cpu()to handle this situation.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Kees Cook <[email protected]>Looks ok to me, but I'm not sure it is stable material.
Well, I figured anything that shipped with
ebba638ae723d8a8fc2f7abce5ec18b688b791d7should get it, since it is a regression in the 32bit PAE with BIOS-disabled NX corner-case.
Aha, if it is an regression it makes sense for stable..
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html