Xen Security Advisory 298 v3 (CVE-2019-18425) - missing descriptor table limit checking in x86 PV emulation
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Xen Security Advisory CVE-2019-18425 / XSA-298
version 3
missing descriptor table limit checking in x86 PV emulation
UPDATES IN VERSION 3
====================
Public release.
ISSUE DESCRIPTION
=================
When emulating certain PV guest operations, descriptor table accesses are performed by the emulating code. Such accesses should respect the guest specified limits, unless otherwise guaranteed to fail in such a case. Without this, emulation of 32-bit guest user mode calls through call gates would allow guest user mode to install and then use descriptors of their choice, as long as the guest kernel did not itself install an LDT. (Most OSes don't install any LDT by default).
IMPACT
======
32-bit PV guest user mode can elevate its privileges to that of the guest kernel.
VULNERABLE SYSTEMS
==================
Xen versions from at least 3.2 onwards are affected.
Only 32-bit PV guest user mode can leverage this vulnerability.
HVM, PVH, as well as 64-bit PV guests cannot leverage this vulnerability.
Arm systems are unaffected.
MITIGATION
==========
Running only HVM, PVH, or 64-bit PV guests will avoid this vulnerability.
CREDITS
=======
This issue was discovered by Andrew Cooper of Citrix.
RESOLUTION
==========
Applying the appropriate attached patch resolves this issue.
xsa298.patch xen-unstable, Xen 4.12.x xsa298-4.11.patch Xen 4.11.x xsa298-4.10.patch Xen 4.10.x xsa298-4.9.patch Xen 4.9.x, Xen 4.8.x, Xen 4.7.x
$ sha256sum xsa298* 82c6f626732f99711212155b280270fe2f6683460299b1a6fc3f70b3932970ce xsa298.meta 3f422ad83abb54fe6afed460a5982cf1faa1717e51ab19fbf2375be1b5f8f4a3 xsa298.patch da8d5bad97a46c072dd1715c96401b145cecda14f0303043e6dca313e7ffff0c xsa298-4.9.patch 92dba14b6a208379c2569b9c1c11438da384ec47db2508b4761af30d74a9403d xsa298-4.10.patch d2d8eb5de5601b88f2a6503ecf6bb83207e4b2f17833d61a74fcd185ac7f5a71 xsa298-4.11.patch $
DEPLOYMENT DURING EMBARGO
=========================
Deployment of the patches and/or mitigations described above (or others which are substantially similar) is permitted during the embargo, even on public-facing systems with untrusted guest users and administrators.
But: Distribution of updated software is prohibited (except to other members of the predisclosure list).
Predisclosure list members who wish to deploy significantly different patches and/or mitigations, please contact the Xen Project Security Team.
(Note: this during-embargo deployment notice is retained in post-embargo publicly released Xen Project advisories, even though it is then no longer applicable. This is to enable the community to have oversight of the Xen Project Security Team's decisionmaking.)
For more information about permissible uses of embargoed information, consult the Xen Project community's agreed Security Policy:
http://www.xenproject.org/security-policy.html
-----BEGIN PGP SIGNATURE-----
iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAl2601AMHHBncEB4ZW4u b3JnAAoJEIP+FMlX6CvZk/AH/iLP9TpdOKNoW8fJDuOjlIQHsI0RPtU6KIdSc1a8 nzrcPfwpdP3/89GJQyEHwi5ZZdXAnNcXSK7BC+EEzqznV/VwHRDusCBH0enjUe0z jDpOsxeI5RsuyJnSFojhI2E+y1khjKtVvnbNWbHzBfWMPD9Inc+nw9Q1KWfpSkk6 TTS8OwR9DwNiVXz9Na+BKuIBOVinFd1wA+HBNZKJl3JCz8N0Oa6RHDKFQQKJ4Uy2 KzBdzm5dWr0xP4stQmnYoU7JobGbcvKyMVMwwryS3cffLyhOLuzCWjDO+n7RkoRy xWmGWVeQWAeIzqvvtb104NrHSVwVeFSOsen0cqFLvV82MRw=
=tmUK
-----END PGP SIGNATURE-----
From: Jan Beulich <[email protected]>
Subject: x86/PV: check GDT/LDT limits during emulation
Accesses beyond the LDT limit originating from emulation would trigger the ASSERT() in pv_map_ldt_shadow_page(). On production builds such accesses would cause an attempt to promote the touched page (offset from the present LDT base address) to a segment descriptor one. If this happens to succeed, guest user mode would be able to elevate its privileges to that of the guest kernel. This is particularly easy when there's no LDT at all, in which case the LDT base stored internally to Xen is simply zero.
Also adjust the ASSERT() that was triggering: It was off by one to begin with, and for production builds we also better use ASSERT_UNREACHABLE() instead with suitable recovery code afterwards.
This is XSA-298.
---
v2: Correct 64-bit-only limit check (by folding into the common one).
xen/arch/x86/pv/emul-gate-op.c +8 -2
@@ -51,7 +51,13 @@ static int read_gate_descriptor(unsignedconst seg_desc_t *pdesc =gdt_ldt_desc_ptr (gate_sel);if ( (gate_sel <4 ) || - ((gate_sel >=FIRST_RESERVED_GDT_BYTE ) && !(gate_sel &4 )) || +/* +* We're interested in call gates only, which occupy a single +* seg_desc_t for 32-bit and a consecutive pair of them for 64-bit. +*/ + ((gate_sel >>3 ) + !is_pv_32bit_vcpu (v) >= + (gate_sel &4 ? v->arch.pv.ldt_ents + : v->arch.pv.gdt_ents)) ||__get_user (desc, pdesc) )return 0 ;
@@ -70,7 +76,7 @@ static int read_gate_descriptor(unsignedif ( !is_pv_32bit_vcpu (v) ) {if ( (*ar &0x1f00 ) !=0x0c00 || - (gate_sel >=FIRST_RESERVED_GDT_BYTE -8 && !(gate_sel &4 )) || +/* Limit check done above already. */ __get_user (desc, pdesc +1 ) || (desc.b &0x1f00 ) )return 0 ;
xen/arch/x86/pv/emulate.c +8 -1
@@ -31,7 +31,14 @@ int pv_emul_read_descriptor(unsigned int {seg_desc_t desc; -if ( sel <4 ) +if ( sel <4 || +/* +* Don't apply the GDT limit here, as the selector may be a Xen +* provided one. __get_user() will fail (without taking further +* action) for ones falling in the gap between guest populated +* and Xen ones. +*/ + ((sel &4 ) && (sel >>3 ) >= v->arch.pv.ldt_ents) ) desc.b = desc.a =0 ;else if (__get_user (desc,gdt_ldt_desc_ptr (sel)) )return 0 ;
xen/arch/x86/pv/mm.c +6 -2
@@ -92,12 +92,16 @@ bool pv_map_ldt_shadow_page(unsigned intBUG_ON (unlikely (in_irq ()));/* -* Hardware limit checking should guarantee this property. NB. This is +* Prior limit checking should guarantee this property. NB. This is * safe as updates to the LDT can only be made by MMUEXT_SET_LDT to the * current vcpu, and vcpu_reset() will block until this vcpu has been * descheduled before continuing. */ -ASSERT ((offset >>3 ) <= curr->arch.pv.ldt_ents); +if (unlikely ((offset >>3 ) >= curr->arch.pv.ldt_ents) ) + { +ASSERT_UNREACHABLE (); +return false; + }if (is_pv_32bit_domain (currd) ) linear = (uint32_t )linear;
From: Jan Beulich <[email protected]>
Subject: x86/PV: check GDT/LDT limits during emulation
Accesses beyond the LDT limit originating from emulation would trigger the ASSERT() in pv_map_ldt_shadow_page(). On production builds such accesses would cause an attempt to promote the touched page (offset from the present LDT base address) to a segment descriptor one. If this happens to succeed, guest user mode would be able to elevate its privileges to that of the guest kernel. This is particularly easy when there's no LDT at all, in which case the LDT base stored internally to Xen is simply zero.
Also adjust the ASSERT() that was triggering: It was off by one to begin with, and for production builds we also better use ASSERT_UNREACHABLE() instead with suitable recovery code afterwards.
This is XSA-298.
xen/arch/x86/mm.c +12 -0
@@ -712,6 +712,18 @@ int map_ldt_shadow_page(unsigned int offBUG_ON (unlikely (in_irq ())); +/* +* Prior limit checking should guarantee this property. NB. This is +* safe as updates to the LDT can only be made by MMUEXT_SET_LDT to the +* current vcpu, and vcpu_reset() will block until this vcpu has been +* descheduled before continuing. +*/ +if (unlikely ((off >>3 ) >= v->arch.pv_vcpu.ldt_ents) ) + { +ASSERT_UNREACHABLE (); +return 0 ; + } +if (is_pv_32bit_domain (d) ) gva = (u32 )gva;guest_get_eff_kern_l1e (v, gva, &l1e);
xen/arch/x86/traps.c +16 -3
@@ -1639,7 +1639,14 @@ static int read_descriptor(unsigned int {struct desc_struct desc; -if ( sel <4 ) +if ( sel <4 || +/* +* Don't apply the GDT limit here, as the selector may be a Xen +* provided one. __get_user() will fail (without taking further +* action) for ones falling in the gap between guest populated +* and Xen ones. +*/ + ((sel &4 ) && (sel >>3 ) >= v->arch.pv_vcpu.ldt_ents) ) desc.b = desc.a =0 ; else if ( __get_user(desc, (const struct desc_struct *)(!(sel & 4)
@@ -1698,7 +1705,13 @@ static int read_gate_descriptor(unsigned (!(gate_sel &4 ) ?GDT_VIRT_START (v) :LDT_VIRT_START (v)) + (gate_sel >>3 );if ( (gate_sel <4 ) || - ((gate_sel >=FIRST_RESERVED_GDT_BYTE ) && !(gate_sel &4 )) || +/* +* We're interested in call gates only, which occupy a single +* seg_desc_t for 32-bit and a consecutive pair of them for 64-bit. +*/ + ((gate_sel >>3 ) + !is_pv_32bit_vcpu (v) >= + (gate_sel &4 ? v->arch.pv_vcpu.ldt_ents + : v->arch.pv_vcpu.gdt_ents)) ||__get_user (desc, pdesc) )return 0 ;
@@ -1717,7 +1730,7 @@ static int read_gate_descriptor(unsignedif ( !is_pv_32bit_vcpu (v) ) {if ( (*ar &0x1f00 ) !=0x0c00 || - (gate_sel >=FIRST_RESERVED_GDT_BYTE -8 && !(gate_sel &4 )) || +/* Limit check done above already. */ __get_user (desc, pdesc +1 ) || (desc.b &0x1f00 ) )return 0 ;
From: Jan Beulich <[email protected]>
Subject: x86/PV: check GDT/LDT limits during emulation
Accesses beyond the LDT limit originating from emulation would trigger the ASSERT() in pv_map_ldt_shadow_page(). On production builds such accesses would cause an attempt to promote the touched page (offset from the present LDT base address) to a segment descriptor one. If this happens to succeed, guest user mode would be able to elevate its privileges to that of the guest kernel. This is particularly easy when there's no LDT at all, in which case the LDT base stored internally to Xen is simply zero.
Also adjust the ASSERT() that was triggering: It was off by one to begin with, and for production builds we also better use ASSERT_UNREACHABLE() instead with suitable recovery code afterwards.
This is XSA-298.
xen/arch/x86/pv/emul-gate-op.c +8 -2
@@ -60,7 +60,13 @@ static int read_gate_descriptor(unsigned (!(gate_sel &4 ) ?GDT_VIRT_START (v) :LDT_VIRT_START (v)) + (gate_sel >>3 );if ( (gate_sel <4 ) || - ((gate_sel >=FIRST_RESERVED_GDT_BYTE ) && !(gate_sel &4 )) || +/* +* We're interested in call gates only, which occupy a single +* seg_desc_t for 32-bit and a consecutive pair of them for 64-bit. +*/ + ((gate_sel >>3 ) + !is_pv_32bit_vcpu (v) >= + (gate_sel &4 ? v->arch.pv_vcpu.ldt_ents + : v->arch.pv_vcpu.gdt_ents)) ||__get_user (desc, pdesc) )return 0 ;
@@ -79,7 +85,7 @@ static int read_gate_descriptor(unsignedif ( !is_pv_32bit_vcpu (v) ) {if ( (*ar &0x1f00 ) !=0x0c00 || - (gate_sel >=FIRST_RESERVED_GDT_BYTE -8 && !(gate_sel &4 )) || +/* Limit check done above already. */ __get_user (desc, pdesc +1 ) || (desc.b &0x1f00 ) )return 0 ;
xen/arch/x86/pv/emulate.c +8 -1
@@ -31,7 +31,14 @@ int pv_emul_read_descriptor(unsigned int {struct desc_struct desc; -if ( sel <4 ) +if ( sel <4 || +/* +* Don't apply the GDT limit here, as the selector may be a Xen +* provided one. __get_user() will fail (without taking further +* action) for ones falling in the gap between guest populated +* and Xen ones. +*/ + ((sel &4 ) && (sel >>3 ) >= v->arch.pv_vcpu.ldt_ents) ) desc.b = desc.a =0 ; else if ( __get_user(desc, (const struct desc_struct *)(!(sel & 4)
xen/arch/x86/pv/mm.c +6 -2
@@ -98,12 +98,16 @@ bool pv_map_ldt_shadow_page(unsigned intBUG_ON (unlikely (in_irq ()));/* -* Hardware limit checking should guarantee this property. NB. This is +* Prior limit checking should guarantee this property. NB. This is * safe as updates to the LDT can only be made by MMUEXT_SET_LDT to the * current vcpu, and vcpu_reset() will block until this vcpu has been * descheduled before continuing. */ -ASSERT ((offset >>3 ) <= curr->arch.pv_vcpu.ldt_ents); +if (unlikely ((offset >>3 ) >= curr->arch.pv_vcpu.ldt_ents) ) + { +ASSERT_UNREACHABLE (); +return false; + }if (is_pv_32bit_domain (currd) ) linear = (uint32_t )linear;
From: Jan Beulich <[email protected]>
Subject: x86/PV: check GDT/LDT limits during emulation
Accesses beyond the LDT limit originating from emulation would trigger the ASSERT() in pv_map_ldt_shadow_page(). On production builds such accesses would cause an attempt to promote the touched page (offset from the present LDT base address) to a segment descriptor one. If this happens to succeed, guest user mode would be able to elevate its privileges to that of the guest kernel. This is particularly easy when there's no LDT at all, in which case the LDT base stored internally to Xen is simply zero.
Also adjust the ASSERT() that was triggering: It was off by one to begin with, and for production builds we also better use ASSERT_UNREACHABLE() instead with suitable recovery code afterwards.
This is XSA-298.
xen/arch/x86/pv/emul-gate-op.c +8 -2
@@ -51,7 +51,13 @@ static int read_gate_descriptor(unsignedconst struct desc_struct *pdesc =gdt_ldt_desc_ptr (gate_sel);if ( (gate_sel <4 ) || - ((gate_sel >=FIRST_RESERVED_GDT_BYTE ) && !(gate_sel &4 )) || +/* +* We're interested in call gates only, which occupy a single +* seg_desc_t for 32-bit and a consecutive pair of them for 64-bit. +*/ + ((gate_sel >>3 ) + !is_pv_32bit_vcpu (v) >= + (gate_sel &4 ? v->arch.pv_vcpu.ldt_ents + : v->arch.pv_vcpu.gdt_ents)) ||__get_user (desc, pdesc) )return 0 ;
@@ -70,7 +76,7 @@ static int read_gate_descriptor(unsignedif ( !is_pv_32bit_vcpu (v) ) {if ( (*ar &0x1f00 ) !=0x0c00 || - (gate_sel >=FIRST_RESERVED_GDT_BYTE -8 && !(gate_sel &4 )) || +/* Limit check done above already. */ __get_user (desc, pdesc +1 ) || (desc.b &0x1f00 ) )return 0 ;
xen/arch/x86/pv/emulate.c +8 -1
@@ -31,7 +31,14 @@ int pv_emul_read_descriptor(unsigned int {struct desc_struct desc; -if ( sel <4 ) +if ( sel <4 || +/* +* Don't apply the GDT limit here, as the selector may be a Xen +* provided one. __get_user() will fail (without taking further +* action) for ones falling in the gap between guest populated +* and Xen ones. +*/ + ((sel &4 ) && (sel >>3 ) >= v->arch.pv_vcpu.ldt_ents) ) desc.b = desc.a =0 ;else if (__get_user (desc,gdt_ldt_desc_ptr (sel)) )return 0 ;
xen/arch/x86/pv/mm.c +6 -2
@@ -92,12 +92,16 @@ bool pv_map_ldt_shadow_page(unsigned intBUG_ON (unlikely (in_irq ()));/* -* Hardware limit checking should guarantee this property. NB. This is +* Prior limit checking should guarantee this property. NB. This is * safe as updates to the LDT can only be made by MMUEXT_SET_LDT to the * current vcpu, and vcpu_reset() will block until this vcpu has been * descheduled before continuing. */ -ASSERT ((offset >>3 ) <= curr->arch.pv_vcpu.ldt_ents); +if (unlikely ((offset >>3 ) >= curr->arch.pv_vcpu.ldt_ents) ) + { +ASSERT_UNREACHABLE (); +return false; + }if (is_pv_32bit_domain (currd) ) linear = (uint32_t )linear;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel