sched/core: Fix bug when moving a domain between cpupools
PATCH 1/1 sched/core: Fix bug when moving a domain between cpupools
For each UNIT, sched_set_affinity is called before unit->priv is updated to the new cpupool private UNIT data structure. The issue is sched_set_affinity will call the adjust_affinity method of the cpupool. If defined, the new cpupool may use unit->priv (e.g. credit), which at this point still references the old cpupool private UNIT data structure.
This change fixes the bug by moving the switch of unit->priv earler in the function.
---
Hello,
I've been working on updating the arinc653 scheduler to support multicore for a few months now. In the process of testing, I came across this obscure bug in the core scheduler code that took me a few weeks to track down. This bug resulted in the credit scheduler writing past the end of the arinc653 private UNIT data structure into the TLSF allocator bhdr structure of the adjacent region. This required some deep diving into the TLSF allocator code to trace the bug back to this point.
Sincerely,
Jeff Kubascik
--- xen/common/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/sched/core.c +1 -1
@@ -686,6 +686,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)unsigned int unit_p = new_p; unitdata = unit->priv; + unit->priv = unit_priv[unit_idx]; for_each_sched_unit_vcpu ( unit, v ) {
@@ -707,7 +708,6 @@ int sched_move_domain(struct domain *d, struct cpupool *c)*/ spin_unlock_irq (lock); - unit->priv = unit_priv[unit_idx];if ( !d->is_dying )sched_move_irqs (unit);
Signature · 1 line
2.17.1
Hello,
I wanted to follow up on this patch, as I have not seen any responses to it.
In my work on the ARINC653 scheduler, I have observed this bug write to memory past the end of a private UNIT structure (and in my case, stomping on a TLSF allocator header) when migrating a domain from an ARINC cpupool to a credit cpupool. This occurs because (a) the private UNIT structure is smaller for the ARINC cpupool and (b) the credit scheduler method csched_aff_cntl does some bit setting/ clearing while the private UNIT pointer still points incorrectly to the ARINC cpupool one.
Quoted 41 lines · Jeff Kubascik
For each UNIT,
sched_set_affinityis called beforeunit->privis updated to the new cpupool private UNIT data structure. The issue issched_set_affinitywill call theadjust_affinitymethod of the cpupool. If defined, the new cpupool may useunit->priv(e.g. credit), which at this point still references the old cpupool private UNIT data structure.This change fixes the bug by moving the switch of
unit->privearler in the function.Signed-off-by Jeff Kubascik <[email protected]>---
Hello,I've been working on updating the arinc653 scheduler to support multicore for a few months now. In the process of testing, I came across this obscure bug in the core scheduler code that took me a few weeks to track down. This bug resulted in the credit scheduler writing past the end of the arinc653 private UNIT data structure into the TLSF allocator bhdr structure of the adjacent region. This required some deep diving into the TLSF allocator code to trace the bug back to this point.
Sincerely,
Jeff Kubascik--- xen/common/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/common/sched/core.c +1
-0@@ -686,6 +686,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)unsigned int unit_p = new_p; unitdata = unit->priv; + unit->priv = unit_priv[unit_idx]; for_each_sched_unit_vcpu ( unit, v ) {
xen/common/sched/core.c int sched_move_domain(struct domain *d, struct cpupool *c) · line 713
Quoted 7 lines
xen/common/sched/core.c +0
-1@@ -707,7 +708,6 @@ int sched_move_domain(struct domain *d, struct cpupool *c)*/ spin_unlock_irq (lock); - unit->priv = unit_priv[unit_idx];if ( !d->is_dying )sched_move_irqs (unit);
Sincerely,
Jeff Kubascik
Quoted 10 lines · Jeff Kubascik
For each UNIT,
sched_set_affinityis called beforeunit->privis updated to the new cpupool private UNIT data structure. The issue issched_set_affinitywill call theadjust_affinitymethod of the cpupool. If defined, the new cpupool may useunit->priv(e.g. credit), which at this point still references the old cpupool private UNIT data structure.This change fixes the bug by moving the switch of
unit->privearler in the function.Signed-off-by Jeff Kubascik <[email protected]>
Juergen
Dario Faggioli
Acked-byQuoted 11 lines · Jürgen Groß
Quoted 10 lines · Jeff Kubascik
For each UNIT,
sched_set_affinityis called beforeunit->privis updated
to the new cpupool private UNIT data structure. The issue issched_set_affinitywill call theadjust_affinitymethod of the cpupool.
If defined, the new cpupool may useunit->priv(e.g. credit), which at
this point still references the old cpupool private UNIT data structure.
Quoted 8 lines
Quoted 5 lines
This change fixes the bug by moving the switch of
unit->privearler in
the function.Signed-off-by Jeff Kubascik <[email protected]>Reviewed-by Juergen Gross <[email protected]>
Sorry it took a while. And thanks Juergen for also having a look.
Regards
Signature · 6 lines
Dario Faggioli, Ph.D http://about.me/dario.faggioli Virtualization Software Engineer SUSE Labs, SUSE https://www.suse.com/ ------------------------------------------------------------------- <<This happens because _I_ choose it to happen!>> (Raistlin Majere)
Thank you Juergen and Dario!
Quoted 18 lines · Dario Faggioli
Quoted 17 lines · Jürgen Groß
Quoted 15 lines · Jeff Kubascik
For each UNIT,
sched_set_affinityis called beforeunit->privis updated
to the new cpupool private UNIT data structure. The issue issched_set_affinitywill call theadjust_affinitymethod of the cpupool.
If defined, the new cpupool may useunit->priv(e.g. credit), which at
this point still references the old cpupool private UNIT data structure.This change fixes the bug by moving the switch of
unit->privearler in
the function.Signed-off-by Jeff Kubascik <[email protected]>
Quoted 8 lines
Quoted 2 lines
Reviewed-by Juergen Gross <[email protected]>Acked-by Dario Faggioli <[email protected]>Sorry it took a while. And thanks Juergen for also having a look.
Regards
Sincerely,
Jeff Kubascik