Skip to contentSkip to conversation

x86, traps: maps all IDTs to fixmap area.

PATCH In review Wang Nan 3 participants 6 messages Feb 26, 2015 – Feb 27, 2015

Subsystems (2)
lore
Share & tools
lore

Wang Nan

author
#0 lore raw

PATCH 1/1 x86, traps: maps all IDTs to fixmap area.

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

---
 arch/x86/include/asm/fixmap.h |  6 ++++++
 arch/x86/kernel/tracepoint.c  |  2 +-
 arch/x86/kernel/traps.c       | 13 +++++++++++--
 arch/x86/xen/mmu.c            |  6 ++++++
 4 files changed, 24 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +6 -0
index f80d700..79550f4 100644
@@ -90,6 +90,12 @@ enum fixed_addresses {
 	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
 #endif
 	FIX_RO_IDT,	/* Virtual mapping for read-only IDT */
+#ifdef CONFIG_X86_64
+	FIX_RO_DEBUG_IDT,	/* Virtual mapping for read-only debug_idt_table */
+#endif
+#ifdef CONFIG_TRACING
+	FIX_RO_TRACE_IDT,	/* Virtual mapping for read-only trace_idt_table */
+#endif
 #ifdef CONFIG_X86_32
 	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
 	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
arch/x86/kernel/tracepoint.c +1 -1
index 1c113db..296e130 100644
@@ -12,7 +12,7 @@ atomic_t trace_idt_ctr = ATOMIC_INIT(0);
 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
 				(unsigned long) trace_idt_table };
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
 
 static int trace_irq_vector_refcount;
arch/x86/kernel/traps.c +11 -2
index cf7898e..6d88c37 100644
@@ -67,7 +67,7 @@
 #include <asm/pgalloc.h>
 #include <asm/proto.h>
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
 #else
 #include <asm/processor-flags.h>
@@ -998,9 +998,18 @@ void __init trap_init(void)
 	 * Set the IDT descriptor to a fixed read-only location, so that the
 	 * "sidt" instruction will not leak the location of the kernel, and
 	 * to defend the IDT against arbitrary memory write vulnerabilities.
-	 * It will be reloaded in cpu_init() */
+	 * It will be reloaded in cpu_init()
+	 */
 	__set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
 	idt_descr.address = fix_to_virt(FIX_RO_IDT);
+#ifdef CONFIG_X86_64
+	__set_fixmap(FIX_RO_DEBUG_IDT, __pa_symbol(debug_idt_table), PAGE_KERNEL_RO);
+	debug_idt_descr.address = fix_to_virt(FIX_RO_DEBUG_IDT);
+#endif
+#ifdef CONFIG_TRACING
+	__set_fixmap(FIX_RO_TRACE_IDT, __pa_symbol(trace_idt_table), PAGE_KERNEL_RO);
+	trace_idt_descr.address = fix_to_virt(FIX_RO_TRACE_IDT);
+#endif
 
 	/*
 	 * Should be a barrier for any external CPU state:
arch/x86/xen/mmu.c +6 -0
index adca9e2..1fd4a4c 100644
@@ -1984,6 +1984,12 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
 	switch (idx) {
 	case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
 	case FIX_RO_IDT:
+#ifdef CONFIG_X86_64
+	case FIX_RO_DEBUG_IDT:
+#endif
+#ifdef CONFIG_TRACING
+	case FIX_RO_TRACE_IDT:
+#endif
 #ifdef CONFIG_X86_32
 	case FIX_WP_TEST:
 # ifdef CONFIG_HIGHMEM
Signature · 1 line
1.8.4
#1 lore raw
Quoted 11 lines · Wang Nan

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

It shouldn't matter, since we should never enter userspace with these IDTs loaded.

--Andy

[patch kept below for Kees' benefit]

Quoted 91 lines
---
 arch/x86/include/asm/fixmap.h |  6 ++++++
 arch/x86/kernel/tracepoint.c  |  2 +-
 arch/x86/kernel/traps.c       | 13 +++++++++++--
 arch/x86/xen/mmu.c            |  6 ++++++
 4 files changed, 24 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +6 -0
index f80d700..79550f4 100644
@@ -90,6 +90,12 @@ enum fixed_addresses {
        FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
 #endif
        FIX_RO_IDT,     /* Virtual mapping for read-only IDT */
+#ifdef CONFIG_X86_64
+       FIX_RO_DEBUG_IDT,       /* Virtual mapping for read-only debug_idt_table */
+#endif
+#ifdef CONFIG_TRACING
+       FIX_RO_TRACE_IDT,       /* Virtual mapping for read-only trace_idt_table */
+#endif
 #ifdef CONFIG_X86_32
        FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
        FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
arch/x86/kernel/tracepoint.c +1 -1
index 1c113db..296e130 100644
@@ -12,7 +12,7 @@ atomic_t trace_idt_ctr = ATOMIC_INIT(0);
 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
                                (unsigned long) trace_idt_table };
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
 
 static int trace_irq_vector_refcount;
arch/x86/kernel/traps.c +11 -2
index cf7898e..6d88c37 100644
@@ -67,7 +67,7 @@
 #include <asm/pgalloc.h>
 #include <asm/proto.h>
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
 #else
 #include <asm/processor-flags.h>
@@ -998,9 +998,18 @@ void __init trap_init(void)
         * Set the IDT descriptor to a fixed read-only location, so that the
         * "sidt" instruction will not leak the location of the kernel, and
         * to defend the IDT against arbitrary memory write vulnerabilities.
-        * It will be reloaded in cpu_init() */
+        * It will be reloaded in cpu_init()
+        */
        __set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
        idt_descr.address = fix_to_virt(FIX_RO_IDT);
+#ifdef CONFIG_X86_64
+       __set_fixmap(FIX_RO_DEBUG_IDT, __pa_symbol(debug_idt_table), PAGE_KERNEL_RO);
+       debug_idt_descr.address = fix_to_virt(FIX_RO_DEBUG_IDT);
+#endif
+#ifdef CONFIG_TRACING
+       __set_fixmap(FIX_RO_TRACE_IDT, __pa_symbol(trace_idt_table), PAGE_KERNEL_RO);
+       trace_idt_descr.address = fix_to_virt(FIX_RO_TRACE_IDT);
+#endif
 
        /*
         * Should be a barrier for any external CPU state:
arch/x86/xen/mmu.c +6 -1
index adca9e2..1fd4a4c 100644
@@ -1984,6 +1984,12 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
        switch (idx) {
        case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
        case FIX_RO_IDT:
+#ifdef CONFIG_X86_64
+       case FIX_RO_DEBUG_IDT:
+#endif
+#ifdef CONFIG_TRACING
+       case FIX_RO_TRACE_IDT:
+#endif
 #ifdef CONFIG_X86_32
        case FIX_WP_TEST:
 # ifdef CONFIG_HIGHMEM
--

1.8.4

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#2 lore raw
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Wang Nan

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

Quoted 6 lines

It shouldn't matter, since we should never enter userspace with these IDTs loaded.

--Andy

[patch kept below for Kees' benefit]

Is there a reason to use fixmap entries for these IDTs? Or rather, is there a situation where these IDTs are ever visible to userspace? (The reason to use the fixmap is to hide their "true" location from userspace.)

-Kees

Quoted 98 lines
Quoted 90 lines

---
 arch/x86/include/asm/fixmap.h |  6 ++++++
 arch/x86/kernel/tracepoint.c  |  2 +-
 arch/x86/kernel/traps.c       | 13 +++++++++++--
 arch/x86/xen/mmu.c            |  6 ++++++
 4 files changed, 24 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +6 -0
index f80d700..79550f4 100644
@@ -90,6 +90,12 @@ enum fixed_addresses {
        FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
 #endif
        FIX_RO_IDT,     /* Virtual mapping for read-only IDT */
+#ifdef CONFIG_X86_64
+       FIX_RO_DEBUG_IDT,       /* Virtual mapping for read-only debug_idt_table */
+#endif
+#ifdef CONFIG_TRACING
+       FIX_RO_TRACE_IDT,       /* Virtual mapping for read-only trace_idt_table */
+#endif
 #ifdef CONFIG_X86_32
        FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
        FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
arch/x86/kernel/tracepoint.c +1 -1
index 1c113db..296e130 100644
@@ -12,7 +12,7 @@ atomic_t trace_idt_ctr = ATOMIC_INIT(0);
 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
                                (unsigned long) trace_idt_table };
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
 
 static int trace_irq_vector_refcount;
arch/x86/kernel/traps.c +11 -2
index cf7898e..6d88c37 100644
@@ -67,7 +67,7 @@
 #include <asm/pgalloc.h>
 #include <asm/proto.h>
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
 #else
 #include <asm/processor-flags.h>
@@ -998,9 +998,18 @@ void __init trap_init(void)
         * Set the IDT descriptor to a fixed read-only location, so that the
         * "sidt" instruction will not leak the location of the kernel, and
         * to defend the IDT against arbitrary memory write vulnerabilities.
-        * It will be reloaded in cpu_init() */
+        * It will be reloaded in cpu_init()
+        */
        __set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
        idt_descr.address = fix_to_virt(FIX_RO_IDT);
+#ifdef CONFIG_X86_64
+       __set_fixmap(FIX_RO_DEBUG_IDT, __pa_symbol(debug_idt_table), PAGE_KERNEL_RO);
+       debug_idt_descr.address = fix_to_virt(FIX_RO_DEBUG_IDT);
+#endif
+#ifdef CONFIG_TRACING
+       __set_fixmap(FIX_RO_TRACE_IDT, __pa_symbol(trace_idt_table), PAGE_KERNEL_RO);
+       trace_idt_descr.address = fix_to_virt(FIX_RO_TRACE_IDT);
+#endif
 
        /*
         * Should be a barrier for any external CPU state:
arch/x86/xen/mmu.c +6 -1
index adca9e2..1fd4a4c 100644
@@ -1984,6 +1984,12 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
        switch (idx) {
        case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
        case FIX_RO_IDT:
+#ifdef CONFIG_X86_64
+       case FIX_RO_DEBUG_IDT:
+#endif
+#ifdef CONFIG_TRACING
+       case FIX_RO_TRACE_IDT:
+#endif
 #ifdef CONFIG_X86_32
        case FIX_WP_TEST:
 # ifdef CONFIG_HIGHMEM
--
Quoted 2 lines

1.8.4

--
Andy Lutomirski
AMA Capital Management, LLC

Signature · 2 lines
Kees Cook
Chrome OS Security
#3 lore raw
Quoted 17 lines · Kees Cook
Quoted 16 lines · Andy Lutomirski
Quoted 11 lines · Wang Nan

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

It shouldn't matter, since we should never enter userspace with these IDTs loaded.

Quoted 8 lines
Quoted 3 lines

--Andy

[patch kept below for Kees' benefit]

Is there a reason to use fixmap entries for these IDTs? Or rather, is there a situation where these IDTs are ever visible to userspace? (The reason to use the fixmap is to hide their "true" location from userspace.)

There's also the F00F workaround, which IIRC we get for free by using the fixmap, but that also shouldn't matter here.

Quoted 107 lines

-Kees

Quoted 90 lines
Quoted 90 lines

---
 arch/x86/include/asm/fixmap.h |  6 ++++++
 arch/x86/kernel/tracepoint.c  |  2 +-
 arch/x86/kernel/traps.c       | 13 +++++++++++--
 arch/x86/xen/mmu.c            |  6 ++++++
 4 files changed, 24 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +6 -0
index f80d700..79550f4 100644
@@ -90,6 +90,12 @@ enum fixed_addresses {
        FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
 #endif
        FIX_RO_IDT,     /* Virtual mapping for read-only IDT */
+#ifdef CONFIG_X86_64
+       FIX_RO_DEBUG_IDT,       /* Virtual mapping for read-only debug_idt_table */
+#endif
+#ifdef CONFIG_TRACING
+       FIX_RO_TRACE_IDT,       /* Virtual mapping for read-only trace_idt_table */
+#endif
 #ifdef CONFIG_X86_32
        FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
        FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
arch/x86/kernel/tracepoint.c +1 -1
index 1c113db..296e130 100644
@@ -12,7 +12,7 @@ atomic_t trace_idt_ctr = ATOMIC_INIT(0);
 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
                                (unsigned long) trace_idt_table };
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
 
 static int trace_irq_vector_refcount;
arch/x86/kernel/traps.c +11 -2
index cf7898e..6d88c37 100644
@@ -67,7 +67,7 @@
 #include <asm/pgalloc.h>
 #include <asm/proto.h>
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
 #else
 #include <asm/processor-flags.h>
@@ -998,9 +998,18 @@ void __init trap_init(void)
         * Set the IDT descriptor to a fixed read-only location, so that the
         * "sidt" instruction will not leak the location of the kernel, and
         * to defend the IDT against arbitrary memory write vulnerabilities.
-        * It will be reloaded in cpu_init() */
+        * It will be reloaded in cpu_init()
+        */
        __set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
        idt_descr.address = fix_to_virt(FIX_RO_IDT);
+#ifdef CONFIG_X86_64
+       __set_fixmap(FIX_RO_DEBUG_IDT, __pa_symbol(debug_idt_table), PAGE_KERNEL_RO);
+       debug_idt_descr.address = fix_to_virt(FIX_RO_DEBUG_IDT);
+#endif
+#ifdef CONFIG_TRACING
+       __set_fixmap(FIX_RO_TRACE_IDT, __pa_symbol(trace_idt_table), PAGE_KERNEL_RO);
+       trace_idt_descr.address = fix_to_virt(FIX_RO_TRACE_IDT);
+#endif
 
        /*
         * Should be a barrier for any external CPU state:
arch/x86/xen/mmu.c +6 -1
index adca9e2..1fd4a4c 100644
@@ -1984,6 +1984,12 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
        switch (idx) {
        case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
        case FIX_RO_IDT:
+#ifdef CONFIG_X86_64
+       case FIX_RO_DEBUG_IDT:
+#endif
+#ifdef CONFIG_TRACING
+       case FIX_RO_TRACE_IDT:
+#endif
 #ifdef CONFIG_X86_32
        case FIX_WP_TEST:
 # ifdef CONFIG_HIGHMEM
--
Quoted 8 lines
Quoted 2 lines

1.8.4

--
Andy Lutomirski
AMA Capital Management, LLC

--
Kees Cook
Chrome OS Security

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
author
#4 lore raw
Quoted 22 lines · Andy Lutomirski
Quoted 21 lines · Kees Cook
Quoted 19 lines · Andy Lutomirski
Quoted 11 lines · Wang Nan

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

It shouldn't matter, since we should never enter userspace with these IDTs loaded.

--Andy

[patch kept below for Kees' benefit]

Quoted 8 lines
Quoted 4 lines

Is there a reason to use fixmap entries for these IDTs? Or rather, is there a situation where these IDTs are ever visible to userspace? (The reason to use the fixmap is to hide their "true" location from userspace.)

There's also the F00F workaround, which IIRC we get for free by using the fixmap, but that also shouldn't matter here.

What about a flaw module triggering the F00F bug in kernel space? Instead of kernel panic, the system will hang. I think tis should be a case for which my patch can help. However, the trigger condition is critical.

Quoted 110 lines
Quoted 107 lines

-Kees

Quoted 90 lines
Quoted 90 lines

---
 arch/x86/include/asm/fixmap.h |  6 ++++++
 arch/x86/kernel/tracepoint.c  |  2 +-
 arch/x86/kernel/traps.c       | 13 +++++++++++--
 arch/x86/xen/mmu.c            |  6 ++++++
 4 files changed, 24 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +6 -0
index f80d700..79550f4 100644
@@ -90,6 +90,12 @@ enum fixed_addresses {
        FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
 #endif
        FIX_RO_IDT,     /* Virtual mapping for read-only IDT */
+#ifdef CONFIG_X86_64
+       FIX_RO_DEBUG_IDT,       /* Virtual mapping for read-only debug_idt_table */
+#endif
+#ifdef CONFIG_TRACING
+       FIX_RO_TRACE_IDT,       /* Virtual mapping for read-only trace_idt_table */
+#endif
 #ifdef CONFIG_X86_32
        FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
        FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
arch/x86/kernel/tracepoint.c +1 -1
index 1c113db..296e130 100644
@@ -12,7 +12,7 @@ atomic_t trace_idt_ctr = ATOMIC_INIT(0);
 struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
                                (unsigned long) trace_idt_table };
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
 
 static int trace_irq_vector_refcount;
arch/x86/kernel/traps.c +11 -2
index cf7898e..6d88c37 100644
@@ -67,7 +67,7 @@
 #include <asm/pgalloc.h>
 #include <asm/proto.h>
 
-/* No need to be aligned, but done to keep all IDTs defined the same way. */
+/* Must be page-aligned because the real IDT is used in a fixmap. */
 gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
 #else
 #include <asm/processor-flags.h>
@@ -998,9 +998,18 @@ void __init trap_init(void)
         * Set the IDT descriptor to a fixed read-only location, so that the
         * "sidt" instruction will not leak the location of the kernel, and
         * to defend the IDT against arbitrary memory write vulnerabilities.
-        * It will be reloaded in cpu_init() */
+        * It will be reloaded in cpu_init()
+        */
        __set_fixmap(FIX_RO_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
        idt_descr.address = fix_to_virt(FIX_RO_IDT);
+#ifdef CONFIG_X86_64
+       __set_fixmap(FIX_RO_DEBUG_IDT, __pa_symbol(debug_idt_table), PAGE_KERNEL_RO);
+       debug_idt_descr.address = fix_to_virt(FIX_RO_DEBUG_IDT);
+#endif
+#ifdef CONFIG_TRACING
+       __set_fixmap(FIX_RO_TRACE_IDT, __pa_symbol(trace_idt_table), PAGE_KERNEL_RO);
+       trace_idt_descr.address = fix_to_virt(FIX_RO_TRACE_IDT);
+#endif
 
        /*
         * Should be a barrier for any external CPU state:
arch/x86/xen/mmu.c +6 -1
index adca9e2..1fd4a4c 100644
@@ -1984,6 +1984,12 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)
        switch (idx) {
        case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
        case FIX_RO_IDT:
+#ifdef CONFIG_X86_64
+       case FIX_RO_DEBUG_IDT:
+#endif
+#ifdef CONFIG_TRACING
+       case FIX_RO_TRACE_IDT:
+#endif
 #ifdef CONFIG_X86_32
        case FIX_WP_TEST:
 # ifdef CONFIG_HIGHMEM
--
Quoted 8 lines
Quoted 2 lines

1.8.4

--
Andy Lutomirski
AMA Capital Management, LLC

--
Kees Cook
Chrome OS Security

#5 lore raw
Quoted 28 lines · Wang Nan
Quoted 27 lines · Andy Lutomirski
Quoted 25 lines · Kees Cook
Quoted 13 lines · Andy Lutomirski
Quoted 11 lines · Wang Nan

The reason why mapping idt_table to fixmap area should also be applied to debug_idt_table and trace_idt_table. This patch does same thing for all IDTs.

---

I believe trace_idt_table and debug_idt_table should be symmetrical with idt_table. However, Like my previous patch 'x86, traps: install gates using IST after cpu_init()', I'm not sure whether this is a practical fix.

Quoted 6 lines

It shouldn't matter, since we should never enter userspace with these IDTs loaded.

--Andy

[patch kept below for Kees' benefit]

Is there a reason to use fixmap entries for these IDTs? Or rather, is there a situation where these IDTs are ever visible to userspace? (The reason to use the fixmap is to hide their "true" location from userspace.)

Quoted 7 lines
Quoted 3 lines

There's also the F00F workaround, which IIRC we get for free by using the fixmap, but that also shouldn't matter here.

What about a flaw module triggering the F00F bug in kernel space? Instead of kernel panic, the system will hang. I think tis should be a case for which my patch can help. However, the trigger condition is critical.

If it solves a real problem, I have no objection. I just wanted to be sure we weren't trivially using up a fixmap entry.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security