x86/monitor: Disallow setting mem_access_emulate_each_rep when vm_event is NULL
PATCH v2 1/1 x86/monitor: Disallow setting mem_access_emulate_each_rep when vm_event is NULL
It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.
---
Changes since V1:
- Fixed the if() condition.
- Introduced an rc return variable to simplify the code.
--- xen/include/asm-x86/monitor.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
xen/include/asm-x86/monitor.h +13 -3
@@ -32,19 +32,29 @@static inline int arch_monitor_domctl_op (struct domain *d,struct xen_domctl_monitor_op *mop) { +int rc =0 ; +switch ( mop->op ) {case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP :domain_pause (d); - d->arch.mem_access_emulate_each_rep = !!mop->event; +/* +* Enabling mem_access_emulate_each_rep without a vm_event subscriber +* is meaningless. +*/ +if ( d->vcpu && d->vcpu[0 ]->arch.vm_event ) + d->arch.mem_access_emulate_each_rep = !!mop->event; +else + rc = -EINVAL ; +domain_unpause (d);break ;default : -return -EOPNOTSUPP ; + rc = -EOPNOTSUPP ; } -return 0 ; +return rc; } int arch_monitor_domctl_event(struct domain *d,
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 25 lines · Razvan Cojocaru
It is meaningless (and potentially dangerous - see
hvmemul_virtual_to_linear()) to setmem_access_emulate_each_repbeforexc_monitor_enable()(which allocatesvcpu->arch.vm_event) has been called, so return an error from theXEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REPhypercall when that is the case.Signed-off-by Razvan Cojocaru <[email protected]>---
Changes since V1:
- Fixed theif()condition.
- Introduced an rc return variable to simplify the code.--- xen/include/asm-x86/monitor.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)xen/include/asm-x86/monitor.h +2
-0@@ -32,19 +32,29 @@static inline int arch_monitor_domctl_op (struct domain *d,struct xen_domctl_monitor_op *mop) { +int rc =0 ; +
xen/include/asm-x86/monitor.h line 45
Quoted 10 lines
xen/include/asm-x86/monitor.h +5
-1switch ( mop->op ) {case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP :domain_pause (d); - d->arch.mem_access_emulate_each_rep = !!mop->event; +/* +* Enabling mem_access_emulate_each_rep without a vm_event subscriber +* is meaningless. +*/ +if ( d->vcpu && d->vcpu[0 ]->arch.vm_event )
Sorry - I forgot to mention this before, but this check is slightly buggy. You want
if ( d->max_vcpus && d->vcpu[0] && d->vcpu[0]->arch.vm_event )
d->max_vcpus being non-zero guarentees that d->vcpu has been allocated, but you still need to check that d->vcpu[0] has been allocated before following the pointer.
With that fixed, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 7 lines
xen/include/asm-x86/monitor.h +4
-0+ d->arch.mem_access_emulate_each_rep = !!mop->event; + else + rc = -EINVAL ; +domain_unpause (d);break ;
xen/include/asm-x86/monitor.h line 60
Quoted 10 lines
xen/include/asm-x86/monitor.h +2
-2default : -return -EOPNOTSUPP ; + rc = -EOPNOTSUPP ; } -return 0 ; +return rc; } int arch_monitor_domctl_event(struct domain *d,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel