OSDN Git Service

kvm: vmx: fix limit checking in get_vmx_mem_address()
authorEugene Korenevsky <ekorenevsky@gmail.com>
Wed, 5 Jun 2019 21:17:39 +0000 (00:17 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 18 Jun 2019 09:43:45 +0000 (11:43 +0200)
commitc1a9acbc5295e278d788e9f7510f543bc9864fa2
tree36ecbc2d28a22fcbfa7d861d58b99171307b6746
parenta87f2d3a6eadabad3ce3a8a57c1dd04c14b856ba
kvm: vmx: fix limit checking in get_vmx_mem_address()

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>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/nested.c