Skip to contentSkip to conversation

x86: make sure IDT is page aligned

PATCH Superseded Kees Cook 2 participants 4 messages Jul 12, 2013 x86

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 x86: make sure IDT is page aligned

Since the IDT is referenced from a fixmap, make sure it is page aligned. This avoids the risk of it ever being moved in the bss and having the fixmap fail.

---
 arch/x86/kernel/head_32.S |    2 +-
 arch/x86/kernel/head_64.S |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +1 -1
index e65ddc6..3526dd1 100644
@@ -734,7 +734,7 @@ boot_gdt_descr:
 	.word __BOOT_DS+7
 	.long boot_gdt - __PAGE_OFFSET
 
-	.word 0				# 32-bit align idt_desc.address
+	.word PAGE_SIZE			# page align idt_desc.address
 idt_descr:
 	.word IDT_ENTRIES*8-1		# idt contains 256 entries
 	.long idt_table
arch/x86/kernel/head_64.S +1 -1
index 5e4d8a8..77e6d3e 100644
@@ -513,7 +513,7 @@ ENTRY(phys_base)
 #include "../../x86/xen/xen-head.S"
 	
 	.section .bss, "aw", @nobits
-	.align L1_CACHE_BYTES
+	.align PAGE_SIZE
 ENTRY(idt_table)
 	.skip IDT_ENTRIES * 16
 
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 31 lines · Kees Cook

Since the IDT is referenced from a fixmap, make sure it is page aligned. This avoids the risk of it ever being moved in the bss and having the fixmap fail.

---
 arch/x86/kernel/head_32.S |    2 +-
 arch/x86/kernel/head_64.S |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +1 -1
index e65ddc6..3526dd1 100644
@@ -734,7 +734,7 @@ boot_gdt_descr:
 	.word __BOOT_DS+7
 	.long boot_gdt - __PAGE_OFFSET
 
-	.word 0				# 32-bit align idt_desc.address
+	.word PAGE_SIZE			# page align idt_desc.address
 idt_descr:
 	.word IDT_ENTRIES*8-1		# idt contains 256 entries
 	.long idt_table
arch/x86/kernel/head_64.S +0 -0
index 5e4d8a8..77e6d3e 100644

arch/x86/kernel/head_64.S ENTRY(phys_base) · line 519

Quoted 8 lines
arch/x86/kernel/head_64.S +1 -1
@@ -513,7 +513,7 @@ ENTRY(phys_base)
 #include "../../x86/xen/xen-head.S"
 
 	.section .bss, "aw", @nobits
-	.align L1_CACHE_BYTES
+	.align PAGE_SIZE
 ENTRY(idt_table)
 	.skip IDT_ENTRIES * 16
 

You are aligning the IDT *descriptor*, not the IDT itself?

-hpa

#2 lore raw
In reply to Kees Cook

arch/x86/kernel/head_32.S boot_gdt_descr: · line 737

Quoted 4 lines · Kees Cook
arch/x86/kernel/head_32.S +1 -1
-	.word 0				# 32-bit align idt_desc.address
+	.word PAGE_SIZE			# page align idt_desc.address

... and this is totally confused. This didn't change alignment one iota, it only put the value 4096 into the padding.

-hpa

author
#3 lore raw

That was the busted patch. See the v2 I sent. Only 64-bit needs alignment. And after looking more at it, the idt in head_64.S could be entirely dropped in favor of using the one in arch/x86/kernel/traps.c (after moving it out of the #ifdef.

-Kees

Quoted 11 lines · H. Peter Anvin

arch/x86/kernel/head_32.S boot_gdt_descr: · line 737

Quoted 4 lines · Kees Cook
arch/x86/kernel/head_32.S +1 -1
-     .word 0                         # 32-bit align idt_desc.address
+     .word PAGE_SIZE                 # page align idt_desc.address

... and this is totally confused. This didn't change alignment one iota, it only put the value 4096 into the padding.

-hpa

Signature · 2 lines
Kees Cook
Chrome OS Security