XSAs 213-315 followups
cover XSAs 213-315 followups
Various improvements based on observations while investigating and fixing the aformentioned XSAs. All are candidate patches for 4.9 at this point, with patches 2, 3 and 7 being the important ones from an attack-surface-mitigation point of view.
This is the subset of my intented series, but I haven't had time to finish the rest of the work I wanted to do, which clearly makes it post 4.9 work at this point.
Andrew Cooper (7):
x86/traps: Drop 32bit fields out of tss_struct x86/traps: Poison unused stack pointers in the TSS x86/mm: Further restrict permissions on some virtual mappings x86/traps: Rename compat_hypercall() to entry_int82() x86/traps: Lift all non-entrypoint logic in entry_int82() up into C x86/asm: Fold LOAD_C_CLOBBERED into RESTORE_ALL
x86/asm: Clobber %r{8..15} on exit to 32bit PV guests
xen/arch/x86/cpu/common.c | 8 +++++++ xen/arch/x86/domain.c | 2 +- xen/arch/x86/mm.c | 10 ++++----- xen/arch/x86/mm/hap/hap.c | 4 ++-- xen/arch/x86/mm/shadow/multi.c | 18 +++++++-------- xen/arch/x86/pv/Makefile | 2 ++ xen/arch/x86/pv/traps.c | 44 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 4 ++-- xen/arch/x86/x86_64/compat/entry.S | 13 +++-------- xen/arch/x86/x86_64/mm.c | 12 +++++----- xen/drivers/passthrough/vtd/iommu.c | 4 ++-- xen/include/asm-x86/apic.h | 1 + xen/include/asm-x86/asm_defns.h | 38 ++++++++++++++------------------ xen/include/asm-x86/hypercall.h | 4 ++++ xen/include/asm-x86/iommu.h | 2 ++ xen/include/asm-x86/processor.h | 26 +++++++++++----------- 16 files changed, 121 insertions(+), 71 deletions(-) create mode 100644 xen/arch/x86/pv/traps.c
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/7 x86/traps: Drop 32bit fields out of tss_struct
The backlink field doesn't exist in a 64bit TSS, and union for esp{0..2} is of no practical use. Specify everything with stdint types, and empty bitfields for reserved values.
No functional change.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/traps.c | 2 +- xen/include/asm-x86/processor.h | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-)
xen/arch/x86/traps.c +1 -1
@@ -461,7 +461,7 @@ void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs)printk ("Valid stack range: %p-%p, sp=%p, tss.esp0=%p\n" , (void *)esp_top, (void *)esp_bottom, (void *)esp, - (void *)per_cpu (init_tss, cpu).esp0); + (void *)per_cpu (init_tss, cpu).rsp0);/* * Trigger overflow trace if %esp is anywhere within the guard page, or
xen/include/asm-x86/processor.h +11 -12
@@ -428,19 +428,18 @@ static always_inline void __mwait(unsigned long eax, unsigned long ecx)#define IOBMP_INVALID_OFFSET 0x8000 struct __packed __cacheline_aligned tss_struct { -unsigned short back_link,__blh; -union {u64 rsp0, esp0; }; -union {u64 rsp1, esp1; }; -union {u64 rsp2, esp2; }; -u64 reserved1; -u64 ist[7 ];/* Interrupt Stack Table is 1-based so tss->ist[0] -* corresponds to an IST value of 1 in an Interrupt -* Descriptor */ -u64 reserved2; -u16 reserved3; -u16 bitmap; + uint32_t :32; +uint64_t rsp0, rsp1, rsp2; + uint64_t :64; +/* +* Interrupt Stack Table is 1-based so tss->ist[0] corresponds to an IST +* value of 1 in an Interrupt Descriptor. +*/ +uint64_t ist[7 ]; + uint64_t :64; + uint16_t :16, bitmap;/* Pads the TSS to be cacheline-aligned (total size is 0x80). */ -u8 __cacheline_filler[24 ]; +uint8_t __cacheline_filler[24 ]; };#define IST_NONE 0UL
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 1/7] x86/traps: Drop 32bit fields out of tss_struct
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
The backlink field doesn't exist in a 64bit TSS, and union for esp{0..2} is of no practical use. Specify everything with stdint types, and empty bitfields for reserved values.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
with one minor extra adjustment:
xen/arch/x86/traps.c void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs) · line 462
Quoted 5 lines
xen/arch/x86/traps.c +0
-0@@ -461,7 +461,7 @@ void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs) printk("Valid stack range: %p-%p, sp=%p, tss.esp0=%p\n",
Would you mind dropping or replacing the e in esp0 here too?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] x86/traps: Drop 32bit fields out of tss_struct
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
The backlink field doesn't exist in a 64bit TSS, and union for esp{0..2} is of no practical use. Specify everything with stdint types, and empty bitfields for reserved values.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Quoted 8 lines
with one minor extra adjustment:
xen/arch/x86/traps.c void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs) · line 462
Quoted 5 lines
xen/arch/x86/traps.c +0
-0@@ -461,7 +461,7 @@ void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs) printk("Valid stack range: %p-%p, sp=%p, tss.esp0=%p\n",Would you mind dropping or replacing the e in esp0 here too?
Fixed.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 1/7] x86/traps: Drop 32bit fields out of tss_struct
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
The backlink field doesn't exist in a 64bit TSS, and union for esp{0..2} is of no practical use. Specify everything with stdint types, and empty bitfields for reserved values.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 2/7 x86/traps: Poison unused stack pointers in the TSS
In reply to Andrew CooperThis is for additional defence-in-depth following LDT/GDT/IDT corruption.
It causes attempted control transfers to ring 1 or 2 (via a call gate), or attempts to use IST 3 through 7 to yield #SS[0], rather than executing with a stack starting at the top of virtual address space.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/cpu/common.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/x86/cpu/common.c +8 -0
@@ -645,6 +645,14 @@ void load_system_tables(void) tss->ist[IST_DF -1 ] = stack_top +IST_DF *PAGE_SIZE ; tss->ist[IST_NMI -1 ] = stack_top +IST_NMI *PAGE_SIZE ; +/* Poision all other stack pointers to prevent their accidental use. */ + tss->rsp1 =0x8600111111111111ul ; + tss->rsp2 =0x8600222222222222ul ; + tss->ist[3 ] =0x8600444444444444ul ; + tss->ist[4 ] =0x8600555555555555ul ; + tss->ist[5 ] =0x8600666666666666ul ; + tss->ist[6 ] =0x8600777777777777ul ; + _set_tssldt_desc( gdt + TSS_ENTRY, (unsigned long)tss,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/7] x86/traps: Poison unused stack pointers in the TSS
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/cpu/common.c void load_system_tables(void) · line 654
Quoted 10 lines
xen/arch/x86/cpu/common.c +7
-0@@ -645,6 +645,14 @@ void load_system_tables(void) tss->ist[IST_DF -1 ] = stack_top +IST_DF *PAGE_SIZE ; tss->ist[IST_NMI -1 ] = stack_top +IST_NMI *PAGE_SIZE ; +/* Poision all other stack pointers to prevent their accidental use. */ + tss->rsp1 =0x8600111111111111ul ; + tss->rsp2 =0x8600222222222222ul ; + tss->ist[3 ] =0x8600444444444444ul ; + tss->ist[4 ] =0x8600555555555555ul ; + tss->ist[5 ] =0x8600666666666666ul ; + tss->ist[6 ] =0x8600777777777777ul ;
I think the ->ist[] part of this should be a loop from IST_MAX + 1 to 7 instead of the above, as what you have now doesn't easily cope with IST indexes being added/removed.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 2/7] x86/traps: Poison unused stack pointers in the TSS
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/cpu/common.c +0
-0@@ -645,6 +645,14 @@ void load_system_tables(void) tss->ist[IST_DF -1 ] = stack_top +IST_DF *PAGE_SIZE ; tss->ist[IST_NMI -1 ] = stack_top +IST_NMI *PAGE_SIZE ;
Quoted 10 lines
xen/arch/x86/cpu/common.c void load_system_tables(void) · line 654
Quoted 7 lines
xen/arch/x86/cpu/common.c +7
-0+/* Poision all other stack pointers to prevent their accidental use. */ + tss->rsp1 =0x8600111111111111ul ; + tss->rsp2 =0x8600222222222222ul ; + tss->ist[3 ] =0x8600444444444444ul ; + tss->ist[4 ] =0x8600555555555555ul ; + tss->ist[5 ] =0x8600666666666666ul ; + tss->ist[6 ] =0x8600777777777777ul ;I think the ->ist[] part of this should be a loop from
IST_MAX+ 1 to 7 instead of the above, as what you have now doesn't easily cope with IST indexes being added/removed.
Part of the intention of having them here is that they are adjacent to the other tss->ist[] setup, which will necessarily change if the indexes get altered.
As for the constants in use, I'd originally intended to make each pointer identifiable, but testing revealed that these constants end up nowhere useful were crash to end up happening. Therefore, I don't have a problem with using alternative constants, and indeed the same poison constant for each pointer.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 2/7 x86/traps: Poison unused stack pointers in the TSS
In reply to Andrew CooperThis is for additional defence-in-depth following LDT/GDT/IDT corruption.
It causes attempted control transfers to ring 1 or 2 (via a call gate), or attempts to use IST 3 through 7 to yield #SS, rather than executing with a stack starting at the top of virtual address space.
Express the TSS setup in terms of structure assignment, which should be less fragile if the IST indexes need to change, and has the useful side effect of zeroing the reserved fields.
---
CC: Jan Beulich <[email protected]>
v2:
* Rearange to avoid 6 straight assignments.
--- xen/arch/x86/cpu/common.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
xen/arch/x86/cpu/common.c +23 -8
@@ -636,14 +636,29 @@ void load_system_tables(void) .limit = (IDT_ENTRIES * sizeof(idt_entry_t)) - 1, }; -/* Main stack for interrupts/exceptions. */ - tss->rsp0 = stack_bottom; - tss->bitmap =IOBMP_INVALID_OFFSET ; - -/* MCE, NMI and Double Fault handlers get their own stacks. */ - tss->ist[IST_MCE -1 ] = stack_top +IST_MCE *PAGE_SIZE ; - tss->ist[IST_DF -1 ] = stack_top +IST_DF *PAGE_SIZE ; - tss->ist[IST_NMI -1 ] = stack_top +IST_NMI *PAGE_SIZE ; + *tss = (struct tss_struct ){ +/* Main stack for interrupts/exceptions. */ + .rsp0 = stack_bottom, + +/* Ring 1 and 2 stacks poisoned. */ + .rsp1 =0x8600111111111111ul , + .rsp2 =0x8600111111111111ul , + +/* +* MCE, NMI and Double Fault handlers get their own stacks. +* All others poisoned. +*/ + .ist = { + [IST_MCE -1 ] = stack_top +IST_MCE *PAGE_SIZE , + [IST_DF -1 ] = stack_top +IST_DF *PAGE_SIZE , + [IST_NMI -1 ] = stack_top +IST_NMI *PAGE_SIZE , + + [IST_MAX ...ARRAY_SIZE (tss->ist) -1 ] = +0x8600111111111111ul , + }, + + .bitmap =IOBMP_INVALID_OFFSET , + }; _set_tssldt_desc( gdt + TSS_ENTRY,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 2/7] x86/traps: Poison unused stack pointers in the TSS
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 15:29, <[email protected]> wrote:
This is for additional defence-in-depth following LDT/GDT/IDT corruption.
It causes attempted control transfers to ring 1 or 2 (via a call gate), or attempts to use IST 3 through 7 to yield #SS, rather than executing with a stack starting at the top of virtual address space.
Quoted 5 lines
Express the TSS setup in terms of structure assignment, which should be less fragile if the IST indexes need to change, and has the useful side effect of zeroing the reserved fields.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/7 x86/mm: Further restrict permissions on some virtual mappings
In reply to Andrew CooperAs originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.
---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>
--- xen/arch/x86/domain.c | 2 +- xen/arch/x86/mm.c | 10 +++++----- xen/arch/x86/mm/hap/hap.c | 4 ++-- xen/arch/x86/mm/shadow/multi.c | 18 +++++++++--------- xen/arch/x86/x86_64/mm.c | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-)
xen/arch/x86/domain.c +1 -1
@@ -2040,7 +2040,7 @@ static void __context_switch(void)for ( i =0 ; i <NR_RESERVED_GDT_PAGES ; i++ )l1e_write (pl1e +FIRST_RESERVED_GDT_PAGE + i, -l1e_from_pfn (mfn + i, __PAGE_HYPERVISOR)); +l1e_from_pfn (mfn + i, __PAGE_HYPERVISOR_RW)); } if ( need_full_gdt(pd) &&
xen/arch/x86/mm.c +5 -5
@@ -384,7 +384,7 @@ void __init arch_init_memory(void)for ( ; i <L3_PAGETABLE_ENTRIES ; ++i ) l3tab[i] =l3e_empty (); split_l4e =l4e_from_pfn (virt_to_mfn (l3tab), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW); }else ++root_pgt_pv_xen_slots;
@@ -1588,9 +1588,9 @@ void init_guest_l4_table(l4_pgentry_t l4tab[], const struct domain *d, split_l4e;#endif l4tab[l4_table_offset (LINEAR_PT_VIRT_START )] = -l4e_from_pfn (domain_page_map_to_mfn (l4tab), __PAGE_HYPERVISOR); +l4e_from_pfn (domain_page_map_to_mfn (l4tab), __PAGE_HYPERVISOR_RW); l4tab[l4_table_offset (PERDOMAIN_VIRT_START )] = -l4e_from_page (d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR); +l4e_from_page (d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW);if ( zap_ro_mpt ||is_pv_32bit_domain (d) ||paging_mode_refcounts (d) ) l4tab[l4_table_offset (RO_MPT_VIRT_START )] =l4e_empty (); }
@@ -6380,7 +6380,7 @@ int create_perdomain_mapping(struct domain *d, unsigned long va, } l2tab =__map_domain_page (pg);clear_page (l2tab); - l3tab[l3_table_offset (va)] =l3e_from_page (pg, __PAGE_HYPERVISOR); + l3tab[l3_table_offset (va)] =l3e_from_page (pg, __PAGE_HYPERVISOR_RW); }else l2tab =map_domain_page (_mfn (l3e_get_pfn (l3tab[l3_table_offset (va)])));
@@ -6422,7 +6422,7 @@ int create_perdomain_mapping(struct domain *d, unsigned long va, l1tab =__map_domain_page (pg); }clear_page (l1tab); - *pl2e =l2e_from_page (pg, __PAGE_HYPERVISOR); + *pl2e =l2e_from_page (pg, __PAGE_HYPERVISOR_RW); }else if ( !l1tab ) l1tab =map_domain_page (_mfn (l2e_get_pfn (*pl2e)));
xen/arch/x86/mm/hap/hap.c +2 -2
@@ -409,11 +409,11 @@ static void hap_install_xen_entries_in_l4(struct vcpu *v, mfn_t l4mfn)/* Install the per-domain mappings for this domain */ l4e[l4_table_offset (PERDOMAIN_VIRT_START )] =l4e_from_pfn (mfn_x (page_to_mfn (d->arch.perdomain_l3_pg)), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW);/* Install a linear mapping */ l4e[l4_table_offset (LINEAR_PT_VIRT_START )] = -l4e_from_pfn (mfn_x (l4mfn), __PAGE_HYPERVISOR); +l4e_from_pfn (mfn_x (l4mfn), __PAGE_HYPERVISOR_RW);unmap_domain_page (l4e); }
xen/arch/x86/mm/shadow/multi.c +9 -9
@@ -1475,7 +1475,7 @@ void sh_install_xen_entries_in_l4(struct domain *d, mfn_t gl4mfn, mfn_t sl4mfn)/* Install the per-domain mappings for this domain */ sl4e[shadow_l4_table_offset (PERDOMAIN_VIRT_START )] =shadow_l4e_from_mfn (page_to_mfn (d->arch.perdomain_l3_pg), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW);if ( !shadow_mode_external (d) && !is_pv_32bit_domain (d) && !VM_ASSIST (d, m2p_strict) )
@@ -1489,7 +1489,7 @@ void sh_install_xen_entries_in_l4(struct domain *d, mfn_t gl4mfn, mfn_t sl4mfn)* monitor pagetable structure, which is built in make_monitor_table * and maintained by sh_update_linear_entries. */ sl4e[shadow_l4_table_offset (SH_LINEAR_PT_VIRT_START )] = -shadow_l4e_from_mfn (sl4mfn, __PAGE_HYPERVISOR); +shadow_l4e_from_mfn (sl4mfn, __PAGE_HYPERVISOR_RW);/* Self linear mapping. */ if (shadow_mode_translate (d) && !shadow_mode_external (d) )
@@ -1501,7 +1501,7 @@ void sh_install_xen_entries_in_l4(struct domain *d, mfn_t gl4mfn, mfn_t sl4mfn)else { sl4e[shadow_l4_table_offset (LINEAR_PT_VIRT_START )] = -shadow_l4e_from_mfn (gl4mfn, __PAGE_HYPERVISOR); +shadow_l4e_from_mfn (gl4mfn, __PAGE_HYPERVISOR_RW); }unmap_domain_page (sl4e);
@@ -1654,12 +1654,12 @@ sh_make_monitor_table(struct vcpu *v) m3mfn =shadow_alloc (d, SH_type_monitor_table,0 );mfn_to_page (m3mfn)->shadow_flags =3 ; l4e[shadow_l4_table_offset (SH_LINEAR_PT_VIRT_START )] - =l4e_from_pfn (mfn_x (m3mfn), __PAGE_HYPERVISOR); + =l4e_from_pfn (mfn_x (m3mfn), __PAGE_HYPERVISOR_RW); m2mfn =shadow_alloc (d, SH_type_monitor_table,0 );mfn_to_page (m2mfn)->shadow_flags =2 ; l3e =map_domain_page (m3mfn); - l3e[0 ] =l3e_from_pfn (mfn_x (m2mfn), __PAGE_HYPERVISOR); + l3e[0 ] =l3e_from_pfn (mfn_x (m2mfn), __PAGE_HYPERVISOR_RW);unmap_domain_page (l3e);if (is_pv_32bit_domain (d) )
@@ -1668,7 +1668,7 @@ sh_make_monitor_table(struct vcpu *v)* area into its usual VAs in the monitor tables */ m3mfn =shadow_alloc (d, SH_type_monitor_table,0 );mfn_to_page (m3mfn)->shadow_flags =3 ; - l4e[0 ] =l4e_from_pfn (mfn_x (m3mfn), __PAGE_HYPERVISOR); + l4e[0 ] =l4e_from_pfn (mfn_x (m3mfn), __PAGE_HYPERVISOR_RW); m2mfn =shadow_alloc (d, SH_type_monitor_table,0 );mfn_to_page (m2mfn)->shadow_flags =2 ;
@@ -3838,7 +3838,7 @@ sh_update_linear_entries(struct vcpu *v) { __linear_l4_table[l4_linear_offset (SH_LINEAR_PT_VIRT_START )] =l4e_from_pfn (pagetable_get_pfn (v->arch.shadow_table[0 ]), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW); } else {
@@ -3846,7 +3846,7 @@ sh_update_linear_entries(struct vcpu *v) ml4e =map_domain_page (pagetable_get_mfn (v->arch.monitor_table)); ml4e[l4_table_offset (SH_LINEAR_PT_VIRT_START )] =l4e_from_pfn (pagetable_get_pfn (v->arch.shadow_table[0 ]), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW);unmap_domain_page (ml4e); } }
@@ -3902,7 +3902,7 @@ sh_update_linear_entries(struct vcpu *v) ml2e[i] = (shadow_l3e_get_flags (sl3e[i]) & _PAGE_PRESENT) ?l2e_from_pfn (mfn_x (shadow_l3e_get_mfn (sl3e[i])), - __PAGE_HYPERVISOR) + __PAGE_HYPERVISOR_RW) :l2e_empty (); }
xen/arch/x86/x86_64/mm.c +6 -6
@@ -470,7 +470,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info)clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (va)],l3e_from_paddr (__pa (l2_ro_mpt), - __PAGE_HYPERVISOR | _PAGE_USER)); + __PAGE_HYPERVISOR_RO | _PAGE_USER)); l2_ro_mpt +=l2_table_offset (va); }
@@ -515,7 +515,7 @@ void __init paging_init(void) l3_ro_mpt =page_to_virt (l3_pg);clear_page (l3_ro_mpt);l4e_write (&idle_pg_table[l4_table_offset (va)], -l4e_from_page (l3_pg, __PAGE_HYPERVISOR)); +l4e_from_page (l3_pg, __PAGE_HYPERVISOR_RW)); } }
@@ -525,7 +525,7 @@ void __init paging_init(void) l3_ro_mpt =page_to_virt (l3_pg);clear_page (l3_ro_mpt);l4e_write (&idle_pg_table[l4_table_offset (RO_MPT_VIRT_START )], -l4e_from_page (l3_pg, __PAGE_HYPERVISOR | _PAGE_USER)); +l4e_from_page (l3_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));/* * Allocate and map the machine-to-phys table.
@@ -612,7 +612,7 @@ void __init paging_init(void) l2_ro_mpt =page_to_virt (l2_pg);clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (va)], -l3e_from_page (l2_pg, __PAGE_HYPERVISOR | _PAGE_USER)); +l3e_from_page (l2_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER));ASSERT (!l2_table_offset (va)); }/* NB. Cannot be GLOBAL: guest user mode should not see it. */
@@ -634,7 +634,7 @@ void __init paging_init(void) compat_idle_pg_table_l2 = l2_ro_mpt;clear_page (l2_ro_mpt);l3e_write (&l3_ro_mpt[l3_table_offset (HIRO_COMPAT_MPT_VIRT_START )], -l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR)); +l3e_from_paddr (__pa (l2_ro_mpt), __PAGE_HYPERVISOR_RO)); l2_ro_mpt +=l2_table_offset (HIRO_COMPAT_MPT_VIRT_START );/* Allocate and map the compatibility mode machine-to-phys table. */ mpt_size = (mpt_size >>1 ) + (1UL << (L2_PAGETABLE_SHIFT -1 ));
@@ -679,7 +679,7 @@ void __init paging_init(void)/* Set up linear page table mapping. */ l4e_write (&idle_pg_table[l4_table_offset (LINEAR_PT_VIRT_START )], -l4e_from_paddr (__pa (idle_pg_table), __PAGE_HYPERVISOR)); +l4e_from_paddr (__pa (idle_pg_table), __PAGE_HYPERVISOR_RW));return ; nomem:
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
As originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
Quoted 8 lines
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.Reported-by Jann Horn <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
with two remarks:
xen/arch/x86/mm.c void __init arch_init_memory(void) · line 387
Quoted 8 lines
xen/arch/x86/mm.c +1
-1@@ -384,7 +384,7 @@ void __init arch_init_memory(void)for ( ; i <L3_PAGETABLE_ENTRIES ; ++i ) l3tab[i] =l3e_empty (); split_l4e =l4e_from_pfn (virt_to_mfn (l3tab), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW);
Would be nice if this change (affecting the direct map) was also mentioned in the commit message, even if it's only debugging code.
xen/arch/x86/mm.c void __init paging_init(void) · line 518
Quoted 6 lines
xen/arch/x86/mm.c +1
-1@@ -515,7 +515,7 @@ void __init paging_init(void) l3_ro_mpt =page_to_virt (l3_pg);clear_page (l3_ro_mpt);l4e_write (&idle_pg_table[l4_table_offset (va)], -l4e_from_page (l3_pg, __PAGE_HYPERVISOR)); +l4e_from_page (l3_pg, __PAGE_HYPERVISOR_RW));
Similarly here (again affecting the direct map).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
Quoted 32 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
As originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
Quoted 8 lines
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.Reported-by Jann Horn <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
xen/arch/x86/mm.c void __init arch_init_memory(void) · line 387
Quoted 8 lines
xen/arch/x86/mm.c +1
-1@@ -384,7 +384,7 @@ void __init arch_init_memory(void)for ( ; i <L3_PAGETABLE_ENTRIES ; ++i ) l3tab[i] =l3e_empty (); split_l4e =l4e_from_pfn (virt_to_mfn (l3tab), - __PAGE_HYPERVISOR); + __PAGE_HYPERVISOR_RW);Would be nice if this change (affecting the direct map) was also mentioned in the commit message, even if it's only debugging code.
Quoted 7 lines
xen/arch/x86/mm.c void __init paging_init(void) · line 518
Quoted 6 lines
xen/arch/x86/mm.c +1
-1@@ -515,7 +515,7 @@ void __init paging_init(void) l3_ro_mpt =page_to_virt (l3_pg);clear_page (l3_ro_mpt);l4e_write (&idle_pg_table[l4_table_offset (va)], -l4e_from_page (l3_pg, __PAGE_HYPERVISOR)); +l4e_from_page (l3_pg, __PAGE_HYPERVISOR_RW));Similarly here (again affecting the direct map).
Updated. The text now reads
* The PV GDT mappings and bits of the directmap don't need to be
executable.
My method of working out which areas to change were to consider all uses of __PAGE_HYPERVISOR. I have half a mind to submit a change renaming it to __PAGE_PGTABLE, as it should only really be used to build intermediate pagetable entries where we control X/NX, R/W or S/U at a more fine grained level.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 15:38, <[email protected]> wrote:
My method of working out which areas to change were to consider all uses of
__PAGE_HYPERVISOR. I have half a mind to submit a change renaming it to__PAGE_PGTABLE, as it should only really be used to build intermediate pagetable entries where we control X/NX, R/W or S/U at a more fine grained level.
Yeah, getting rid of that overly permissive __PAGE_HYPERVISOR would likely be a good thing.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
As originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
Quoted 8 lines
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.Reported-by Jann Horn <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
In reply to Andrew CooperHi,
Quoted 8 lines · Andrew Cooper
As originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
Quoted 8 lines
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.Reported-by Jann Horn <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 3/7] x86/mm: Further restrict permissions on some virtual mappings
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
As originally reported, the Linear Pagetable slot maps 512GB of ram as RWX, where the guest has full read access and a lot of direct or indirect control over the written content. It isn't hard for a PV guest to hide shellcode here.
Therefore, increase defence in depth by auditing our current pagetable mappings.
Quoted 8 lines
* The regular linear, shadow linear, and per-domain slots have no business being executable (but need to be written), so are updated to be NX.
* The Read Only mappings of the M2P (compat and regular) don't need to be writeable or executable.
* The PV GDT mappings don't need to be executable.Reported-by Jann Horn <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/7 x86/traps: Rename compat_hypercall() to entry_int82()
In reply to Andrew CooperThis follows the Linux example of naming the entry point by how it is arrived at, rather than its purpose.
Doing so highlights that the SAVE_VOLATILE instantiation sets up the wrong entry_vector on the stack (although this is benign as we never sysret to a 32bit PV guest, and the iret path doesn't care).
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_64/compat/entry.S | 4 ++-- xen/include/asm-x86/processor.h | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/traps.c +1 -1
@@ -3872,7 +3872,7 @@ void __init trap_init(void)/* The 32-on-64 hypercall vector is only accessible from ring 1. */ _set_gate (idt_table +HYPERCALL_VECTOR , - SYS_DESC_trap_gate,1 , &compat_hypercall); + SYS_DESC_trap_gate,1 , &entry_int82);/* Fast trap for int80 (faster than taking the #GP-fixup path). */ _set_gate (idt_table +0x80 , SYS_DESC_trap_gate,3 , &int80_direct_trap);
xen/arch/x86/x86_64/compat/entry.S +2 -2
@@ -11,10 +11,10 @@ #include <public/xen.h> #include <irq_vectors.h> -ENTRY(compat_hypercall) +ENTRY(entry_int82) ASM_CLAC pushq $0 - SAVE_VOLATILE type=TRAP_syscall compat=1 + SAVE_VOLATILE type=HYPERCALL_VECTOR compat=1 CR4_PV32_RESTORE cmpb $0,untrusted_msi(%rip)
xen/include/asm-x86/processor.h +2 -1
@@ -529,6 +529,8 @@ DECLARE_TRAP_HANDLER(simd_coprocessor_error);DECLARE_TRAP_HANDLER_CONST (machine_check);DECLARE_TRAP_HANDLER (alignment_check); +DECLARE_TRAP_HANDLER (entry_int82); +#undef DECLARE_TRAP_HANDLER_CONST#undef DECLARE_TRAP_HANDLER
@@ -538,7 +540,6 @@ void do_reserved_trap(struct cpu_user_regs *regs);void sysenter_entry (void );void sysenter_eflags_saved (void ); -void compat_hypercall (void );void int80_direct_trap (void );#define STUBS_PER_PAGE (PAGE_SIZE / STUB_BUF_SIZE)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 4/7] x86/traps: Rename compat_hypercall() to entry_int82()
xen/arch/x86/traps.c void __init trap_init(void) · line 3875
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/traps.c +1
-1@@ -3872,7 +3872,7 @@ void __init trap_init(void)/* The 32-on-64 hypercall vector is only accessible from ring 1. */ _set_gate (idt_table +HYPERCALL_VECTOR , - SYS_DESC_trap_gate,1 , &compat_hypercall); + SYS_DESC_trap_gate,1 , &entry_int82);
Would you mind at once dropping the unnecessary & ?
xen/include/asm-x86/processor.h DECLARE_TRAP_HANDLER(simd_coprocessor_error); · line 532
Quoted 7 lines
xen/include/asm-x86/processor.h +1
-0@@ -529,6 +529,8 @@ DECLARE_TRAP_HANDLER(simd_coprocessor_error);DECLARE_TRAP_HANDLER_CONST (machine_check);DECLARE_TRAP_HANDLER (alignment_check); +DECLARE_TRAP_HANDLER (entry_int82);
This is inappropriate, I think: There's no do_entry_int82. With this changed to a simply void entry_int82(void) declaration
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 4/7] x86/traps: Rename compat_hypercall() to entry_int82()
Quoted 10 lines · Jan Beulich
xen/arch/x86/traps.c void __init trap_init(void) · line 3875
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/traps.c +1
-1@@ -3872,7 +3872,7 @@ void __init trap_init(void)/* The 32-on-64 hypercall vector is only accessible from ring 1. */ _set_gate (idt_table +HYPERCALL_VECTOR , - SYS_DESC_trap_gate,1 , &compat_hypercall); + SYS_DESC_trap_gate,1 , &entry_int82);Would you mind at once dropping the unnecessary & ?
Fixed.
Quoted 7 lines
Quoted 7 lines
xen/include/asm-x86/processor.h +0
-0@@ -529,6 +529,8 @@ DECLARE_TRAP_HANDLER(simd_coprocessor_error);DECLARE_TRAP_HANDLER_CONST (machine_check);DECLARE_TRAP_HANDLER (alignment_check);
Quoted 5 lines
xen/include/asm-x86/processor.h DECLARE_TRAP_HANDLER(simd_coprocessor_error); · line 532
Quoted 1 line
xen/include/asm-x86/processor.h +1
-0+DECLARE_TRAP_HANDLER (entry_int82);This is inappropriate, I think: There's no
do_entry_int82. With this changed to a simply voidentry_int82(void)declarationReviewed-by Jan Beulich <[email protected]>
I hadn't even realised I had split the introduction of the two functions across two patches, but I'd prefer to keep them split like this and I will ensure that this gets committed at the same time as the following patch.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/7 x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
In reply to Andrew CooperThis is more readable, maintainable, and livepatchable.
This involves declaring check_for_unexpected_msi(), untrusted_msi and pv_hypercall() suitably for use by C. While making these changes, untrusted_msi is switched over to being a C99 bool.
No behavioural change.
---
CC: Jan Beulich <[email protected]>
--- xen/arch/x86/pv/Makefile | 2 ++ xen/arch/x86/pv/traps.c | 44 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 9 +------- xen/drivers/passthrough/vtd/iommu.c | 4 ++-- xen/include/asm-x86/apic.h | 1 + xen/include/asm-x86/hypercall.h | 4 ++++ xen/include/asm-x86/iommu.h | 2 ++ 7 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 xen/arch/x86/pv/traps.c
xen/arch/x86/pv/Makefile +2 -0
@@ -1,2 +1,4 @@ obj-y += hypercall.o +obj-y += traps.o + obj-bin-y += dom0_build.init.o
xen/arch/x86/pv/traps.c new file +44 -0
44 lines not on this page · raw message
xen/arch/x86/x86_64/compat/entry.S +1 -8
@@ -17,17 +17,10 @@ ENTRY(entry_int82) SAVE_VOLATILE type=HYPERCALL_VECTOR compat=1 CR4_PV32_RESTORE - cmpb $0,untrusted_msi(%rip) -UNLIKELY_START(ne, msi_check) - movl $HYPERCALL_VECTOR,%edi - call check_for_unexpected_msi - LOAD_C_CLOBBERED compat=1 ax=0 -UNLIKELY_END(msi_check) - GET_CURRENT(bx) mov %rsp, %rdi - call pv_hypercall + call do_entry_int82 /* %rbx: struct vcpu */ ENTRY(compat_test_all_events)
xen/drivers/passthrough/vtd/iommu.c +2 -2
@@ -48,7 +48,7 @@ struct mapped_rmrr { };/* Possible unfiltered LAPIC/MSI messages from untrusted sources? */ -bool_t __read_mostly untrusted_msi; +bool __read_mostly untrusted_msi;int nr_iommus;
@@ -2334,7 +2334,7 @@ static int reassign_device_ownership(* by the root complex unless interrupt remapping is enabled. */ if ( (target != hardware_domain) && !iommu_intremap ) - untrusted_msi =1 ; + untrusted_msi = true;/* * If the device belongs to the hardware domain, and it has RMRR, don't
xen/include/asm-x86/apic.h +1 -0
@@ -213,6 +213,7 @@ extern int lapic_suspend(void);extern int lapic_resume (void );extern void record_boot_APIC_mode (void );extern enum apic_mode current_local_apic_mode (void ); +extern void check_for_unexpected_msi (unsigned int vector);extern int check_nmi_watchdog (void );
xen/include/asm-x86/hypercall.h +4 -0
@@ -25,6 +25,10 @@ typedef struct {extern const hypercall_args_t hypercall_args_table[NR_hypercalls]; +#ifdef CONFIG_PV +void pv_hypercall (struct cpu_user_regs *regs); +#endif +/* * Both do_mmuext_op() and do_mmu_update(): * We steal the m.s.b. of the @count parameter to indicate whether this
xen/include/asm-x86/iommu.h +2 -0
@@ -92,6 +92,8 @@ bool_t iommu_supports_eim(void);int iommu_enable_x2apic_IR (void );void iommu_disable_x2apic_IR (void ); +extern bool untrusted_msi; +int pi_update_irte (const struct pi_desc *pi_desc,const struct pirq *pirq,const uint8_t gvec);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +16
-0@@ -0,0 +1,44 @@ +/****************************************************************************** +* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License
xen/arch/x86/pv/traps.c line 26
Quoted 10 lines
xen/arch/x86/pv/traps.c new file +10
-0+* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT
As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
xen/arch/x86/pv/traps.c line 27
Quoted 1 line
xen/arch/x86/pv/traps.c new file +1
-0+void do_entry_int82 (struct cpu_user_regs *regs)
Ah, so here we go. If this and patch 4 get committed together, I withdraw my declaration specific change request on that other patch.
xen/include/asm-x86/hypercall.h typedef struct { · line 30
Quoted 9 lines
xen/include/asm-x86/hypercall.h +3
-0@@ -25,6 +25,10 @@ typedef struct {extern const hypercall_args_t hypercall_args_table[NR_hypercalls]; +#ifdef CONFIG_PV +void pv_hypercall (struct cpu_user_regs *regs); +#endif
Are such #ifdef-s really useful? Having the declaration does no harm, linking would fail if the config setting is off.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +21
-0@@ -0,0 +1,44 @@ +/****************************************************************************** +* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ +
Quoted 9 lines
xen/arch/x86/pv/traps.c line 26
Quoted 5 lines
xen/arch/x86/pv/traps.c new file +5
-0+#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 34 lines · Wei Liu
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +20
-0@@ -0,0 +1,44 @@ +/****************************************************************************** +* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ Quoted 9 lines
xen/arch/x86/pv/traps.c line 26
Quoted 6 lines
xen/arch/x86/pv/traps.c new file +6
-0+ +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
Quoted 3 lines
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
There is a valid usecase to disable CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 35 lines · Andrew Cooper
Quoted 34 lines · Wei Liu
Quoted 33 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +16
-0@@ -0,0 +1,44 @@ +/****************************************************************************** +* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License xen/arch/x86/pv/traps.c line 26
Quoted 10 lines
xen/arch/x86/pv/traps.c new file +10
-0+* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
Quoted 8 lines
Quoted 3 lines
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
There is a valid usecase to disable
CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.
I agree.
Quoted 7 lines
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
Yes, I think a proper discussion is needed to clarify the future direction.
Wei.
Quoted 1 line
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
In reply to Andrew CooperQuoted 38 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 13:38, <[email protected]> wrote:
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
xen/arch/x86/pv/traps.c
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +0
-0@@ -0,0 +1,44 @@+/***************************************************************************
***Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
xen/arch/x86/pv/traps.c new file +15
-0+* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License xen/arch/x86/pv/traps.c line 26
Quoted 10 lines
xen/arch/x86/pv/traps.c new file +10
-0+* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
Quoted 7 lines
Quoted 3 lines
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
There is a valid usecase to disable
CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.
What does PVH have to do with 32-bit PV compat guest support?
Quoted 6 lines
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
Once again - from common code perspective this is a valid config option to have. X86, however, unconditionally selects it, so there's no point having such conditionals in x86 code.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 38 lines · Jan Beulich
Quoted 38 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 13:38, <[email protected]> wrote:
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
xen/arch/x86/pv/traps.c
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +0
-0@@ -0,0 +1,44 @@+/***************************************************************************
***Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
xen/arch/x86/pv/traps.c new file +15
-0+* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License xen/arch/x86/pv/traps.c line 26
Quoted 10 lines
xen/arch/x86/pv/traps.c new file +10
-0+* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ + +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
There is a valid usecase to disable
CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.What does PVH have to do with 32-bit PV compat guest support?
Nothing. I am unsure as to why do you think it does?
The CONFIG_COMPAT infrastructure by HVM guests as well.
Quoted 10 lines
Quoted 7 lines
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
Once again - from common code perspective this is a valid config option to have. X86, however, unconditionally selects it, so there's no point having such conditionals in x86 code.
I don't agree with this reasoning. If it is a reasonable configuration for common code to use, it is a reasonable configuration for x86 code to use.
Or do you disagree with my argument for why it should be a configurable option which can be turned off in an x86 build?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 14:18, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 13:38, <[email protected]> wrote:
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
xen/arch/x86/pv/traps.c
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +0
-0@@ -0,0 +1,44 @@+/***************************************************************************
Quoted 32 lines
Quoted 32 lines
***
Quoted 31 lines
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/pv/traps.c new file +19
-0+* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ Quoted 9 lines
xen/arch/x86/pv/traps.c line 26
Quoted 6 lines
xen/arch/x86/pv/traps.c new file +6
-0+ +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
There is a valid usecase to disable
CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.What does PVH have to do with 32-bit PV compat guest support?
Nothing. I am unsure as to why do you think it does?
The
CONFIG_COMPATinfrastructure by HVM guests as well.
A rather small part of it, if at all. And if HVM guests really use parts of it, we can't disable it without breaking such guests running (perhaps just temporarily) in 32-bit mode.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
Quoted 7 lines
Quoted 3 lines
Once again - from common code perspective this is a valid config option to have. X86, however, unconditionally selects it, so there's no point having such conditionals in x86 code.
I don't agree with this reasoning. If it is a reasonable configuration for common code to use, it is a reasonable configuration for x86 code to use.
Depends: It's there in common code to skip the respective pieces of code for architectures not needing it. It used to be a meaningful option in x86 as long as there was a 32-bit hypervisor.
Quoted 2 lines
Or do you disagree with my argument for why it should be a configurable option which can be turned off in an x86 build?
Well, I'd first of all have to check again how much of this really is being used by HVM code. Hmm, looks like it's more than I did remember. But with all CONFIG_COMPAT uses gone from x86 code (minus the ones you introduced not very long ago), I don't see why you want to re-introduce a few more now. If we really want the option of disabling that code, a concerted effort should be made to re-add the conditionals wherever needed. Otherwise we'll end up with code where readers would legitimately ask why the conditionals are there in some places, but missing in many others. And no, I wouldn't view a patch like the one here as the beginning of a transitional period (as expressed before, I should have noticed and objected to the re-introduction of such #ifdef-s in your PV hypercall changes).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 72 lines · Jan Beulich
Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 14:18, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 13:38, <[email protected]> wrote:
Quoted 6 lines · Wei Liu
Quoted 5 lines · Jan Beulich
xen/arch/x86/pv/traps.c
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +0
-0@@ -0,0 +1,44 @@+/***************************************************************************
Quoted 31 lines
Quoted 31 lines
***
Quoted 30 lines
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/pv/traps.c new file +19
-0+* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ Quoted 9 lines
xen/arch/x86/pv/traps.c line 25
Quoted 6 lines
xen/arch/x86/pv/traps.c new file +6
-0+ +#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
I'm curious to know how the COMPAT interface is treated long term.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
I guess you're of the opinion that we should always have them enabled?
There is a valid usecase to disable
CONFIG_COMPAT, seeing as sufficient PVH interfaces exist to start APs straight in 64bit mode, as it provides a meaningful reduction in hypervisor attack surface.What does PVH have to do with 32-bit PV compat guest support?
Nothing. I am unsure as to why do you think it does?
The
CONFIG_COMPATinfrastructure by HVM guests as well.A rather small part of it, if at all. And if HVM guests really use parts of it, we can't disable it without breaking such guests running (perhaps just temporarily) in 32-bit mode.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
As it is a configurable option, I intend to work in a direction which eventually makes it usable under x86.
If there is a wish to move in an opposite direction, that should be a separate discussion made over a patch removing its entry from common/Kconfig.
Quoted 6 lines
Quoted 3 lines
Once again - from common code perspective this is a valid config option to have. X86, however, unconditionally selects it, so there's no point having such conditionals in x86 code.
I don't agree with this reasoning. If it is a reasonable configuration for common code to use, it is a reasonable configuration for x86 code to use.
Depends: It's there in common code to skip the respective pieces of code for architectures not needing it. It used to be a meaningful option in x86 as long as there was a 32-bit hypervisor.
Quoted 2 lines
Or do you disagree with my argument for why it should be a configurable option which can be turned off in an x86 build?
Quoted 13 lines
Well, I'd first of all have to check again how much of this really is being used by HVM code. Hmm, looks like it's more than I did remember. But with all
CONFIG_COMPATuses gone from x86 code (minus the ones you introduced not very long ago), I don't see why you want to re-introduce a few more now. If we really want the option of disabling that code, a concerted effort should be made to re-add the conditionals wherever needed. Otherwise we'll end up with code where readers would legitimately ask why the conditionals are there in some places, but missing in many others. And no, I wouldn't view a patch like the one here as the beginning of a transitional period (as expressed before, I should have noticed and objected to the re-introduction of such #ifdef-s in your PV hypercall changes).
The reason c/s de82feebf2c uses CONFIG_COMPAT is because of
struct mc_state {
unsigned long flags;
union {
struct multicall_entry call;
#ifdef CONFIG_COMPAT
struct compat_multicall_entry compat_call;
#endif
};
};being defined using CONFIG_COMPAT. It didn't even cross my mind that it might have been ok to allow the code to fail to compile if CONFIG_COMPAT was not selected. I therefore wrote code which matched the structure definition it was using.
Irrespective of the history which lead to this point, the important question is whether we want to allow compiling x86 without CONFIG_COMPAT.
If the eventual decision is yes, then new code should specifically be introduced as being CONFIG_COMPAT-clean, because decisions like that affect how to structure the code in the first place, and therefore be far cleaner changes than trying to retrofit CONFIG_COMPAT in the future.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 20:29, <[email protected]> wrote:
Irrespective of the history which lead to this point, the important question is whether we want to allow compiling x86 without
CONFIG_COMPAT.If the eventual decision is yes, then new code should specifically be introduced as being CONFIG_COMPAT-clean, because decisions like that affect how to structure the code in the first place, and therefore be far cleaner changes than trying to retrofit
CONFIG_COMPATin the future.
Well, okay, I can agree with this. So what would an x86-Xen with COMPAT off support? 64-bit guests only, regardless of type? As said before, I don't view it as a reasonable setup to allow only 64-bit HVM guests, so unless there is an intention to have a configuration where only PVH guests are supported (i.e. neither PV nor traditional HVM), I don't think allowing the option to be turned off makes sense on x86.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 10 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 20:29, <[email protected]> wrote:
Irrespective of the history which lead to this point, the important question is whether we want to allow compiling x86 without
CONFIG_COMPAT.If the eventual decision is yes, then new code should specifically be introduced as being CONFIG_COMPAT-clean, because decisions like that affect how to structure the code in the first place, and therefore be far cleaner changes than trying to retrofit
CONFIG_COMPATin the future.Well, okay, I can agree with this. So what would an x86-Xen with COMPAT off support? 64-bit guests only, regardless of type?
Yes. I intend this to mean 64bit guests of any type.
Quoted 5 lines
As said before, I don't view it as a reasonable setup to allow only 64-bit HVM guests, so unless there is an intention to have a configuration where only PVH guests are supported (i.e. neither PV nor traditional HVM), I don't think allowing the option to be turned off makes sense on x86.
HVM and PVH aren't very different, but there will be a small amount of work required to get plain HVM booting like this, because of hvmloader currently being 32bit only. I do see (potentially) value in allowing 64bit-only traditional HVM guests, e.g. with a 64bit OVMF firmware (although this is already turning fairly PVH in nature).
PVH on the other hand is already capable of booting and running properly were CONFIG_COMPAT to be disabled today.
The selection of CONFIG_PV, CONFIG_HVM and CONFIG_COMPAT will eventually define the matrix of which guests are supported in this build of the hypervisor, based on which chunks of functionality they compile out.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 04.05.17 at 11:27, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
As said before, I don't view it as a reasonable setup to allow only 64-bit HVM guests, so unless there is an intention to have a configuration where only PVH guests are supported (i.e. neither PV nor traditional HVM), I don't think allowing the option to be turned off makes sense on x86.
Quoted 5 lines
HVM and PVH aren't very different, but there will be a small amount of work required to get plain HVM booting like this, because of hvmloader currently being 32bit only. I do see (potentially) value in allowing 64bit-only traditional HVM guests, e.g. with a 64bit OVMF firmware (although this is already turning fairly PVH in nature).
So that would then be yet another construct with no raw hardware equivalent. I'd prefer if we strove for improving our compatibility with raw hardware (as we do in various other places, you being one of the primary advocates to do so) instead of inventing new custom environments. Furthermore, while I can see the benefit of e.g. not allowing PV guests for security reasons, I'm having a hard time imagining some security benefit from disallowing a HVM guest to run in 32-bit mode. But perhaps you've thought of something already...
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 12 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 04.05.17 at 11:27, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
As said before, I don't view it as a reasonable setup to allow only 64-bit HVM guests, so unless there is an intention to have a configuration where only PVH guests are supported (i.e. neither PV nor traditional HVM), I don't think allowing the option to be turned off makes sense on x86.
Quoted 5 lines
HVM and PVH aren't very different, but there will be a small amount of work required to get plain HVM booting like this, because of hvmloader currently being 32bit only. I do see (potentially) value in allowing 64bit-only traditional HVM guests, e.g. with a 64bit OVMF firmware (although this is already turning fairly PVH in nature).
Quoted 8 lines
So that would then be yet another construct with no raw hardware equivalent. I'd prefer if we strove for improving our compatibility with raw hardware (as we do in various other places, you being one of the primary advocates to do so) instead of inventing new custom environments. Furthermore, while I can see the benefit of e.g. not allowing PV guests for security reasons, I'm having a hard time imagining some security benefit from disallowing a HVM guest to run in 32-bit mode. But perhaps you've thought of something already...
Hmm. It might be nice to be able to compile out 32bit PV without excluding 32bit HVM.
The security gain for COMPAT HVM guests is fractional, compared to PV, but is non-zero; we have had infinite loops in the compat translation code before.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
In reply to Wei LiuQuoted 39 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 13:26, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
xen/arch/x86/pv/traps.c
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/arch/x86/pv/traps.c new file +0
-0@@ -0,0 +1,44 @@+/***************************************************************************
***Quoted 20 lines
Quoted 20 lines
xen/arch/x86/pv/traps.c new file +20
-0+* arch/x86/pv/traps.c +* +* PV low level entry points. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* +* Copyright (c) 2017 Citrix Systems Ltd. +*/ +Quoted 9 lines
xen/arch/x86/pv/traps.c line 26
Quoted 5 lines
xen/arch/x86/pv/traps.c new file +5
-0+#include <xen/hypercall.h> + +#include <asm/apic.h> + +#ifdef CONFIG_COMPAT As expressed before, I disagree to the re-introduction of such conditionals in x86 code.
Quoted 3 lines
I'm curious to know how the COMPAT interface is treated long term.
I guess you're of the opinion that we should always have them enabled?
Yes, that's why all of its uses in x86 code had been removed (until Andrew recently re-introduced some).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 5/7 x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
In reply to Jan BeulichThis is more readable, maintainable, and livepatchable.
This involves declaring check_for_unexpected_msi(), untrusted_msi and pv_hypercall() suitably for use by C. While making these changes, untrusted_msi is switched over to being a C99 bool.
No behavioural change.
---
CC: Jan Beulich <[email protected]>
v2:
* Drop ifdefary for now
--- xen/arch/x86/pv/Makefile | 2 ++ xen/arch/x86/pv/traps.c | 42 +++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/entry.S | 9 +------- xen/drivers/passthrough/vtd/iommu.c | 4 ++-- xen/include/asm-x86/apic.h | 1 + xen/include/asm-x86/hypercall.h | 2 ++ xen/include/asm-x86/iommu.h | 2 ++ 7 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 xen/arch/x86/pv/traps.c
xen/arch/x86/pv/Makefile +2 -0
@@ -1,2 +1,4 @@ obj-y += hypercall.o +obj-y += traps.o + obj-bin-y += dom0_build.init.o
xen/arch/x86/pv/traps.c new file +42 -0
42 lines not on this page · raw message
xen/arch/x86/x86_64/compat/entry.S +1 -8
@@ -17,17 +17,10 @@ ENTRY(entry_int82) SAVE_VOLATILE type=HYPERCALL_VECTOR compat=1 CR4_PV32_RESTORE - cmpb $0,untrusted_msi(%rip) -UNLIKELY_START(ne, msi_check) - movl $HYPERCALL_VECTOR,%edi - call check_for_unexpected_msi - LOAD_C_CLOBBERED compat=1 ax=0 -UNLIKELY_END(msi_check) - GET_CURRENT(bx) mov %rsp, %rdi - call pv_hypercall + call do_entry_int82 /* %rbx: struct vcpu */ ENTRY(compat_test_all_events)
xen/drivers/passthrough/vtd/iommu.c +2 -2
@@ -48,7 +48,7 @@ struct mapped_rmrr { };/* Possible unfiltered LAPIC/MSI messages from untrusted sources? */ -bool_t __read_mostly untrusted_msi; +bool __read_mostly untrusted_msi;int nr_iommus;
@@ -2334,7 +2334,7 @@ static int reassign_device_ownership(* by the root complex unless interrupt remapping is enabled. */ if ( (target != hardware_domain) && !iommu_intremap ) - untrusted_msi =1 ; + untrusted_msi = true;/* * If the device belongs to the hardware domain, and it has RMRR, don't
xen/include/asm-x86/apic.h +1 -0
@@ -213,6 +213,7 @@ extern int lapic_suspend(void);extern int lapic_resume (void );extern void record_boot_APIC_mode (void );extern enum apic_mode current_local_apic_mode (void ); +extern void check_for_unexpected_msi (unsigned int vector);extern int check_nmi_watchdog (void );
xen/include/asm-x86/hypercall.h +2 -0
@@ -25,6 +25,8 @@ typedef struct {extern const hypercall_args_t hypercall_args_table[NR_hypercalls]; +void pv_hypercall (struct cpu_user_regs *regs); +/* * Both do_mmuext_op() and do_mmu_update(): * We steal the m.s.b. of the @count parameter to indicate whether this
xen/include/asm-x86/iommu.h +2 -0
@@ -92,6 +92,8 @@ bool_t iommu_supports_eim(void);int iommu_enable_x2apic_IR (void );void iommu_disable_x2apic_IR (void ); +extern bool untrusted_msi; +int pi_update_irte (const struct pi_desc *pi_desc,const struct pirq *pirq,const uint8_t gvec);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 9 lines · Andrew Cooper
This is more readable, maintainable, and livepatchable.
This involves declaring
check_for_unexpected_msi(),untrusted_msiandpv_hypercall()suitably for use by C. While making these changes,untrusted_msiis switched over to being a C99 bool.No behavioural change.
Signed-off-by Andrew Cooper <[email protected]>
Actually, in addition, I think the following change should be folded in.
andrewcoop@andrewcoop:/local/xen.git/xen$ git diff
(quoted diff) +0 -0
b/xen/arch/x86/x86_64/compat/entry.S
index 90bda09..51b1c257 100644
xen/arch/x86/x86_64/compat/entry.S +1 -0
@@ -21,6 +21,7 @@ ENTRY(entry_int82) mov %rsp, %rdi call do_entry_int82 + jmp compat_test_all_events /* %rbx: struct vcpu */ ENTRY(compat_test_all_events)
This only currently works because the ALIGN hidden in ENTRY() happens to be safe to execute through, but we shouldn't rely on this, and a single predicted jump is probably faster to execute than a line of single-byte nops.
Thoughts?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 04.05.17 at 12:16, <[email protected]> wrote:
On 04/05/17 11:01, Andrew Cooper wrote:
xen/arch/x86/x86_64/compat/entry.S +1
-0@@ -21,6 +21,7 @@ ENTRY(entry_int82) mov %rsp, %rdi call do_entry_int82 + jmp compat_test_all_events /* %rbx: struct vcpu */ ENTRY(compat_test_all_events)
Quoted 2 lines
This only currently works because the ALIGN hidden in
ENTRY()happens to be safe to execute through, but we shouldn't rely on this,
Why not? ALIGN is the way it is for a reason.
Quoted 2 lines
and a single predicted jump is probably faster to execute than a line of single-byte nops.
I'm not sure about this, but it's possible. A question is whether we really should force 0x90 fillers in ALIGN, rather than having the assembler use multi-bytes NOPs when suitable.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 04.05.17 at 12:16, <[email protected]> wrote:
On 04/05/17 11:01, Andrew Cooper wrote:
xen/arch/x86/x86_64/compat/entry.S +1
-0@@ -21,6 +21,7 @@ ENTRY(entry_int82) mov %rsp, %rdi call do_entry_int82 + jmp compat_test_all_events
Quoted 7 lines
Quoted 6 lines
xen/arch/x86/x86_64/compat/entry.S +0
-0/* %rbx: struct vcpu */ ENTRY(compat_test_all_events)This only currently works because the ALIGN hidden in
ENTRY()happens to be safe to execute through, but we shouldn't rely on this,Why not? ALIGN is the way it is for a reason.
It still doesn't strike me as a safe or sensible thing to rely on, and will become forbidden if/when we decide to borrow some of the objtool improvements from Linux.
Quoted 6 lines
Quoted 3 lines
and a single predicted jump is probably faster to execute than a line of single-byte nops.
I'm not sure about this, but it's possible. A question is whether we really should force
0x90fillers in ALIGN, rather than having the assembler use multi-bytes NOPs when suitable.
I've been experimenting and it appears that some ALIGNs are reduced to multibyte nops, while others aren't. I can't find any consistency.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 5/7] x86/traps: Lift all non-entrypoint logic in entry_int82() up into C
In reply to Andrew CooperQuoted 10 lines
Quoted 1 line
Quoted 1 line · On 04.05.17 at 12:01, <[email protected]> wrote:
This is more readable, maintainable, and livepatchable.
This involves declaring
check_for_unexpected_msi(),untrusted_msiandpv_hypercall()suitably for use by C. While making these changes,untrusted_msiis switched over to being a C99 bool.No behavioural change.
Signed-off-by Andrew Cooper <[email protected]>
without the subsequently suggested adjustment; I'll reply there.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/7 x86/asm: Fold LOAD_C_CLOBBERED into RESTORE_ALL
In reply to Andrew CooperWith its sole other user removed, fold LOAD_C_CLOBBERED into RESTORE_ALL to reduce the cognitive load of trying to work out which registers get modified.
No functional change.
---
CC: Jan Beulich <[email protected]>
--- xen/include/asm-x86/asm_defns.h | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-)
xen/include/asm-x86/asm_defns.h +6 -21
@@ -321,40 +321,25 @@ static always_inline void stac(void) .endif /* - * Reload registers not preserved by C code from frame. - * - * @compat: R8-R11 don't need reloading + * Restore all previously saved registers. * - * For the way it is used in RESTORE_ALL, this macro must preserve EFLAGS.ZF. + * @adj: extra stack pointer adjustment to be folded into the adjustment done + * anyway at the end of the macro + * @compat: R8-R15 don't need reloading */ -.macro LOAD_C_CLOBBERED compat=0 ax=1 +.macro RESTORE_ALL adj=0 compat=0 .if !\compat + testl $TRAP_regs_dirty,UREGS_entry_vector(%rsp) movq UREGS_r11(%rsp),%r11 movq UREGS_r10(%rsp),%r10 movq UREGS_r9(%rsp),%r9 movq UREGS_r8(%rsp),%r8 .endif -.if \ax LOAD_ONE_REG(ax, \compat) -.endif LOAD_ONE_REG(cx, \compat) LOAD_ONE_REG(dx, \compat) LOAD_ONE_REG(si, \compat) LOAD_ONE_REG(di, \compat) -.endm - -/* -* Restore all previously saved registers. -* -* @adj: extra stack pointer adjustment to be folded into the adjustment done -* anyway at the end of the macro -* @compat: R8-R15 don't need reloading -*/ -.macro RESTORE_ALL adj=0 compat=0 -.if !\compat - testl $TRAP_regs_dirty,UREGS_entry_vector(%rsp) -.endif - LOAD_C_CLOBBERED \compat .if !\compat jz 987f movq UREGS_r15(%rsp),%r15
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 6/7] x86/asm: Fold LOAD_C_CLOBBERED into RESTORE_ALL
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
With its sole other user removed, fold
LOAD_C_CLOBBEREDintoRESTORE_ALLto reduce the cognitive load of trying to work out which registers get modified.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 6/7] x86/asm: Fold LOAD_C_CLOBBERED into RESTORE_ALL
In reply to Andrew CooperQuoted 6 lines · Andrew Cooper
With its sole other user removed, fold
LOAD_C_CLOBBEREDintoRESTORE_ALLto reduce the cognitive load of trying to work out which registers get modified.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 7/7 x86/asm: Clobber %r{8..15} on exit to 32bit PV guests
In reply to Andrew CooperIn the presence of bugs such as XSA-214 where a 32bit PV guest can get its hands on a long mode segment, this change prevents register content leaking between domains.
---
CC: Jan Beulich <[email protected]>
--- xen/include/asm-x86/asm_defns.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
xen/include/asm-x86/asm_defns.h +12 -1
@@ -325,7 +325,8 @@ static always_inline void stac(void)* * @adj: extra stack pointer adjustment to be folded into the adjustment done * anyway at the end of the macro -* @compat: R8-R15 don't need reloading +* @compat: R8-R15 don't need reloading, but they are clobbered for added +* safety against information leaks. */ .macro RESTORE_ALL adj=0 compat=0 .if !\compat
@@ -366,6 +367,16 @@ static always_inline void stac(void) LOAD_ONE_REG(bp, \compat) LOAD_ONE_REG(bx, \compat) subq $-(UREGS_error_code-UREGS_r15+\adj), %rsp +.if \compat + xor %r8d, %r8d + xor %r9d, %r9d + xor %r10d, %r10d + xor %r11d, %r11d + xor %r12d, %r12d + xor %r13d, %r13d + xor %r14d, %r14d + xor %r15d, %r15d +.endif .endm#endif
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 7/7] x86/asm: Clobber %r{8..15} on exit to 32bit PV guests
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.05.17 at 20:05, <[email protected]> wrote:
xen/include/asm-x86/asm_defns.h +1
-0@@ -366,6 +367,16 @@ static always_inline void stac(void) LOAD_ONE_REG(bp, \compat) LOAD_ONE_REG(bx, \compat) subq $-(UREGS_error_code-UREGS_r15+\adj), %rsp +.if \compat
xen/include/asm-x86/asm_defns.h static always_inline void stac(void) · line 380
Quoted 10 lines
xen/include/asm-x86/asm_defns.h +9
-0+ xor %r8d, %r8d + xor %r9d, %r9d + xor %r10d, %r10d + xor %r11d, %r11d + xor %r12d, %r12d + xor %r13d, %r13d + xor %r14d, %r14d + xor %r15d, %r15d +.endif .endm
Rather than having yet another .if, I think this would better be the .else to one of the existing ones. Possibly even two .else-s, one each for the R8-R11 and R12-R15 register ranges.
Also the d suffixes on the register names are pretty pointless here, as a REX prefix is going to be needed anyway.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 7/7 x86/asm: Clobber %r{8..15} on exit to 32bit PV guests
In the presence of bugs such as XSA-214 where a 32bit PV guest can get its hands on a long mode segment, this change prevents register content leaking between domains.
---
CC: Jan Beulich <[email protected]>
v2:
* Move to being in .else clauses
--- xen/include/asm-x86/asm_defns.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
xen/include/asm-x86/asm_defns.h +12 -1
@@ -325,7 +325,8 @@ static always_inline void stac(void)* * @adj: extra stack pointer adjustment to be folded into the adjustment done * anyway at the end of the macro -* @compat: R8-R15 don't need reloading +* @compat: R8-R15 don't need reloading, but they are clobbered for added +* safety against information leaks. */ .macro RESTORE_ALL adj=0 compat=0 .if !\compat
@@ -334,6 +335,11 @@ static always_inline void stac(void) movq UREGS_r10(%rsp),%r10 movq UREGS_r9(%rsp),%r9 movq UREGS_r8(%rsp),%r8 +.else + xor %r11, %r11 + xor %r10, %r10 + xor %r9, %r9 + xor %r8, %r8 .endif LOAD_ONE_REG(ax, \compat) LOAD_ONE_REG(cx, \compat)
@@ -361,6 +367,11 @@ static always_inline void stac(void) 789: BUG /* Corruption of partial register state. */ .subsection 0 #endif +.else + xor %r15, %r15 + xor %r14, %r14 + xor %r13, %r13 + xor %r12, %r12 .endif 987: LOAD_ONE_REG(bp, \compat)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 7/7] x86/asm: Clobber %r{8..15} on exit to 32bit PV guests
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 03.05.17 at 19:51, <[email protected]> wrote:
In the presence of bugs such as XSA-214 where a 32bit PV guest can get its hands on a long mode segment, this change prevents register content leaking between domains.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines · Andrew Cooper
Various improvements based on observations while investigating and fixing the aformentioned XSAs. All are candidate patches for 4.9 at this point, with patches 2, 3 and 7 being the important ones from an attack-surface-mitigation point of view.
This is the subset of my intented series, but I haven't had time to finish the rest of the work I wanted to do, which clearly makes it post 4.9 work at this point.
Julien: I have v2 of this series now fully reviewed/acked.
I'd like to request them for inclusion into 4.9 at this point (unless there are any last minute objections from other maintainers).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Andrew,
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Andrew Cooper
Various improvements based on observations while investigating and fixing the aformentioned XSAs. All are candidate patches for 4.9 at this point, with patches 2, 3 and 7 being the important ones from an attack-surface-mitigation point of view.
Quoted 8 lines
Quoted 3 lines
This is the subset of my intented series, but I haven't had time to finish the rest of the work I wanted to do, which clearly makes it post 4.9 work at this point.
Julien: I have v2 of this series now fully reviewed/acked.
I'd like to request them for inclusion into 4.9 at this point (unless there are any last minute objections from other maintainers).
I agree that mitigating the attack-surface is important for Xen 4.9:
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel