x86: refine debugging of SMEP/SMAP fix
PATCH 1/1 x86: refine debugging of SMEP/SMAP fix
Instead of just latching cr4_pv32_mask into %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducing cr4_pv32_mask from the register dump.
Also there is one more place for XEN_CR4_PV32_BITS to be used.
xen/arch/x86/x86_64/compat/entry.S +5 -3
@@ -182,7 +182,7 @@ ENTRY(compat_restore_all_guest) testb $3,UREGS_cs(%rsp) jpe .Lcr4_alt_end mov CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp), %rax - and $~(X86_CR4_SMEP|X86_CR4_SMAP), %rax + and $~XEN_CR4_PV32_BITS, %rax mov %rax, CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp) mov %rax, %cr4 .Lcr4_alt_end:
@@ -218,8 +218,10 @@ ENTRY(cr4_pv32_restore) and cr4_pv32_mask(%rip), %rax cmp cr4_pv32_mask(%rip), %rax je 1f - /* Cause cr4_pv32_mask to be visible in the BUG register dump. */ - mov cr4_pv32_mask(%rip), %rdx + /* Avoid coming back here while handling the #UD we cause below. */ + mov %cr4, %rdx + or cr4_pv32_mask(%rip), %rdx + mov %rdx, %cr4 BUG 1: #endif
x86: refine debugging of SMEP/SMAP fix
Instead of just latching cr4_pv32_mask into %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducing cr4_pv32_mask from the register dump.
Also there is one more place for XEN_CR4_PV32_BITS to be used.
xen/arch/x86/x86_64/compat/entry.S +5 -3
@@ -182,7 +182,7 @@ ENTRY(compat_restore_all_guest) testb $3,UREGS_cs(%rsp) jpe .Lcr4_alt_end mov CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp), %rax - and $~(X86_CR4_SMEP|X86_CR4_SMAP), %rax + and $~XEN_CR4_PV32_BITS, %rax mov %rax, CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp) mov %rax, %cr4 .Lcr4_alt_end:
@@ -218,8 +218,10 @@ ENTRY(cr4_pv32_restore) and cr4_pv32_mask(%rip), %rax cmp cr4_pv32_mask(%rip), %rax je 1f - /* Cause cr4_pv32_mask to be visible in the BUG register dump. */ - mov cr4_pv32_mask(%rip), %rdx + /* Avoid coming back here while handling the #UD we cause below. */ + mov %cr4, %rdx + or cr4_pv32_mask(%rip), %rdx + mov %rdx, %cr4 BUG 1: #endif
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 4 lines · Jan Beulich
Instead of just latching
cr4_pv32_maskinto %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducingcr4_pv32_maskfrom the register dump.
Alternatively, you can reuse %rax (as its value is useless by this point) and leave %rdx as exactly cr4_pv32_mask. This avoids needing a subsequent step to reverse engineer cr4_pv32_mask.
Quoted 2 lines
Also there is one more place for
XEN_CR4_PV32_BITSto be used.
So there is. Sorry for missing it.
~Andrew
Quoted 32 lines
Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/x86_64/compat/entry.S +5
-3@@ -182,7 +182,7 @@ ENTRY(compat_restore_all_guest) testb $3,UREGS_cs(%rsp) jpe .Lcr4_alt_end mov CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp), %rax - and $~(X86_CR4_SMEP|X86_CR4_SMAP), %rax + and $~XEN_CR4_PV32_BITS, %rax mov %rax, CPUINFO_cr4-CPUINFO_guest_cpu_user_regs(%rsp) mov %rax, %cr4 .Lcr4_alt_end:@@ -218,8 +218,10 @@ ENTRY(cr4_pv32_restore) and cr4_pv32_mask(%rip), %rax cmp cr4_pv32_mask(%rip), %rax je 1f - /* Cause cr4_pv32_mask to be visible in the BUG register dump. */ - mov cr4_pv32_mask(%rip), %rdx + /* Avoid coming back here while handling the #UD we cause below. */ + mov %cr4, %rdx + or cr4_pv32_mask(%rip), %rdx + mov %rdx, %cr4 BUG 1: #endif
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 17.05.16 at 12:28, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Instead of just latching
cr4_pv32_maskinto %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducingcr4_pv32_maskfrom the register dump.Alternatively, you can reuse %rax (as its value is useless by this point) and leave %rdx as exactly
cr4_pv32_mask. This avoids needing a subsequent step to reverse engineercr4_pv32_mask.
I don't view the value in %rax as useless - that's the set of bits we have found set, which didn't match our expectation. Hence I specifically don't want to re-use that register.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 17.05.16 at 12:28, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Instead of just latching
cr4_pv32_maskinto %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducingcr4_pv32_maskfrom the register dump.
Quoted 6 lines
Quoted 3 lines
Alternatively, you can reuse %rax (as its value is useless by this point) and leave %rdx as exactly
cr4_pv32_mask. This avoids needing a subsequent step to reverse engineercr4_pv32_mask.I don't view the value in %rax as useless - that's the set of bits we have found set, which didn't match our expectation. Hence I specifically don't want to re-use that register.
Ok. We don't need to preserve any registers from the caller, so using a different one such as %rbx or %rcx would be fine.
The issue is that it is important to see precisely what cr4_pv32_mask is.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 17.05.16 at 14:56, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 17.05.16 at 12:28, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Instead of just latching
cr4_pv32_maskinto %rdx, correct the found wrong value in %cr4 (to avoid triggering another BUG). The value left in %rdx should be sufficient for deducingcr4_pv32_maskfrom the register dump.Alternatively, you can reuse %rax (as its value is useless by this point) and leave %rdx as exactly
cr4_pv32_mask. This avoids needing a subsequent step to reverse engineercr4_pv32_mask.
Quoted 6 lines
Quoted 3 lines
I don't view the value in %rax as useless - that's the set of bits we have found set, which didn't match our expectation. Hence I specifically don't want to re-use that register.
Ok. We don't need to preserve any registers from the caller, so using a different one such as %rbx or %rcx would be fine.
Well, I can certainly (yet hesitantly) do that (and I see no harm in clobbering another register), but ...
Quoted 1 line
The issue is that it is important to see precisely what
cr4_pv32_maskis.
... it's not really clear to me what case you see where the value just written to CR4 won't give you all the information you need. After all cr4_pv32_mask doesn't have an awful lot of possible values.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel