Enabling #VE for a domain from dom0
Hello,
We are trying to use the #VE support in Xen to monitor memory accesses to certain pages from a kernel module in Windows.
As it is written now, the #VE-enabling code appears to enforce being called by a domain for itself (by each VCPU for itself, actually), which severely limits its usefulness. Is there an architectural reasoning for this or some other factor I'm missing?
The process of enabling #VE as I understand it starts from xc_altp2m_set_vcpu_enable_notify(); further along, when the HVMOP_altp2m_vcpu_enable_notify message is handled, several checks are made to ensure it's called for the current VCPU.
Another check is in p2m.c in the function p2m_set_altp2m_mem_access(), which clears the "suppress #VE" bit only for pages on the same domain:
return ap2m->set_entry(ap2m, gfn_l, mfn, PAGE_ORDER_4K, t, a,
(current->domain != d));The "(current->domain != d)" bit there is the sve parameter.
Is there any reason not to allow cross-domain enabling of #VE?
Thank you,
--
Vlad-Ioan TOPAN
Linux Kernel Development Lead
Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 18 lines · Vlad-Ioan TOPAN
Hello,
We are trying to use the #VE support in Xen to monitor memory accesses to certain pages from a kernel module in Windows.
As it is written now, the #VE-enabling code appears to enforce being called by a domain for itself (by each VCPU for itself, actually), which severely limits its usefulness. Is there an architectural reasoning for this or some other factor I'm missing?
The process of enabling #VE as I understand it starts from
xc_altp2m_set_vcpu_enable_notify(); further along, when theHVMOP_altp2m_vcpu_enable_notifymessage is handled, several checks are made to ensure it's called for the current VCPU.Another check is in
p2m.cin the functionp2m_set_altp2m_mem_access(), which clears the "suppress #VE" bit only for pages on the same domain:
Quoted 6 lines
return ap2m->set_entry(ap2m, gfn_l, mfn, PAGE_ORDER_4K, t, a, (current->domain != d));The "(
current->domain!= d)" bit there is the sve parameter.Is there any reason not to allow cross-domain enabling of #VE?
#VE, by design, raises an exception in non-root context, without breaking out to the hypervisor.
The vcpu in question needs to set up a suitable #VE handler, so it is not safe for an external entity to chose when a vcpu should start receiving #VE's.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines
#VE, by design, raises an exception in non-root context, without breaking out to the hypervisor.
The vcpu in question needs to set up a suitable #VE handler, so it is not safe for an external entity to chose when a vcpu should start receiving #VE's.
The problem is that from a security solution standpoint, it isn't feasible in a Windows guest to use libxc to enable #VE. As it is implemented, libxc is required to allow sharing a structure between the guest and the host; the structure only contains the gfn of the #VE page and the domain id/vcpu id, which are useless since it can only be enabled on the current VCPU. Would a patch providing a simpler VMCALL (without sharing structures, only passing the gfn) to enable #VE be acceptable?
Is there any reason for the other check I've mentioned, performed when setting the "suppres #VE" bit in PTEs? Unsuppressing #VEs for a page will only do anything if the guest has already enabled #VE, so the previous issue doesn't apply in this case.
Thank you for the prompt answer!
--
Vlad-Ioan TOPAN
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Vlad-Ioan TOPAN
Quoted 6 lines
#VE, by design, raises an exception in non-root context, without breaking out to the hypervisor.
The vcpu in question needs to set up a suitable #VE handler, so it is not safe for an external entity to chose when a vcpu should start receiving #VE's.
Quoted 8 lines
The problem is that from a security solution standpoint, it isn't feasible in a Windows guest to use libxc to enable #VE. As it is implemented, libxc is required to allow sharing a structure between the guest and the host; the structure only contains the gfn of the #VE page and the domain id/vcpu id, which are useless since it can only be enabled on the current VCPU. Would a patch providing a simpler VMCALL (without sharing structures, only passing the gfn) to enable #VE be acceptable?
/sigh
The underlying hypercall is HVMOP_altp2m, which is supposed to have a stable ABI, as it is guest visible.
However, it has a HVMOP_ALTP2M_INTERFACE_VERSION wedged in there, which is unacceptable, and broken, as it cannot be used correctly from within a guest.
The only option we have to is freeze HVMOP_ALTP2M_INTERFACE_VERSION at its current value and force it to never change. I am sorry for not having picked up on this point during review of the series several releases ago.
However, for your purposes, you don't need libxc. You should just be able to make HVMOP hypercalls directly to set up #VE from within the guest.
Quoted 4 lines
Is there any reason for the other check I've mentioned, performed when setting the "suppres #VE" bit in PTEs? Unsuppressing #VEs for a page will only do anything if the guest has already enabled #VE, so the previous issue doesn't apply in this case.
suppress #VE has a negative meaning. Once #VE is enabled, all frames need SVE for Xen to continue getting EPT_VIOLATION vmexits per usual. It is only whitelisted frames which should have SVE cleared on them.
Having said that, by the time you have cooperation between several domains, I don't see a reason for excluding a remote domain updating SVE.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 21 lines · Andrew Cooper
Quoted 6 lines · Vlad-Ioan TOPAN
Quoted 6 lines
#VE, by design, raises an exception in non-root context, without breaking out to the hypervisor.
The vcpu in question needs to set up a suitable #VE handler, so it is not safe for an external entity to chose when a vcpu should start receiving #VE's.
Quoted 8 lines
The problem is that from a security solution standpoint, it isn't feasible in a Windows guest to use libxc to enable #VE. As it is implemented, libxc is required to allow sharing a structure between the guest and the host; the structure only contains the gfn of the #VE page and the domain id/vcpu id, which are useless since it can only be enabled on the current VCPU. Would a patch providing a simpler VMCALL (without sharing structures, only passing the gfn) to enable #VE be acceptable?
/sigh
The underlying hypercall is
HVMOP_altp2m, which is supposed to have a stable ABI, as it is guest visible.
Quoted 8 lines
However, it has a
HVMOP_ALTP2M_INTERFACE_VERSIONwedged in there, which is unacceptable, and broken, as it cannot be used correctly from within a guest.The only option we have to is freeze
HVMOP_ALTP2M_INTERFACE_VERSIONat its current value and force it to never change. I am sorry for not having picked up on this point during review of the series several releases ago.
I'm just curious, why is it broken exactly?
Quoted 3 lines
However, for your purposes, you don't need libxc. You should just be able to make HVMOP hypercalls directly to set up #VE from within the guest.
Right, I've been meaning to submit a patch that removes that libxc function for a while now as it is misleading..
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 26 lines · Tamas K Lengyel
Quoted 24 lines · Andrew Cooper
Quoted 6 lines · Vlad-Ioan TOPAN
Quoted 6 lines
#VE, by design, raises an exception in non-root context, without breaking out to the hypervisor.
The vcpu in question needs to set up a suitable #VE handler, so it is not safe for an external entity to chose when a vcpu should start receiving #VE's.
Quoted 8 lines
The problem is that from a security solution standpoint, it isn't feasible in a Windows guest to use libxc to enable #VE. As it is implemented, libxc is required to allow sharing a structure between the guest and the host; the structure only contains the gfn of the #VE page and the domain id/vcpu id, which are useless since it can only be enabled on the current VCPU. Would a patch providing a simpler VMCALL (without sharing structures, only passing the gfn) to enable #VE be acceptable?
/sigh
The underlying hypercall is
HVMOP_altp2m, which is supposed to have a stable ABI, as it is guest visible.However, it has a
HVMOP_ALTP2M_INTERFACE_VERSIONwedged in there, which is unacceptable, and broken, as it cannot be used correctly from within a guest.
Quoted 5 lines
Quoted 4 lines
The only option we have to is freeze
HVMOP_ALTP2M_INTERFACE_VERSIONat its current value and force it to never change. I am sorry for not having picked up on this point during review of the series several releases ago.I'm just curious, why is it broken exactly?
All ABI exposed to domUs must be stable (extendibility in a backwards compatible way is of course fine).
The conditions that would necessitate changing the interface version will guarantee to break a running in-guest agent of a VM which has migrated in from a different version of Xen.
On a lesser point, all the in-guest agent could do with the interface version is work out whether Xen was compiled with the same version or not. If not, all it can do is bail out, and "please recompiled your inguest agent against a different version of the hypervisor" isn't ok.
Stable ABIs are not hard.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 11 lines
Quoted 4 lines
Is there any reason for the other check I've mentioned, performed when setting the "suppres #VE" bit in PTEs? Unsuppressing #VEs for a page will only do anything if the guest has already enabled #VE, so the previous issue doesn't apply in this case.
suppress #VE has a negative meaning. Once #VE is enabled, all frames need SVE for Xen to continue getting
EPT_VIOLATIONvmexits per usual. It is only whitelisted frames which should have SVE cleared on them.Having said that, by the time you have cooperation between several domains, I don't see a reason for excluding a remote domain updating SVE.
Sorry for following up so late on this; what would be an acceptable approach to allow a remote domain to update the "Suppress VE" bit for a given domain?
The current page permission code flow via do_altp2m_op() / HVMOP_altp2m_set_mem_access only allows setting actual page permissions, and all the other APIs it calls along the way (p2m_set_mem_access(), set_mem_access() and p2m_set_altp2m_mem_access() in mem_access.c) don't have a "suppress VE" parameter (up until the ept_set_entry() call, which gets sve as "current->domain != d" from p2m_set_altp2m_mem_access()). At that level a separate parameter for sVE does not make sense, since the code is shared with the ARM arch.
Would it be acceptable to add an HVMOP_altp2m_set_suppres_ve op?
Thank you,
--
Vlad-Ioan TOPAN
Linux Kernel Development Lead
Bitdefender
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 23 lines · Vlad-Ioan TOPAN
Quoted 10 lines
Quoted 4 lines
Is there any reason for the other check I've mentioned, performed when setting the "suppres #VE" bit in PTEs? Unsuppressing #VEs for a page will only do anything if the guest has already enabled #VE, so the previous issue doesn't apply in this case.
suppress #VE has a negative meaning. Once #VE is enabled, all frames need SVE for Xen to continue getting
EPT_VIOLATIONvmexits per usual. It is only whitelisted frames which should have SVE cleared on them.Having said that, by the time you have cooperation between several domains, I don't see a reason for excluding a remote domain updating SVE.
Sorry for following up so late on this; what would be an acceptable approach to allow a remote domain to update the "Suppress VE" bit for a given domain?
The current page permission code flow via
do_altp2m_op()/HVMOP_altp2m_set_mem_accessonly allows setting actual page permissions, and all the other APIs it calls along the way (p2m_set_mem_access(),set_mem_access()andp2m_set_altp2m_mem_access()inmem_access.c) don't have a "suppress VE" parameter (up until theept_set_entry()call, which gets sve as "current->domain!= d" fromp2m_set_altp2m_mem_access()). At that level a separate parameter for sVE does not make sense, since the code is shared with the ARM arch.
Quoted 1 line
Would it be acceptable to add an
HVMOP_altp2m_set_suppres_veop?
Given the reasoning in
https://lists.xenproject.org/archives/html/xen-devel/2017-03/msg01309.html
I think it is reasonable, after the domain has initialised altp2m support, to allow a remote domain to alter all aspects of altp2m permissions.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel