x86/hvm: Fix boundary check in hvmemul_insn_fetch()
PATCH 1/1 x86/hvm: Fix boundary check in hvmemul_insn_fetch()
c/s 0943a03037 added some extra protection for overflowing the emulation instruction cache, but Coverity points out that boundary condition is off by one when memcpy()'ing out of the buffer.
---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>
--- xen/arch/x86/hvm/emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/emulate.c +2 -2
@@ -958,8 +958,8 @@ int hvmemul_insn_fetch(* Will we overflow insn_buf[]? This shouldn't be able to happen, * which means something went wrong with instruction decoding... */ -if ( insn_off >sizeof (hvmemul_ctxt->insn_buf) || - (insn_off + bytes) >sizeof (hvmemul_ctxt->insn_buf) ) +if ( insn_off >=sizeof (hvmemul_ctxt->insn_buf) || + (insn_off + bytes) >=sizeof (hvmemul_ctxt->insn_buf) ) {ASSERT_UNREACHABLE ();return X86EMUL_UNHANDLEABLE ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 25 July 2017 19:56
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/hvm: Fix boundary check inhvmemul_insn_fetch()
Quoted 5 lines
c/s
0943a03037added some extra protection for overflowing the emulation instruction cache, but Coverity points out that boundary condition is off by one when memcpy()'ing out of the buffer.Signed-off-by Andrew Cooper <[email protected]>
Oops. Yes.
Quoted 23 lines
---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>--- xen/arch/x86/hvm/emulate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/hvm/emulate.c +2
-3@@ -958,8 +958,8 @@ int hvmemul_insn_fetch(* Will we overflow insn_buf[]? This shouldn't be able to happen, * which means something went wrong with instruction decoding... */ -if ( insn_off >sizeof (hvmemul_ctxt->insn_buf) || - (insn_off + bytes) >sizeof (hvmemul_ctxt->insn_buf) ) +if ( insn_off >=sizeof (hvmemul_ctxt->insn_buf) || + (insn_off + bytes) >=sizeof (hvmemul_ctxt->insn_buf) ) {ASSERT_UNREACHABLE ();return X86EMUL_UNHANDLEABLE ; --
Quoted 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
xen/arch/x86/hvm/emulate.c int hvmemul_insn_fetch( · line 962
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Andrew Cooper <[email protected]> 07/25/17 8:55 PM >>>
xen/arch/x86/hvm/emulate.c +2
-2@@ -958,8 +958,8 @@ int hvmemul_insn_fetch(* Will we overflow insn_buf[]? This shouldn't be able to happen, * which means something went wrong with instruction decoding... */ -if ( insn_off >sizeof (hvmemul_ctxt->insn_buf) || - (insn_off + bytes) >sizeof (hvmemul_ctxt->insn_buf) ) +if ( insn_off >=sizeof (hvmemul_ctxt->insn_buf) || + (insn_off + bytes) >=sizeof (hvmemul_ctxt->insn_buf) )
I agree with the change to the first line, but are you sure about the second one? At the example of insn_off == 0, surely
bytes == sizeof() is fine?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel