* [PATCH v5 1/3] kvm: vmx: fix limit checking in get_vmx_mem_address()
@ 2019-06-07 6:02 Eugene Korenevsky
2019-06-07 15:00 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Eugene Korenevsky @ 2019-06-07 6:02 UTC (permalink / raw)
To: kvm; +Cc: Paolo Bonzini, Sean Christopherson
Intel SDM vol. 3, 5.3:
The processor causes a
general-protection exception (or, if the segment is SS, a stack-fault
exception) any time an attempt is made to access the following addresses
in a segment:
- A byte at an offset greater than the effective limit
- A word at an offset greater than the (effective-limit – 1)
- A doubleword at an offset greater than the (effective-limit – 3)
- A quadword at an offset greater than the (effective-limit – 7)
Therefore, the generic limit checking error condition must be
exn = (off > limit + 1 - access_len) = (off + access_len - 1 > limit)
but not
exn = (off + access_len > limit)
as for now.
Also avoid integer overflow of `off` at 32-bit KVM by casting it to u64.
Note: access length is currently sizeof(u64) which is incorrect. This
will be fixed in the subsequent patch.
Signed-off-by: Eugene Korenevsky <ekorenevsky@gmail.com>
---
Changes in v3 since v2: fixed limit checking condition to avoid underflow;
added note
Changes in v4 since v3: fixed `off` overflow at 32-bit by casting to u64
arch/x86/kvm/vmx/nested.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index f1a69117ac0f..1a51bff129a8 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4115,7 +4115,7 @@ int get_vmx_mem_address(struct kvm_vcpu *vcpu, unsigned long exit_qualification,
*/
if (!(s.base == 0 && s.limit == 0xffffffff &&
((s.type & 8) || !(s.type & 4))))
- exn = exn || (off + sizeof(u64) > s.limit);
+ exn = exn || ((u64)off + sizeof(u64) - 1 > s.limit);
}
if (exn) {
kvm_queue_exception_e(vcpu,
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v5 1/3] kvm: vmx: fix limit checking in get_vmx_mem_address()
2019-06-07 6:02 [PATCH v5 1/3] kvm: vmx: fix limit checking in get_vmx_mem_address() Eugene Korenevsky
@ 2019-06-07 15:00 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2019-06-07 15:00 UTC (permalink / raw)
To: Eugene Korenevsky, kvm, Paolo Bonzini
On Fri, Jun 07, 2019 at 09:02:48AM +0300, Eugene Korenevsky wrote:
> Intel SDM vol. 3, 5.3:
> The processor causes a
> general-protection exception (or, if the segment is SS, a stack-fault
> exception) any time an attempt is made to access the following addresses
> in a segment:
> - A byte at an offset greater than the effective limit
> - A word at an offset greater than the (effective-limit – 1)
> - A doubleword at an offset greater than the (effective-limit – 3)
> - A quadword at an offset greater than the (effective-limit – 7)
>
> Therefore, the generic limit checking error condition must be
>
> exn = (off > limit + 1 - access_len) = (off + access_len - 1 > limit)
>
> but not
>
> exn = (off + access_len > limit)
>
> as for now.
>
> Also avoid integer overflow of `off` at 32-bit KVM by casting it to u64.
>
> Note: access length is currently sizeof(u64) which is incorrect. This
> will be fixed in the subsequent patch.
>
> Signed-off-by: Eugene Korenevsky <ekorenevsky@gmail.com>
When sending a new revision of a patch, please add any supplied tags to
the changelog, e.g. Reviewed-by, Tested-by, Acked-by, etc... For example,
my Reviewed-by for v4 of this patch.
The one situation where you don't want to carry tags is if you make
non-trivial changes to a patch, e.g. person X reviews a patch but then
it gets reworked based on feedback from person Y, in which case the
Reviewed-by from X should be dropped as they haven't reviewed the new
code.
Thans for the patches!
Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-07 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-07 6:02 [PATCH v5 1/3] kvm: vmx: fix limit checking in get_vmx_mem_address() Eugene Korenevsky
2019-06-07 15:00 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).