x86/vPIC: check values loaded from state save record
PATCH 1/1 x86/vPIC: check values loaded from state save record
Loading is_master from the state save record can lead to out-of-bounds accesses via at least the two container_of() uses by vpic_domain() and __vpic_lock(). Calculate the field from the supplied instance number instead. Adjust the public header comment accordingly.
For ELCR follow what vpic_intercept_elcr_io()'s write path and vpic_reset() do.
Convert ->int_output (which for whatever reason isn't a 1-bit bitfield) to boolean, also taking ->init_state into account.
While there also correct vpic_domain() itself, to use its parameter in both places.
---
Of course an alternative would be to simply reject state save records with bogus values.
xen/arch/x86/hvm/vpic.c +9 -1
@@ -35,7 +35,7 @@#include <asm/hvm/save.h> #define vpic_domain (v) (container_of((v), struct domain, \ - arch.hvm.vpic[!vpic->is_master])) + arch.hvm.vpic[!(v)->is_master]))#define __vpic_lock (v) &container_of((v), struct hvm_domain, \ vpic[!(v)->is_master])->irq_lock#define vpic_lock (v) spin_lock(__vpic_lock(v))
@@ -437,6 +437,14 @@ static int cf_check vpic_load(struct domif (hvm_load_entry (PIC , h, s) !=0 )return -EINVAL ; + s->is_master = !inst; + + s->elcr &=vpic_elcr_mask (s); +if ( s->is_master ) + s->elcr |=1 <<2 ; + + s->int_output = !s->init_state && s->int_output; +return 0 ; }
xen/include/public/arch-x86/hvm/save.h +4 -1
@@ -329,7 +329,10 @@ struct hvm_hw_vpic {/* Special mask mode excludes masked IRs from AEOI and priority checks. */ uint8_t special_mask_mode:1; -/* Is this a master PIC or slave PIC? (NB. This is not programmable.) */ +/* +* Is this the master PIC or a slave one? (NB. This is not programmable, +* and hence is ignored upon loading.) +*/ uint8_t is_master:1;/* Edge/trigger selection. */
Quoted 11 lines · Jan Beulich
Loading
is_masterfrom the state save record can lead to out-of-bounds accesses via at least the twocontainer_of()uses byvpic_domain()and__vpic_lock(). Calculate the field from the supplied instance number instead. Adjust the public header comment accordingly.For ELCR follow what vpic_intercept_elcr_io()'s write path and
vpic_reset()do.Convert ->int_output (which for whatever reason isn't a 1-bit bitfield) to boolean, also taking ->init_state into account.
Quoted 7 lines
While there also correct
vpic_domain()itself, to use its parameter in both places.Signed-off-by Jan Beulich <[email protected]>---
Of course an alternative would be to simply reject state save records with bogus values.
Likewise on the vPIC one, I feel it might be better to just reject such bogus entries, instead of attempting to amend them.
This one however just unconditionally reset some values, but might be simpler to just test if is_master == !inst and if it's master than bit 2 in s->elcr is set?
Also if we are serious about doing some sanity checks in the loaded records, we could introduce a checker function for the load machinery.
Thanks, Roger.
Quoted 15 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
Loading
is_masterfrom the state save record can lead to out-of-bounds accesses via at least the twocontainer_of()uses byvpic_domain()and__vpic_lock(). Calculate the field from the supplied instance number instead. Adjust the public header comment accordingly.For ELCR follow what vpic_intercept_elcr_io()'s write path and
vpic_reset()do.Convert ->int_output (which for whatever reason isn't a 1-bit bitfield) to boolean, also taking ->init_state into account.
While there also correct
vpic_domain()itself, to use its parameter in both places.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>---
Of course an alternative would be to simply reject state save records with bogus values.Likewise on the vPIC one, I feel it might be better to just reject such bogus entries, instead of attempting to amend them.
Perhaps we should discuss which route to take on the next x86 meeting? Then also Andrew would have a chance to voice concerns; not sure if he's following the thread.
Quoted 3 lines
This one however just unconditionally reset some values, but might be simpler to just test if
is_master== !inst and if it's master than bit 2 ins->elcris set?
vpic_elcr_mask() also wants applying (or a respective check carrying out). Plus int_output can't be left alone, I thunk.
Quoted 2 lines
Also if we are serious about doing some sanity checks in the loaded records, we could introduce a checker function for the load machinery.
If we were to check rather than override, then yes, perhaps running through all check functions first would be desirable.
Jan
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich
Loading
is_masterfrom the state save record can lead to out-of-bounds accesses via at least the twocontainer_of()uses byvpic_domain()and__vpic_lock(). Calculate the field from the supplied instance number instead. Adjust the public header comment accordingly.For ELCR follow what vpic_intercept_elcr_io()'s write path and
vpic_reset()do.Convert ->int_output (which for whatever reason isn't a 1-bit bitfield) to boolean, also taking ->init_state into account.
While there also correct
vpic_domain()itself, to use its parameter in both places.Signed-off-by Jan Beulich <[email protected]>---
Of course an alternative would be to simply reject state save records with bogus values.
Quoted 6 lines
Quoted 2 lines
Likewise on the vPIC one, I feel it might be better to just reject such bogus entries, instead of attempting to amend them.
Perhaps we should discuss which route to take on the next x86 meeting? Then also Andrew would have a chance to voice concerns; not sure if he's following the thread.
I don't have a strong opinion. It seems more prone to errors to try to adjust state that we know it's wrong. The adjustments could have bad interactions, or we might miss other fields that also need adjusting. Plus any such 'bogus' state is a sign of something going wrong.
Thanks, Roger.