xen/sched: don't let XEN_RUNSTATE_UPDATE leak into vcpu_runstate_get()
PATCH v3 1/1 xen/sched: don't let XEN_RUNSTATE_UPDATE leak into vcpu_runstate_get()
vcpu_runstate_get() should never return a state entry time with XEN_RUNSTATE_UPDATE set. To avoid this let update_runstate_area() operate on a local runstate copy.
As it is required to first set the XEN_RUNSTATE_UPDATE indicator in guest memory, then update all the runstate data, and then at last clear the XEN_RUNSTATE_UPDATE again it is much less effort to have a local copy of the runstate data instead of keeping only a copy of state_entry_time.
This problem was introduced with commit 2529c850ea48f036 ("add update indicator to vcpu_runstate_info").
---
V2: add handling on ARM, too (Jan Beulich)
--- xen/arch/arm/domain.c | 13 ++++++++----- xen/arch/x86/domain.c | 17 ++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-)
xen/arch/arm/domain.c +8 -5
@@ -280,28 +280,31 @@ static void ctxt_switch_to(struct vcpu *n)static void update_runstate_area (struct vcpu *v) {void __user *guest_handle =NULL ; +struct vcpu_runstate_info runstate;if (guest_handle_is_null (runstate_guest (v)) )return ; +memcpy (&runstate, &v->runstate,sizeof (runstate)); +if (VM_ASSIST (v->domain, runstate_update_flag) ) { guest_handle = &v->runstate_guest.p->state_entry_time +1 ; guest_handle--; - v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ;__raw_copy_to_guest (guest_handle, - (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); + (void *)(&runstate.state_entry_time +1 ) -1 ,1 );smp_wmb (); } -__copy_to_guest (runstate_guest (v), &v->runstate,1 ); +__copy_to_guest (runstate_guest (v), &runstate,1 );if ( guest_handle ) { - v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ;smp_wmb ();__raw_copy_to_guest (guest_handle, - (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); + (void *)(&runstate.state_entry_time +1 ) -1 ,1 ); } }
xen/arch/x86/domain.c +10 -7
@@ -1600,21 +1600,24 @@ bool update_runstate_area(struct vcpu *v)bool rc;struct guest_memory_policy policy = { .nested_guest_mode = false };void __user *guest_handle =NULL ; +struct vcpu_runstate_info runstate;if (guest_handle_is_null (runstate_guest (v)) )return true;update_guest_memory_policy (v, &policy); +memcpy (&runstate, &v->runstate,sizeof (runstate)); +if (VM_ASSIST (v->domain, runstate_update_flag) ) { guest_handle =has_32bit_shinfo (v->domain) ? &v->runstate_guest.compat.p->state_entry_time +1 : &v->runstate_guest.native.p->state_entry_time +1 ; guest_handle--; - v->runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ; + runstate.state_entry_time |=XEN_RUNSTATE_UPDATE ;__raw_copy_to_guest (guest_handle, - (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); + (void *)(&runstate.state_entry_time +1 ) -1 ,1 );smp_wmb (); }
@@ -1622,20 +1625,20 @@ bool update_runstate_area(struct vcpu *v) {struct compat_vcpu_runstate_info info; -XLAT_vcpu_runstate_info (&info, &v->runstate); +XLAT_vcpu_runstate_info (&info, &runstate);__copy_to_guest (v->runstate_guest.compat, &info,1 ); rc = true; } else - rc =__copy_to_guest (runstate_guest (v), &v->runstate,1 ) != -sizeof (v->runstate); + rc =__copy_to_guest (runstate_guest (v), &runstate,1 ) != +sizeof (runstate);if ( guest_handle ) { - v->runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ; + runstate.state_entry_time &= ~XEN_RUNSTATE_UPDATE ;smp_wmb ();__raw_copy_to_guest (guest_handle, - (void *)(&v->runstate.state_entry_time +1 ) -1 ,1 ); + (void *)(&runstate.state_entry_time +1 ) -1 ,1 ); }update_guest_memory_policy (v, &policy);
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Juergen Gross
vcpu_runstate_get()should never return a state entry time withXEN_RUNSTATE_UPDATEset. To avoid this letupdate_runstate_area()operate on a local runstate copy.As it is required to first set the
XEN_RUNSTATE_UPDATEindicator in guest memory, then update all the runstate data, and then at last clear theXEN_RUNSTATE_UPDATEagain it is much less effort to have a local copy of the runstate data instead of keeping only a copy ofstate_entry_time.
Quoted 5 lines
This problem was introduced with commit
2529c850ea48f036("add update indicator tovcpu_runstate_info").Reported-by Andrew Cooper <[email protected]>Signed-off-by Juergen Gross <[email protected]>
And yet another time
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Hi Juergen,
Quoted 10 lines · Juergen Gross
vcpu_runstate_get()should never return a state entry time withXEN_RUNSTATE_UPDATEset. To avoid this letupdate_runstate_area()operate on a local runstate copy.As it is required to first set the
XEN_RUNSTATE_UPDATEindicator in guest memory, then update all the runstate data, and then at last clear theXEN_RUNSTATE_UPDATEagain it is much less effort to have a local copy of the runstate data instead of keeping only a copy ofstate_entry_time.
Quoted 5 lines
This problem was introduced with commit
2529c850ea48f036("add update indicator tovcpu_runstate_info").Reported-by Andrew Cooper <[email protected]>Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel