Skip to contentSkip to conversation

x86/xpti: Hide almost all of .text and all .data/.rodata/.bss mappings

PATCH In review Andrew Cooper 3 participants 11 messages Feb 13, 2018 – Feb 14, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/xpti: Hide almost all of .text and all .data/.rodata/.bss mappings

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +32 -5
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));
+
     stub_va = XEN_VIRT_END - (cpu + 1) * PAGE_SIZE;
     if ( map_pages_to_xen(stub_va, mfn_x(page_to_mfn(pg)), 1,
                           PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) )
@@ -651,9 +654,6 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     l2_pgentry_t *pl2e;
     l1_pgentry_t *pl1e;
 
-    if ( linear < DIRECTMAP_VIRT_START )
-        return 0;
-
     flags = l3e_get_flags(*pl3e);
     ASSERT(flags & _PAGE_PRESENT);
     if ( flags & _PAGE_PSE )
@@ -744,6 +744,9 @@ static __read_mostly int8_t opt_xpti = -1;
 boolean_param("xpti", opt_xpti);
 DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
 
+static root_pgentry_t common_pgt;
+extern char _stextentry[], _etextentry[];
+
 static int setup_cpu_root_pgt(unsigned int cpu)
 {
     root_pgentry_t *rpt;
@@ -764,8 +767,32 @@ static int setup_cpu_root_pgt(unsigned int cpu)
         idle_pg_table[root_table_offset(RO_MPT_VIRT_START)];
     /* SH_LINEAR_PT inserted together with guest mappings. */
     /* PERDOMAIN inserted during context switch. */
-    rpt[root_table_offset(XEN_VIRT_START)] =
-        idle_pg_table[root_table_offset(XEN_VIRT_START)];
+
+    /* One-time setup of common_pgt, which maps .text.entry and the stubs. */
+    if ( unlikely(!root_get_intpte(common_pgt)) )
+    {
+        unsigned long stubs_linear = XEN_VIRT_END - 1;
+        l3_pgentry_t *stubs_main, *stubs_shadow;
+        char *ptr;
+
+        for ( rc = 0, ptr = _stextentry;
+              !rc && ptr < _etextentry; ptr += PAGE_SIZE )
+            rc = clone_mapping(ptr, rpt);
+
+        if ( rc )
+            return rc;
+
+        stubs_main = l4e_to_l3e(idle_pg_table[l4_table_offset(stubs_linear)]);
+        stubs_shadow = l4e_to_l3e(rpt[l4_table_offset(stubs_linear)]);
+
+        /* Splice into the regular L2 mapping the stubs. */
+        stubs_shadow[l3_table_offset(stubs_linear)] =
+            stubs_main[l3_table_offset(stubs_linear)];
+
+        common_pgt = rpt[root_table_offset(XEN_VIRT_START)];
+    }
+
+    rpt[root_table_offset(XEN_VIRT_START)] = common_pgt;
 
     /* Install direct map page table entries for stack, IDT, and TSS. */
     for ( off = rc = 0; !rc && off < STACK_SIZE; off += PAGE_SIZE )
xen/arch/x86/x86_64/compat/entry.S +2 -0
index 707c746..b001e79 100644
@@ -13,6 +13,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
+        .section .text.entry, "ax", @progbits
+
 ENTRY(entry_int82)
         ASM_CLAC
         pushq $0
xen/arch/x86/x86_64/entry.S +3 -1
index 58f652d..5c5310d 100644
@@ -14,6 +14,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
+        .section .text.entry, "ax", @progbits
+
 /* %rbx: struct vcpu */
 ENTRY(switch_to_kernel)
         leaq  VCPU_trap_bounce(%rbx),%rdx
@@ -854,7 +856,7 @@ GLOBAL(autogen_entrypoints)
         .popsection
         .endm
 
-        .text
+        .previous
 autogen_stubs: /* Automatically generated stubs. */
 
         vec = 0
xen/arch/x86/xen.lds.S +7 -0
index 0952980..25c6cbc 100644
@@ -67,6 +67,13 @@ SECTIONS
        *(.text)
        *(.text.__x86_indirect_thunk_*)
        *(.text.page_aligned)
+
+       . = ALIGN(PAGE_SIZE);
+       _stextentry = .;
+       *(.text.entry)
+       . = ALIGN(PAGE_SIZE);
+       _etextentry = .;
+
        *(.text.cold)
        *(.text.unlikely)
        *(.fixup)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 45 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 5 lines
xen/arch/x86/smpboot.c +2 -0
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

Juergen

Quoted 103 lines
xen/arch/x86/smpboot.c +30 -5
+
     stub_va = XEN_VIRT_END - (cpu + 1) * PAGE_SIZE;
     if ( map_pages_to_xen(stub_va, mfn_x(page_to_mfn(pg)), 1,
                           PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) )
@@ -651,9 +654,6 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     l2_pgentry_t *pl2e;
     l1_pgentry_t *pl1e;
 
-    if ( linear < DIRECTMAP_VIRT_START )
-        return 0;
-
     flags = l3e_get_flags(*pl3e);
     ASSERT(flags & _PAGE_PRESENT);
     if ( flags & _PAGE_PSE )
@@ -744,6 +744,9 @@ static __read_mostly int8_t opt_xpti = -1;
 boolean_param("xpti", opt_xpti);
 DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
 
+static root_pgentry_t common_pgt;
+extern char _stextentry[], _etextentry[];
+
 static int setup_cpu_root_pgt(unsigned int cpu)
 {
     root_pgentry_t *rpt;
@@ -764,8 +767,32 @@ static int setup_cpu_root_pgt(unsigned int cpu)
         idle_pg_table[root_table_offset(RO_MPT_VIRT_START)];
     /* SH_LINEAR_PT inserted together with guest mappings. */
     /* PERDOMAIN inserted during context switch. */
-    rpt[root_table_offset(XEN_VIRT_START)] =
-        idle_pg_table[root_table_offset(XEN_VIRT_START)];
+
+    /* One-time setup of common_pgt, which maps .text.entry and the stubs. */
+    if ( unlikely(!root_get_intpte(common_pgt)) )
+    {
+        unsigned long stubs_linear = XEN_VIRT_END - 1;
+        l3_pgentry_t *stubs_main, *stubs_shadow;
+        char *ptr;
+
+        for ( rc = 0, ptr = _stextentry;
+              !rc && ptr < _etextentry; ptr += PAGE_SIZE )
+            rc = clone_mapping(ptr, rpt);
+
+        if ( rc )
+            return rc;
+
+        stubs_main = l4e_to_l3e(idle_pg_table[l4_table_offset(stubs_linear)]);
+        stubs_shadow = l4e_to_l3e(rpt[l4_table_offset(stubs_linear)]);
+
+        /* Splice into the regular L2 mapping the stubs. */
+        stubs_shadow[l3_table_offset(stubs_linear)] =
+            stubs_main[l3_table_offset(stubs_linear)];
+
+        common_pgt = rpt[root_table_offset(XEN_VIRT_START)];
+    }
+
+    rpt[root_table_offset(XEN_VIRT_START)] = common_pgt;
 
     /* Install direct map page table entries for stack, IDT, and TSS. */
     for ( off = rc = 0; !rc && off < STACK_SIZE; off += PAGE_SIZE )
xen/arch/x86/x86_64/compat/entry.S +2 -0
index 707c746..b001e79 100644
@@ -13,6 +13,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
+        .section .text.entry, "ax", @progbits
+
 ENTRY(entry_int82)
         ASM_CLAC
         pushq $0
xen/arch/x86/x86_64/entry.S +3 -1
index 58f652d..5c5310d 100644
@@ -14,6 +14,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
+        .section .text.entry, "ax", @progbits
+
 /* %rbx: struct vcpu */
 ENTRY(switch_to_kernel)
         leaq  VCPU_trap_bounce(%rbx),%rdx
@@ -854,7 +856,7 @@ GLOBAL(autogen_entrypoints)
         .popsection
         .endm
 
-        .text
+        .previous
 autogen_stubs: /* Automatically generated stubs. */
 
         vec = 0
xen/arch/x86/xen.lds.S +0 -0
index 0952980..25c6cbc 100644
@@ -67,6 +67,13 @@ SECTIONS
        *(.text)
        *(.text.__x86_indirect_thunk_*)
        *(.text.page_aligned)

xen/arch/x86/xen.lds.S SECTIONS · line 79

Quoted 10 lines
xen/arch/x86/xen.lds.S +7 -0
+
+       . = ALIGN(PAGE_SIZE);
+       _stextentry = .;
+       *(.text.entry)
+       . = ALIGN(PAGE_SIZE);
+       _etextentry = .;
+
        *(.text.cold)
        *(.text.unlikely)
        *(.fixup)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 6 lines
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

L2_PAGETABLE_SHIFT is 21. So I still don't get why dropping PAGE_SIZE will correct it. OTOH I'm quite sure the BUILD_BUG_ON() won't trigger any more with PAGE_SIZE being dropped. :-)

Quoted 10 lines
Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

Quoted 4 lines

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

The stub-page of a cpu is currently mapped as the 3rd page of the stack area. So the distance to the primary stack would be the same for all cpus (a little bit less than 20kB).

Quoted 4 lines

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

The stack area is mapped. And that's where the stub is living.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 81 lines · Juergen Gross
Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 6 lines
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

L2_PAGETABLE_SHIFT is 21. So I still don't get why dropping PAGE_SIZE will correct it. OTOH I'm quite sure the BUILD_BUG_ON() won't trigger any more with PAGE_SIZE being dropped. :-)

Quoted 10 lines
Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

Quoted 4 lines

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

The stub-page of a cpu is currently mapped as the 3rd page of the stack area. So the distance to the primary stack would be the same for all cpus (a little bit less than 20kB).

Quoted 6 lines
Quoted 4 lines

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

The stack area is mapped. And that's where the stub is living.

Oh, did I mix up something? I followed the comments in current.h. The code suggests the syscall trampoline page isn't used at the moment for the stubs...

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 77 lines · Juergen Gross
Quoted 76 lines · Juergen Gross
Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 5 lines
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

L2_PAGETABLE_SHIFT is 21. So I still don't get why dropping PAGE_SIZE will correct it. OTOH I'm quite sure the BUILD_BUG_ON() won't trigger any more with PAGE_SIZE being dropped. :-)

Quoted 4 lines
Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 8 lines
Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

The stub-page of a cpu is currently mapped as the 3rd page of the stack area. So the distance to the primary stack would be the same for all cpus (a little bit less than 20kB).

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

The stack area is mapped. And that's where the stub is living.

Oh, did I mix up something? I followed the comments in current.h. The code suggests the syscall trampoline page isn't used at the moment for the stubs...

That will be stale from the work Jan did to make the stack fully NX. The syscall stubs used to be on the stack, but are no longer.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 82 lines · Andrew Cooper
Quoted 81 lines · Juergen Gross
Quoted 80 lines · Juergen Gross
Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 5 lines
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

L2_PAGETABLE_SHIFT is 21. So I still don't get why dropping PAGE_SIZE will correct it. OTOH I'm quite sure the BUILD_BUG_ON() won't trigger any more with PAGE_SIZE being dropped. :-)

Quoted 4 lines
Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 8 lines
Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

The stub-page of a cpu is currently mapped as the 3rd page of the stack area. So the distance to the primary stack would be the same for all cpus (a little bit less than 20kB).

Quoted 4 lines

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

The stack area is mapped. And that's where the stub is living.

Oh, did I mix up something? I followed the comments in current.h. The code suggests the syscall trampoline page isn't used at the moment for the stubs...

That will be stale from the work Jan did to make the stack fully NX. The syscall stubs used to be on the stack, but are no longer.

Changing this to make the syscall stub RO and executable again isn't impossible, I guess. Especially when this will make life easier at other places we should at least consider that option.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
Quoted 84 lines · Juergen Gross
Quoted 83 lines · Andrew Cooper
Quoted 82 lines · Juergen Gross
Quoted 81 lines · Juergen Gross
Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Juergen Gross
Quoted 48 lines · Andrew Cooper

The current XPTI implementation isolates the directmap (and therefore a lot of guest data), but a large quantity of CPU0's state (including its stack) remains visible.

Furthermore, an attacker able to read .text is in a vastly superior position to normal when it comes to fingerprinting Xen for known vulnerabilities, or scanning for ROP/Spectre gadgets.

Collect together the entrypoints in .text.entry (currently 3x4k frames, but can almost certainly be slimmed down), and create a common mapping which is inserted into each per-cpu shadow. The stubs are also inserted into this mapping by pointing at the in-use L2. This allows stubs allocated later (SMP boot, or CPU hotplug) to work without further changes to the common mappings.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

Also, my plan to cause .text.entry to straddle a 512TB boundary (and therefore avoid any further pagetable allocations) has come a little unstuck because of CONFIG_BIGMEM. I'm still working out whether there is a sensible way to rearrange the virtual layout for this plan to work.

---
 xen/arch/x86/smpboot.c             | 37 ++++++++++++++++++++++++++++++++-----
 xen/arch/x86/x86_64/compat/entry.S |  2 ++
 xen/arch/x86/x86_64/entry.S        |  4 +++-
 xen/arch/x86/xen.lds.S             |  7 +++++++
 4 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/x86/smpboot.c +0 -0
index 2ebef03..2519141 100644
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
Quoted 5 lines
Quoted 3 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 2 lines
xen/arch/x86/smpboot.c +2 -0
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

So we limit NR_CPUS to be max 512 now?

Not intentionally.  The PAGE_SIZE should be dropped.  (One full L2 pagetable allows us to map 512*512 pages).

L2_PAGETABLE_SHIFT is 21. So I still don't get why dropping PAGE_SIZE will correct it. OTOH I'm quite sure the BUILD_BUG_ON() won't trigger any more with PAGE_SIZE being dropped. :-)

Quoted 4 lines
Quoted 1 line

Maybe you should use STUB_BUF_SIZE instead of PAGE_SIZE?

No - that would be incorrect because of the physical packing of stubs which occurs.

Quoted 8 lines
Quoted 4 lines

BTW: Is there any reason we don't use a common stub page mapped to each per-cpu stack area? The stack address can easily be obtained via %rip relative addressing then (see my patch for the per-vcpu stacks:
https://lists.xen.org/archives/html/xen-devel/2018-02/msg00773.html )

I don't understand what you are asking here.  We cannot access the per-cpu area with plain rip-retaliative addressing without using gs base (and we really don't want to go down that route), or without per-cpu pagetables (which would have to be a compile time choice).

The stub-page of a cpu is currently mapped as the 3rd page of the stack area. So the distance to the primary stack would be the same for all cpus (a little bit less than 20kB).

Quoted 4 lines

As for why the per-cpu areas aren't mapped, that's because they aren't needed at the moment.  Any decision to change this needs to weigh the utility of mapping the areas vs the additional data leakage, which is substantial.

The stack area is mapped. And that's where the stub is living.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Oh, did I mix up something? I followed the comments in current.h. The code suggests the syscall trampoline page isn't used at the moment for the stubs...

That will be stale from the work Jan did to make the stack fully NX. The syscall stubs used to be on the stack, but are no longer.

Changing this to make the syscall stub RO and executable again isn't impossible, I guess. Especially when this will make life easier at other places we should at least consider that option.

The stubs are RO/NX in the XEN_VIRT_* range, and it is these mappings that I clone.

The emulation stubs are written by using map_domain_page() to make a writeable alias.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw
In reply to Andrew Cooper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 20:45, <[email protected]> wrote:

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

The 4k-per-CPU allocation of VA space is probably not strictly necessary - quoting the original commit message:
"While sharing physical pages among certain CPUs on the same node, for
now the virtual mappings get established in distinct pages for each CPU. This isn't a strict requirement, but simplifies VA space management for this initial implementation: Sharing VA space would require additional tracking of which areas are currently in use. If the VA and/or TLB overhead turned out to be a problem, such extra code could easily be added."

Without allocating a page per CPU I think what you do is sensible. And I don't see how hiding stubs of other CPUs would help much - an attacker can gather stack locations from various CPUs as its vCPU is being moved around, and you can't hide the current CPU's stub space.

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 8 lines
xen/arch/x86/smpboot.c +2 -0
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

Perhaps duplicate this in setup_cpu_root_pgt() (suitably adjusted of course, as Jürgen has already pointed out)?

xen/arch/x86/smpboot.c static int clone_mapping(const void *ptr, root_pgentry_t *rpt) · line 655

Quoted 6 lines
xen/arch/x86/smpboot.c +0 -2
@@ -651,9 +654,6 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     l2_pgentry_t *pl2e;
     l1_pgentry_t *pl1e;
 
-    if ( linear < DIRECTMAP_VIRT_START )
-        return 0;

Isn't outright removing this going a little too far?

xen/arch/x86/smpboot.c static __read_mostly int8_t opt_xpti = -1; · line 747

Quoted 5 lines
xen/arch/x86/smpboot.c +1 -0
@@ -744,6 +744,9 @@ static __read_mostly int8_t opt_xpti = -1;
 boolean_param("xpti", opt_xpti);
 DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
 
+static root_pgentry_t common_pgt;

Move into setup_cpu_root_pgt()?

xen/arch/x86/smpboot.c static __read_mostly int8_t opt_xpti = -1; · line 748

Quoted 1 line
xen/arch/x86/smpboot.c +1 -0
+extern char _stextentry[], _etextentry[];

const?

xen/arch/x86/x86_64/compat/entry.S line 20

Quoted 11 lines
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -13,6 +13,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
+        .section .text.entry, "ax", @progbits
+
 ENTRY(entry_int82)
         ASM_CLAC
         pushq $0

This also puts compat_create_bounce_frame into the entry section, which surely isn't needed. Same for the non-compat variant.

xen/arch/x86/x86_64/compat/entry.S GLOBAL(autogen_entrypoints) · line 860

Quoted 7 lines
xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -854,7 +856,7 @@ GLOBAL(autogen_entrypoints)
         .popsection
         .endm
 
-        .text
+        .previous
 autogen_stubs: /* Automatically generated stubs. */

Perhaps better to switch the earlier .section to .pushsection, and use .popsection here?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw
Quoted 19 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 20:45, <[email protected]> wrote:

RFC, because I don't think the stubs handling is particularly sensible.

We allocate 4k of virtual address space per CPU, but squash loads of CPUs together onto a single MFN. The stubs ought to be isolated as well (as they leak the virtual addresses of each stack), which can be done by allocating an MFN per CPU (and simplifies cpu_smpboot_alloc() somewhat). At this point, we can't use a common set of mappings, and will have to clone the single stub and .entry.text into each PCPUs copy of the pagetables.

The 4k-per-CPU allocation of VA space is probably not strictly necessary - quoting the original commit message:
"While sharing physical pages among certain CPUs on the same node, for
now the virtual mappings get established in distinct pages for each CPU. This isn't a strict requirement, but simplifies VA space management for this initial implementation: Sharing VA space would require additional tracking of which areas are currently in use. If the VA and/or TLB overhead turned out to be a problem, such extra code could easily be added."

Quoted 5 lines

Without allocating a page per CPU I think what you do is sensible. And I don't see how hiding stubs of other CPUs would help much - an attacker can gather stack locations from various CPUs as its vCPU is being moved around, and you can't hide the current CPU's stub space.

Well - scenarios with pinning or cpupools would have a restricted access to other cpu stack locations.

If the stubs were split in half, we could at least separate the syscall stubs from the emulation stubs, and leave the latter unmapped.

Quoted 12 lines

xen/arch/x86/smpboot.c unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) · line 626

Quoted 9 lines
xen/arch/x86/smpboot.c +2 -0
@@ -622,6 +622,9 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
         unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
     }
 
+    /* Confirm that all stubs fit in a single L2 pagetable. */
+    BUILD_BUG_ON(NR_CPUS * PAGE_SIZE > (1u << L2_PAGETABLE_SHIFT));

Perhaps duplicate this in setup_cpu_root_pgt() (suitably adjusted of course, as Jürgen has already pointed out)?

Quoted 7 lines

xen/arch/x86/smpboot.c static int clone_mapping(const void *ptr, root_pgentry_t *rpt) · line 655

Quoted 6 lines
xen/arch/x86/smpboot.c +0 -2
@@ -651,9 +654,6 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     l2_pgentry_t *pl2e;
     l1_pgentry_t *pl1e;
 
-    if ( linear < DIRECTMAP_VIRT_START )
-        return 0;

Isn't outright removing this going a little too far?

Considering it is buggy, no.  Retuning success after doing nothing is very antisocial.

If anything, it should return -EINVAL so the caller knows that something expected happened, but it should also reject attempts to clone mappings beyond the end of the directmap (as those will explode when we switch to PV context), and the XEN_VIRT_* range needs white-listing as ok to clone for this usecase to work.

Quoted 6 lines
Quoted 6 lines
xen/arch/x86/x86_64/compat/entry.S +0 -0
@@ -13,6 +13,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
Quoted 7 lines

xen/arch/x86/x86_64/compat/entry.S line 20

Quoted 5 lines
xen/arch/x86/x86_64/compat/entry.S +2 -0
+        .section .text.entry, "ax", @progbits
+
 ENTRY(entry_int82)
         ASM_CLAC
         pushq $0

This also puts compat_create_bounce_frame into the entry section, which surely isn't needed. Same for the non-compat variant.

I considered that.  Excluding those ranges won't reduce the number of allocations we make, but it does complicate backports.

Also, I still fully intend to make the functions disappear into C and move out of .text.entry that way.

Quoted 10 lines

xen/arch/x86/x86_64/compat/entry.S GLOBAL(autogen_entrypoints) · line 860

Quoted 8 lines
xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -854,7 +856,7 @@ GLOBAL(autogen_entrypoints)
         .popsection
         .endm
 
-        .text
+        .previous
 autogen_stubs: /* Automatically generated stubs. */

Perhaps better to switch the earlier .section to .pushsection, and use .popsection here?

Will do.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 14.02.18 at 13:34, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

xen/arch/x86/smpboot.c static int clone_mapping(const void *ptr, root_pgentry_t *rpt) · line 655

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.18 at 20:45, <[email protected]> wrote:
xen/arch/x86/smpboot.c +0 -2
@@ -651,9 +654,6 @@ static int clone_mapping(const void *ptr, root_pgentry_t *rpt)
     l2_pgentry_t *pl2e;
     l1_pgentry_t *pl1e;
 
-    if ( linear < DIRECTMAP_VIRT_START )
-        return 0;

Isn't outright removing this going a little too far?

Quoted 8 lines

Considering it is buggy, no. Retuning success after doing nothing is very antisocial.

If anything, it should return -EINVAL so the caller knows that something expected happened, but it should also reject attempts to clone mappings beyond the end of the directmap (as those will explode when we switch to PV context), and the XEN_VIRT_* range needs white-listing as ok to clone for this usecase to work.

Returning -EINVAL would have been wrong without excluding the XEN_VIRT_* range - the boot CPU has at least its IDT there. Tightening the check would be fine with me.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/x86_64/compat/entry.S +0 -0
@@ -13,6 +13,8 @@
 #include <public/xen.h>
 #include <irq_vectors.h>
 
Quoted 7 lines

xen/arch/x86/x86_64/compat/entry.S line 20

Quoted 5 lines
xen/arch/x86/x86_64/compat/entry.S +2 -0
+        .section .text.entry, "ax", @progbits
+
 ENTRY(entry_int82)
         ASM_CLAC
         pushq $0

This also puts compat_create_bounce_frame into the entry section, which surely isn't needed. Same for the non-compat variant.

Quoted 2 lines

I considered that. Excluding those ranges won't reduce the number of allocations we make, but it does complicate backports.

Complicate backports? The context of the section directive may change some, but that's not a significant complication imo.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel