Skip to content

Commit 8a50e51

Browse files
author
H. Peter Anvin
committed
x86-32: Use symbolic constants, safer CPUID when enabling EFER.NX
Use symbolic constants rather than hard-coded values when setting EFER.NX in head_32.S, and do a more rigorous test for the validity of the response when probing for the extended CPUID range. Signed-off-by: H. Peter Anvin <[email protected]> LKML-Reference: <[email protected]> Acked-by: Kees Cook <[email protected]>
1 parent 196cf0d commit 8a50e51

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

arch/x86/kernel/head_32.S

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <asm/asm-offsets.h>
1919
#include <asm/setup.h>
2020
#include <asm/processor-flags.h>
21+
#include <asm/msr-index.h>
22+
#include <asm/cpufeature.h>
2123
#include <asm/percpu.h>
2224

2325
/* Physical address */
@@ -297,25 +299,27 @@ ENTRY(startup_32_smp)
297299
orl %edx,%eax
298300
movl %eax,%cr4
299301

300-
btl $5, %eax # check if PAE is enabled
301-
jnc 6f
302+
testb $X86_CR4_PAE, %al # check if PAE is enabled
303+
jz 6f
302304

303305
/* Check if extended functions are implemented */
304306
movl $0x80000000, %eax
305307
cpuid
306-
cmpl $0x80000000, %eax
307-
jbe 6f
308+
/* Value must be in the range 0x80000001 to 0x8000ffff */
309+
subl $0x80000001, %eax
310+
cmpl $(0x8000ffff-0x80000001), %eax
311+
ja 6f
308312
mov $0x80000001, %eax
309313
cpuid
310314
/* Execute Disable bit supported? */
311-
btl $20, %edx
315+
btl $(X86_FEATURE_NX & 31), %edx
312316
jnc 6f
313317

314318
/* Setup EFER (Extended Feature Enable Register) */
315-
movl $0xc0000080, %ecx
319+
movl $MSR_EFER, %ecx
316320
rdmsr
317321

318-
btsl $11, %eax
322+
btsl $_EFER_NX, %eax
319323
/* Make changes effective */
320324
wrmsr
321325

0 commit comments

Comments
 (0)