public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees.cook@canonical.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Tim Abbott <tabbott@ksplice.com>, Sam Ravnborg <sam@ravnborg.org>,
	Alexander van Heukelum <heukelum@fastmail.fm>,
	Jiri Kosina <jkosina@suse.cz>,
	Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH] x86: clear XD_DISABLED flag on Intel to regain NX
Date: Thu, 17 Jun 2010 15:13:18 -0700	[thread overview]
Message-ID: <20100617221318.GC24749@outflux.net> (raw)

This will clear the MSR_IA32_MISC_ENABLE_XD_DISABLE bit so that NX cannot
be inappropriately controlled by the BIOS on Intel CPUs.  If NX actually
needs to be disabled, "noexec=off" can be used.

Signed-off-by: Kees Cook <kees.cook@canonical.com>
---
 arch/x86/kernel/head_32.S |   19 +++++++++++++++++++
 arch/x86/kernel/head_64.S |   18 ++++++++++++++++++
 arch/x86/mm/setup_nx.c    |    2 +-
 3 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 37c3d4b..111e434 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -309,6 +309,25 @@ ENTRY(startup_32_smp)
 	subl $0x80000001, %eax
 	cmpl $(0x8000ffff-0x80000001), %eax
 	ja 6f
+
+	/* Is this "GenuineIntel"? */
+	movl $0x0, %eax
+	cpuid
+	cmpl $0x756e6547, %ebx
+	jnz 5f
+	cmpl $0x49656e69, %edx
+	jnz 5f
+	cmpl $0x6c65746e, %ecx
+	jnz 5f
+
+	/* Clear MSR_IA32_MISC_ENABLE_XD_DISABLE if set */
+	movl $MSR_IA32_MISC_ENABLE, %ecx
+	rdmsr
+	btrl $2, %edx
+	jnc 5f
+	wrmsr
+
+5:
 	mov $0x80000001, %eax
 	cpuid
 	/* Execute Disable bit supported? */
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 3d1e6f1..e918e40 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -175,6 +175,24 @@ ENTRY(secondary_startup_64)
 	jmp	*%rax
 1:
 
+	/* Is this "GenuineIntel"? */
+	movl $0x0, %eax
+	cpuid
+	cmpl $0x756e6547, %ebx
+	jnz 5f
+	cmpl $0x49656e69, %edx
+	jnz 5f
+	cmpl $0x6c65746e, %ecx
+	jnz 5f
+
+	/* Clear MSR_IA32_MISC_ENABLE_XD_DISABLE if set */
+	movl $MSR_IA32_MISC_ENABLE, %ecx
+	rdmsr
+	btrl $2, %edx
+	jnc 5f
+	wrmsr
+
+5:
 	/* Check if nx is implemented */
 	movl	$0x80000001, %eax
 	cpuid
diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index a3250aa..410531d 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -41,7 +41,7 @@ void __init x86_report_nx(void)
 {
 	if (!cpu_has_nx) {
 		printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
-		       "missing in CPU or disabled in BIOS!\n");
+		       "missing in CPU!\n");
 	} else {
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
 		if (disable_nx) {
-- 
1.7.1

-- 
Kees Cook
Ubuntu Security Team

             reply	other threads:[~2010-06-17 22:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-17 22:13 Kees Cook [this message]
2010-06-17 22:27 ` [PATCH] x86: clear XD_DISABLED flag on Intel to regain NX H. Peter Anvin
2010-06-18  2:07   ` Yuhong Bao
2010-06-18  3:03     ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100617221318.GC24749@outflux.net \
    --to=kees.cook@canonical.com \
    --cc=heukelum@fastmail.fm \
    --cc=hpa@zytor.com \
    --cc=jeremy.fitzhardinge@citrix.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=tabbott@ksplice.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox