Patchwork [Lucid,Precise,Quantal,Raring,CVE-2013-1796] KVM: x86: fix for buffer overflow in handling of MSR_KVM_SYSTEM_TIME (CVE-2013-1796)

login
register
mail settings
Submitter Luis Henriques
Date April 5, 2013, 11:33 a.m.
Message ID <1365161596-11996-1-git-send-email-luis.henriques@canonical.com>
Download mbox | patch
Permalink /patch/234113/
State New
Headers show

Comments

Luis Henriques - April 5, 2013, 11:33 a.m.
From: Andy Honig <ahonig@google.com>

CVE-2013-1796

BugLink: http://bugs.launchpad.net/bugs/1158254

If the guest sets the GPA of the time_page so that the request to update the
time straddles a page then KVM will write onto an incorrect page.  The
write is done byusing kmap atomic to get a pointer to the page for the time
structure and then performing a memcpy to that page starting at an offset
that the guest controls.  Well behaved guests always provide a 32-byte aligned
address, however a malicious guest could use this to corrupt host kernel
memory.

Tested: Tested against kvmclock unit test.

Signed-off-by: Andrew Honig <ahonig@google.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
(cherry picked from commit c300aa64ddf57d9c5d9c898a64b36877345dd4a9)

Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
 arch/x86/kvm/x86.c | 5 +++++
 1 file changed, 5 insertions(+)
Stefan Bader - April 5, 2013, 11:51 a.m.
On 05.04.2013 13:33, Luis Henriques wrote:
> From: Andy Honig <ahonig@google.com>
> 
> CVE-2013-1796
> 
> BugLink: http://bugs.launchpad.net/bugs/1158254
> 
> If the guest sets the GPA of the time_page so that the request to update the
> time straddles a page then KVM will write onto an incorrect page.  The
> write is done byusing kmap atomic to get a pointer to the page for the time
> structure and then performing a memcpy to that page starting at an offset
> that the guest controls.  Well behaved guests always provide a 32-byte aligned
> address, however a malicious guest could use this to corrupt host kernel
> memory.
> 
> Tested: Tested against kvmclock unit test.
> 
> Signed-off-by: Andrew Honig <ahonig@google.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> (cherry picked from commit c300aa64ddf57d9c5d9c898a64b36877345dd4a9)
> 
> Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
> ---
>  arch/x86/kvm/x86.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index a52bd56..3fee182 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1635,6 +1635,11 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
>  		/* ...but clean it before doing the actual write */
>  		vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
>  
> +		/* Check that the address is 32-byte aligned. */
> +		if (vcpu->arch.time_offset &
> +				(sizeof(struct pvclock_vcpu_time_info) - 1))
> +			break;
> +
>  		vcpu->arch.time_page =
>  				gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
>  
> 
Its cherry-picked. Still don't like the implicit assumptions. :-P But ack anyway.
Tim Gardner - April 5, 2013, 12:26 p.m.

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a52bd56..3fee182 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1635,6 +1635,11 @@  int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 		/* ...but clean it before doing the actual write */
 		vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
 
+		/* Check that the address is 32-byte aligned. */
+		if (vcpu->arch.time_offset &
+				(sizeof(struct pvclock_vcpu_time_info) - 1))
+			break;
+
 		vcpu->arch.time_page =
 				gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);