x86/emul: Poision the stubs with debug traps
PATCH 1/1 x86/emul: Poision the stubs with debug traps
...rather than leaving fragments of old instructions in place. This reduces the chances of something going further-wrong (as the debug trap will be cause and terminate the guest) in a cascade-failure where we end up executing the instruction fragments.
Before:
(XEN) d2v0 exception 6 (ec=0000) in emulation stub (line 6239)
(XEN) d2v0 stub: c4 e1 44 77 c3 80 d0 82 ff ff ff d1 90 ec 90After:
(XEN) d3v0 exception 6 (ec=0000) in emulation stub (line 6239) (XEN) d3v0 stub: c4 e1 44 77 c3 cc cc cc cc cc cc cc cc cc cc
---
CC: Jan Beulich <[email protected]>
Semi-RFC: I really don't like (ab)use of memset, but can't think of a cleaner way of doing this.
--- xen/arch/x86/x86_emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/x86_emulate.c +2 -2
@@ -30,8 +30,8 @@BUILD_BUG_ON (STUB_BUF_SIZE /2 <MAX_INST_LEN +1 ); \ASSERT (!(stb).ptr); \ (stb).addr =this_cpu (stubs.addr) +STUB_BUF_SIZE /2 ; \ - ((stb).ptr =map_domain_page (_mfn (this_cpu (stubs.mfn)))) + \ - ((stb).addr & ~PAGE_MASK ); \ +memset (((stb).ptr =map_domain_page (_mfn (this_cpu (stubs.mfn)))) + \ + ((stb).addr & ~PAGE_MASK ),0xcc ,STUB_BUF_SIZE /2 ); \ })#define put_stub (stb) ({ \ if ( (stb).ptr ) \
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.03.17 at 16:39, <[email protected]> wrote:
...rather than leaving fragments of old instructions in place. This reduces the chances of something going further-wrong (as the debug trap will be cause and terminate the guest) in a cascade-failure where we end up executing the instruction fragments.
Where are you taking the "and terminate the guest" from? As far as I can see, do_int3() does nothing at all for an INT3 from hypervisor context (without CRASH_DEBUG), so we'd just take a row of INT3s until we hit the end of stub space (running either past the page boundary or into the next CPU's stub space, which is the syscall entry code).
Quoted 3 lines
Before:
(XEN) d2v0 exception 6 (ec=0000) in emulation stub (line 6239) (XEN) d2v0 stub: c4 e1 44 77 c3 80 d0 82 ff ff ff d1 90 ec 90
Hmm, this is concerning: I don't think we have ways to generate 15-byte instructions into the stub, so where are all these non-zero bytes coming from? After all alloc_stub_page() pre-fills the page with all 0xCC.
Quoted 10 lines
After:
(XEN) d3v0 exception 6 (ec=0000) in emulation stub (line 6239) (XEN) d3v0 stub: c4 e1 44 77 c3 cc cc cc cc cc cc cc cc cc ccSigned-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>Semi-RFC: I really don't like (ab)use of memset, but can't think of a cleaner way of doing this.
What abuse are you seeing here?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.03.17 at 16:39, <[email protected]> wrote:
...rather than leaving fragments of old instructions in place. This reduces the chances of something going further-wrong (as the debug trap will be cause and terminate the guest) in a cascade-failure where we end up executing the instruction fragments.
Where are you taking the "and terminate the guest" from?
Memory, which has proved to be a poor source of information.
Quoted 6 lines
As far as
I can see,do_int3()does nothing at all for an INT3 from hypervisor context (withoutCRASH_DEBUG), so we'd just take a row of INT3s until we hit the end of stub space (running either past the page boundary or into the next CPU's stub space, which is the syscall entry code).
I will see about fixing this, so any exception in the stubs gets bounced back.
Quoted 7 lines
Quoted 4 lines
Before:
(XEN) d2v0 exception 6 (ec=0000) in emulation stub (line 6239) (XEN) d2v0 stub: c4 e1 44 77 c3 80 d0 82 ff ff ff d1 90 ec 90Hmm, this is concerning: I don't think we have ways to generate 15-byte instructions into the stub, so where are all these non-zero bytes coming from?
This is the host_to_guest_gpr_switch invocation in io_emul_stub_setup(), which uses 15 bytes of stub.
Quoted 7 lines
After all
alloc_stub_page()pre-fills the page
with all0xCC.Quoted 4 lines
After:
(XEN) d3v0 exception 6 (ec=0000) in emulation stub (line 6239) (XEN) d3v0 stub: c4 e1 44 77 c3 cc cc cc cc cc cc cc cc cc cc
Quoted 7 lines
Quoted 6 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>Semi-RFC: I really don't like (ab)use of memset, but can't think of a cleaner way of doing this.
What abuse are you seeing here?
The semantics used here are "return memset((a = b) + offset, ...);" where the assignment is unrelated to the value returned, which is propagated through memset returning its first parameter.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel