x86/traps: Fix error handling of the pv %dr7 shadow state
PATCH 1/1 x86/traps: Fix error handling of the pv %dr7 shadow state
c/s "x86/pv: Introduce and use x86emul_write_dr()" fixed a bug with IO shadow handling, in that it remained stale and visible until %dr7.L/G got set again.
However, it neglected the -EPERM return inbetween these two hunks, introducing a different bug in which a write to %dr7 which tries to set IO breakpoints without %cr4.DE being set clobbers the IO state, rather than leaves it alone.
Instead, move the zeroing slightly later, which guarentees that the shadow gets written exactly once, on a successful update to %dr7.
---
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>
Although minor, this is a regression from Xen 4.10, so should be considered for 4.11 at this point. Given that PV debugging was basically completely broken before the XSA-263 investigation work, the risk of further issues is very small.
--- xen/arch/x86/traps.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/traps.c +4 -3
@@ -2123,9 +2123,6 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)if ( value &DR_GENERAL_DETECT )return -EPERM ; -/* Zero the IO shadow before recalculating the real %dr7 */ - v->arch.debugreg[5 ] =0 ; -/* DR7.{G,L}E = 0 => debugging disabled for this domain. */ if ( value &DR7_ACTIVE_MASK ) {
@@ -2154,6 +2151,10 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value) !(v->arch.debugreg[7] & DR7_ACTIVE_MASK) )activate_debugregs (v); } +else +/* Zero the emulated controls if %dr7 isn't active. */ + v->arch.debugreg[5 ] =0 ; +if ( v == curr )write_debugreg (7 , value);break ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Andrew Cooper
c/s "x86/pv: Introduce and use
x86emul_write_dr()" fixed a bug with IO shadow handling, in that it remained stale and visible until %dr7.L/G got set again.However, it neglected the
-EPERMreturn inbetween these two hunks, introducing a different bug in which a write to %dr7 which tries to set IO breakpoints without %cr4.DE being set clobbers the IO state, rather than leaves it alone.Instead, move the zeroing slightly later, which guarentees that the shadow gets written exactly once, on a successful update to %dr7.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 8 lines
---
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>Although minor, this is a regression from Xen 4.10, so should be considered for 4.11 at this point. Given that PV debugging was basically completely broken before the XSA-263 investigation work, the risk of further issues is very small.
Sorry - this is a bad way of phrasing what I meant to say. The behaviour of 4.11 is less bad than 4.10, but still wrong (and in a way which is technically a regression from 4.10).
~Andrew
Quoted 19 lines
--- xen/arch/x86/traps.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)xen/arch/x86/traps.c +0
-3@@ -2123,9 +2123,6 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value)if ( value &DR_GENERAL_DETECT )return -EPERM ; -/* Zero the IO shadow before recalculating the real %dr7 */ - v->arch.debugreg[5 ] =0 ; -/* DR7.{G,L}E = 0 => debugging disabled for this domain. */ if ( value &DR7_ACTIVE_MASK ) {
xen/arch/x86/traps.c long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value) · line 2160
Quoted 10 lines
xen/arch/x86/traps.c +4
-0@@ -2154,6 +2151,10 @@ long set_debugreg(struct vcpu *v, unsigned int reg, unsigned long value) !(v->arch.debugreg[7] & DR7_ACTIVE_MASK) )activate_debugregs (v); } +else +/* Zero the emulated controls if %dr7 isn't active. */ + v->arch.debugreg[5 ] =0 ; +if ( v == curr )write_debugreg (7 , value);break ;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 01.06.18 at 16:06, <[email protected]> wrote:
c/s "x86/pv: Introduce and use
x86emul_write_dr()" fixed a bug with IO shadow handling, in that it remained stale and visible until %dr7.L/G got set again.
Quoted 8 lines
However, it neglected the
-EPERMreturn inbetween these two hunks, introducing a different bug in which a write to %dr7 which tries to set IO breakpoints without %cr4.DE being set clobbers the IO state, rather than leaves it alone.Instead, move the zeroing slightly later, which guarentees that the shadow gets written exactly once, on a successful update to %dr7.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Andrew Cooper
c/s "x86/pv: Introduce and use
x86emul_write_dr()" fixed a bug with IO shadow handling, in that it remained stale and visible until %dr7.L/G got set again.However, it neglected the
-EPERMreturn inbetween these two hunks, introducing a different bug in which a write to %dr7 which tries to set IO breakpoints without %cr4.DE being set clobbers the IO state, rather than leaves it alone.Instead, move the zeroing slightly later, which guarentees that the shadow gets written exactly once, on a successful update to %dr7.
Signed-off-by Andrew Cooper <[email protected]>
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel