Skip to contentSkip to conversation

x86: make sure IDT is page aligned

PATCH Superseded Kees Cook 4 participants 6 messages Jul 12, 2013 – Jul 15, 2013 x86

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

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

Since the IDT is referenced from a fixmap, make sure it is page aligned. Merge with 32-bit one, since it was already aligned to deal with F00F bug. This avoids the risk of it ever being moved in the bss and having the mapping be offset, resulting in calling incorrect handlers.

---
v3:
- merge 32-bit and 64-bit idt_table definition
v2:
- 32-bit was already aligned

---
 arch/x86/kernel/head_64.S |    4 ----
 arch/x86/kernel/traps.c   |    7 ++-----
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/x86/kernel/head_64.S +0 -4
index 5e4d8a8..317b8cc 100644
@@ -514,10 +514,6 @@ ENTRY(phys_base)
 	
 	.section .bss, "aw", @nobits
 	.align L1_CACHE_BYTES
-ENTRY(idt_table)
-	.skip IDT_ENTRIES * 16
-
-	.align L1_CACHE_BYTES
 ENTRY(debug_idt_table)
 	.skip IDT_ENTRIES * 16
 
arch/x86/kernel/traps.c +2 -5
index b0865e8..0952614 100644
@@ -68,13 +68,10 @@
 #include <asm/setup.h>
 
 asmlinkage int system_call(void);
+#endif
 
-/*
- * The IDT has to be page-aligned to simplify the Pentium
- * F0 0F bug workaround.
- */
+/* The IDT has to be page-aligned to keep it aligned with its fixmap. */
 gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
-#endif
 
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw

[tip:x86/urgent] x86: Make sure IDT is page aligned

x86: Make sure IDT is page aligned
Commit-ID:  c0b3450f101523a49823fa93d155f1d258e5ac6f
Gitweb:     http://git.kernel.org/tip/c0b3450f101523a49823fa93d155f1d258e5ac6f
Author:     Kees Cook <[email protected]>
AuthorDate: Fri, 12 Jul 2013 15:50:17 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 12 Jul 2013 16:14:08 -0700

x86: Make sure IDT is page aligned

Since the IDT is referenced from a fixmap, make sure it is page aligned. Merge with 32-bit one, since it was already aligned to deal with F00F bug. This avoids the risk of it ever being moved in the bss and having the mapping be offset, resulting in calling incorrect handlers.

[ hpa: It isn't clear that this is a manifest bug in any way, but
tagging for -stable because it shouldn't hurt and might avoid some very hard-to-debug breakages due to unrelated changes. ]

---
 arch/x86/kernel/head_64.S | 4 ----
 arch/x86/kernel/traps.c   | 7 ++-----
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/x86/kernel/head_64.S +0 -4
index 5e4d8a8..317b8cc 100644
@@ -514,10 +514,6 @@ ENTRY(phys_base)
 	
 	.section .bss, "aw", @nobits
 	.align L1_CACHE_BYTES
-ENTRY(idt_table)
-	.skip IDT_ENTRIES * 16
-
-	.align L1_CACHE_BYTES
 ENTRY(debug_idt_table)
 	.skip IDT_ENTRIES * 16
 
arch/x86/kernel/traps.c +2 -5
index b0865e8..0952614 100644
@@ -68,13 +68,10 @@
 #include <asm/setup.h>
 
 asmlinkage int system_call(void);
+#endif
 
-/*
- * The IDT has to be page-aligned to simplify the Pentium
- * F0 0F bug workaround.
- */
+/* The IDT has to be page-aligned to keep it aligned with its fixmap. */
 gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
-#endif
 
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
#2 lore raw

Re: [tip:x86/urgent] x86: Make sure IDT is page aligned

Quoted 53 lines · tip-bot for Kees Cook
Commit-ID:  c0b3450f101523a49823fa93d155f1d258e5ac6f
Gitweb:     http://git.kernel.org/tip/c0b3450f101523a49823fa93d155f1d258e5ac6f
Author:     Kees Cook <[email protected]>
AuthorDate: Fri, 12 Jul 2013 15:50:17 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 12 Jul 2013 16:14:08 -0700

x86: Make sure IDT is page aligned

Since the IDT is referenced from a fixmap, make sure it is page aligned. Merge with 32-bit one, since it was already aligned to deal with F00F bug. This avoids the risk of it ever being moved in the bss and having the mapping be offset, resulting in calling incorrect handlers.

[ hpa: It isn't clear that this is a manifest bug in any way, but
tagging for -stable because it shouldn't hurt and might avoid some very hard-to-debug breakages due to unrelated changes. ]

---
 arch/x86/kernel/head_64.S | 4 ----
 arch/x86/kernel/traps.c   | 7 ++-----
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/x86/kernel/head_64.S +0 -4
index 5e4d8a8..317b8cc 100644
@@ -514,10 +514,6 @@ ENTRY(phys_base)
 
        .section .bss, "aw", @nobits
        .align L1_CACHE_BYTES
-ENTRY(idt_table)
-       .skip IDT_ENTRIES * 16
-
-       .align L1_CACHE_BYTES
 ENTRY(debug_idt_table)
        .skip IDT_ENTRIES * 16
 
arch/x86/kernel/traps.c +1 -0
index b0865e8..0952614 100644
@@ -68,13 +68,10 @@
 #include <asm/setup.h>
 
 asmlinkage int system_call(void);
+#endif
 

arch/x86/kernel/traps.c line 77

Quoted 10 lines
arch/x86/kernel/traps.c +1 -5
-/*
- * The IDT has to be page-aligned to simplify the Pentium
- * F0 0F bug workaround.
- */
+/* The IDT has to be page-aligned to keep it aligned with its fixmap. */
 gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
-#endif
 
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);

arch/x86/kernel/traps.c:74:1: warning: braces around scalar initializer [enabled by default] arch/x86/kernel/traps.c:74:1: warning: (near initialization for ‘idt_table[0].offset_low’) [enabled by default] arch/x86/kernel/traps.c:74:1: warning: braces around scalar initializer [enabled by default] arch/x86/kernel/traps.c:74:1: warning: (near initialization for ‘idt_table[0].offset_low’) [enabled by default] arch/x86/kernel/traps.c:74:1: warning: excess elements in scalar initializer [enabled by default] arch/x86/kernel/traps.c:74:1: warning: (near initialization for ‘idt_table[0].offset_low’) [enabled by default]

#3 lore raw

Re: [tip:x86/urgent] x86: Make sure IDT is page aligned

In reply to tip-bot for Kees Cook
Quoted 7 lines · tip-bot for Kees Cook
Commit-ID:  c0b3450f101523a49823fa93d155f1d258e5ac6f
Gitweb:     http://git.kernel.org/tip/c0b3450f101523a49823fa93d155f1d258e5ac6f
Author:     Kees Cook <[email protected]>
AuthorDate: Fri, 12 Jul 2013 15:50:17 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 12 Jul 2013 16:14:08 -0700
Quoted 6 lines

x86: Make sure IDT is page aligned

Since the IDT is referenced from a fixmap, make sure it is page aligned. Merge with 32-bit one, since it was already aligned to deal with F00F bug. This avoids the risk of it ever being moved in the bss and having the mapping be offset, resulting in calling incorrect handlers.

why can put idt_table not be in .bss?

Quoted 37 lines

[ hpa: It isn't clear that this is a manifest bug in any way, but
tagging for -stable because it shouldn't hurt and might avoid some very hard-to-debug breakages due to unrelated changes. ]

---
 arch/x86/kernel/head_64.S | 4 ----
 arch/x86/kernel/traps.c   | 7 ++-----
 2 files changed, 2 insertions(+), 9 deletions(-)
arch/x86/kernel/head_64.S +0 -4
index 5e4d8a8..317b8cc 100644
@@ -514,10 +514,6 @@ ENTRY(phys_base)
 
        .section .bss, "aw", @nobits
        .align L1_CACHE_BYTES
-ENTRY(idt_table)
-       .skip IDT_ENTRIES * 16
-
-       .align L1_CACHE_BYTES
 ENTRY(debug_idt_table)
        .skip IDT_ENTRIES * 16
 
arch/x86/kernel/traps.c +0 -0
index b0865e8..0952614 100644
@@ -68,13 +68,10 @@
 #include <asm/setup.h>
 

arch/x86/kernel/traps.c line 77

Quoted 10 lines
arch/x86/kernel/traps.c +2 -5
 asmlinkage int system_call(void);
+#endif
 
-/*
- * The IDT has to be page-aligned to simplify the Pentium
- * F0 0F bug workaround.
- */
+/* The IDT has to be page-aligned to keep it aligned with its fixmap. */
 gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
-#endif

can we use put all idt_table related in to __bss.aligned section ...?

like
gate_desc idt_table[NR_VECTORS] __page_aligned_bss;

Quoted 8 lines
arch/x86/kernel/traps.c +0 -1
 DECLARE_BITMAP(used_vectors, NR_VECTORS);
 EXPORT_SYMBOL_GPL(used_vectors);
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw

Re: [tip:x86/urgent] x86: Make sure IDT is page aligned

Quoted 6 lines · Yinghai Lu

can we use put all idt_table related in to __bss.aligned section ...?

like
gate_desc idt_table[NR_VECTORS] __page_aligned_bss;

I think this is the best solution all around... it not only solves the initializer problem but also reduces the size of data.

A long, long time ago in a galaxy far, far away I believe the IDT got set up before we cleared bss, but that is no longer the case as we now clear bss very, very early (on 32 bits before paging is even enabled.)

Still, it would seem that the minimal solution, if we need something for 3.11/stable, is to simply fix the alignment statement in head_64.S (optionally move to .bss..page_aligned) and then do the proper cleanup for 3.12. If you could prepare a patch for the former (please include the descriptions we discussed over IRC) and a patchset for the latter it would be good.

Thanks,

-hpa

author
#5 lore raw

Re: [tip:x86/urgent] x86: Make sure IDT is page aligned

Hi,

Quoted 15 lines · H. Peter Anvin
Quoted 6 lines · Yinghai Lu

can we use put all idt_table related in to __bss.aligned section ...?

like
gate_desc idt_table[NR_VECTORS] __page_aligned_bss;

I think this is the best solution all around... it not only solves the initializer problem but also reduces the size of data.

A long, long time ago in a galaxy far, far away I believe the IDT got set up before we cleared bss, but that is no longer the case as we now clear bss very, very early (on 32 bits before paging is even enabled.)

Quoted 6 lines

Still, it would seem that the minimal solution, if we need something for 3.11/stable, is to simply fix the alignment statement in head_64.S (optionally move to .bss..page_aligned) and then do the proper cleanup for 3.12. If you could prepare a patch for the former (please include the descriptions we discussed over IRC) and a patchset for the latter it would be good.

Sorry for the trouble I caused on this. I've reorganized how I do test builds now, which should hopefully cut down on my stupid mistakes.

I'll send two patches, one for 3.11/stable with the absolute minimal change to alignment, and another for 3.12 that moves all the IDT variables into common places using __page_aligned_bss as Yinghai Lu recommended.

Thanks,

-Kees

--
Kees Cook
Chrome OS Security