Skip to contentSkip to conversation

x86: add missing verify_cpu to 32bit wakeup

PATCH In review Kees Cook 3 participants 8 messages Jul 1, 2011 – Jul 3, 2011

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

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
index ead21b6..19698da 100644
@@ -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
index b9242ba..50c5edd 100644
@@ -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
#1 lore raw
Quoted 9 lines · Kees Cook

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.

For S3, we should save/restore MISC_ENABLE instead... in fact, we already save it, we just restore it too late.

-hpa

author
#2 lore raw

Hi,

Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Kees Cook

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.

Quoted 2 lines

For S3, we should save/restore MISC_ENABLE instead... 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
#3 lore raw
Quoted 11 lines · Kees Cook
Quoted 3 lines

For S3, we should save/restore MISC_ENABLE instead... 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?

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

#4 lore raw
In reply to Kees Cook

Hi!

Quoted 10 lines

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.

Quoted 2 lines

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
author
#5 lore raw

Hi Pavel,

Quoted 10 lines · Pavel Machek
Quoted 10 lines

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.

Quoted 4 lines
Quoted 2 lines

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
#6 lore raw
Quoted 5 lines · Kees Cook

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.

Yes, but let's do the early restore... it's both more complete and simpler.

-hpa

#7 lore raw
In reply to Kees Cook
Quoted 13 lines · Kees Cook

Hi Pavel,

Quoted 10 lines · Pavel Machek
Quoted 10 lines

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.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

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.

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