From: Luis Henriques <luis.henriques@canonical.com>
To: Ben Hutchings <ben@decadent.org.uk>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com, Andrew Honig <ahonig@google.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: Re: [PATCH 35/72] KVM: x86: Convert MSR_KVM_SYSTEM_TIME to use gfn_to_hva_cache functions (CVE-2013-1797)
Date: Mon, 22 Apr 2013 09:55:51 +0100 [thread overview]
Message-ID: <20130422085551.GD3222@hercules> (raw)
In-Reply-To: <1366602889.3408.144.camel@deadeye.wl.decadent.org.uk>
On Mon, Apr 22, 2013 at 04:54:49AM +0100, Ben Hutchings wrote:
> On Thu, 2013-04-18 at 10:16 +0100, Luis Henriques wrote:
> > 3.5.7.11 -stable review patch. If anyone has any objections, please let me know.
> >
> > ------------------
> >
> > From: Andy Honig <ahonig@google.com>
> >
> > commit 0b79459b482e85cb7426aa7da683a9f2c97aeae1 upstream.
> >
> > There is a potential use after free issue with the handling of
> > MSR_KVM_SYSTEM_TIME. If the guest specifies a GPA in a movable or removable
> > memory such as frame buffers then KVM might continue to write to that
> > address even after it's removed via KVM_SET_USER_MEMORY_REGION. KVM pins
> > the page in memory so it's unlikely to cause an issue, but if the user
> > space component re-purposes the memory previously used for the guest, then
> > the guest will be able to corrupt that memory.
> >
> > Tested: Tested against kvmclock unit test
> >
> > Signed-off-by: Andrew Honig <ahonig@google.com>
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > [ luis: backported to 3.5:
> > - Adjust context
> > - Removed references to PVCLOCK_GUEST_STOPPED ]
> > Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
>
> This apparently needs to be followed by commit 8f964525a121 'KVM: Allow
> cross page reads and writes from cached translations.', as some guests
> don't follow the rules.
Thanks Ben, I'll add it to the queue.
Cheers,
--
Luis
>
> Ben.
>
> > ---
> > arch/x86/include/asm/kvm_host.h | 4 ++--
> > arch/x86/kvm/x86.c | 40 +++++++++++++++-------------------------
> > 2 files changed, 17 insertions(+), 27 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > index db7c1f2..9a50912 100644
> > --- a/arch/x86/include/asm/kvm_host.h
> > +++ b/arch/x86/include/asm/kvm_host.h
> > @@ -410,8 +410,8 @@ struct kvm_vcpu_arch {
> > gpa_t time;
> > struct pvclock_vcpu_time_info hv_clock;
> > unsigned int hw_tsc_khz;
> > - unsigned int time_offset;
> > - struct page *time_page;
> > + struct gfn_to_hva_cache pv_time;
> > + bool pv_time_enabled;
> >
> > struct {
> > u64 msr_val;
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index ad5cf4b..5b4ac78 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -1118,7 +1118,6 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
> > {
> > unsigned long flags;
> > struct kvm_vcpu_arch *vcpu = &v->arch;
> > - void *shared_kaddr;
> > unsigned long this_tsc_khz;
> > s64 kernel_ns, max_kernel_ns;
> > u64 tsc_timestamp;
> > @@ -1154,7 +1153,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
> >
> > local_irq_restore(flags);
> >
> > - if (!vcpu->time_page)
> > + if (!vcpu->pv_time_enabled)
> > return 0;
> >
> > /*
> > @@ -1212,14 +1211,9 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
> > */
> > vcpu->hv_clock.version += 2;
> >
> > - shared_kaddr = kmap_atomic(vcpu->time_page);
> > -
> > - memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
> > - sizeof(vcpu->hv_clock));
> > -
> > - kunmap_atomic(shared_kaddr);
> > -
> > - mark_page_dirty(v->kvm, vcpu->time >> PAGE_SHIFT);
> > + kvm_write_guest_cached(v->kvm, &vcpu->pv_time,
> > + &vcpu->hv_clock,
> > + sizeof(vcpu->hv_clock));
> > return 0;
> > }
> >
> > @@ -1508,10 +1502,7 @@ static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
> >
> > static void kvmclock_reset(struct kvm_vcpu *vcpu)
> > {
> > - if (vcpu->arch.time_page) {
> > - kvm_release_page_dirty(vcpu->arch.time_page);
> > - vcpu->arch.time_page = NULL;
> > - }
> > + vcpu->arch.pv_time_enabled = false;
> > }
> >
> > static void accumulate_steal_time(struct kvm_vcpu *vcpu)
> > @@ -1606,6 +1597,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
> > break;
> > case MSR_KVM_SYSTEM_TIME_NEW:
> > case MSR_KVM_SYSTEM_TIME: {
> > + u64 gpa_offset;
> > kvmclock_reset(vcpu);
> >
> > vcpu->arch.time = data;
> > @@ -1615,21 +1607,18 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
> > if (!(data & 1))
> > break;
> >
> > - /* ...but clean it before doing the actual write */
> > - vcpu->arch.time_offset = data & ~(PAGE_MASK | 1);
> > + gpa_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))
> > + if (gpa_offset & (sizeof(struct pvclock_vcpu_time_info) - 1))
> > break;
> >
> > - vcpu->arch.time_page =
> > - gfn_to_page(vcpu->kvm, data >> PAGE_SHIFT);
> > + if (kvm_gfn_to_hva_cache_init(vcpu->kvm,
> > + &vcpu->arch.pv_time, data & ~1ULL))
> > + vcpu->arch.pv_time_enabled = false;
> > + else
> > + vcpu->arch.pv_time_enabled = true;
> >
> > - if (is_error_page(vcpu->arch.time_page)) {
> > - kvm_release_page_clean(vcpu->arch.time_page);
> > - vcpu->arch.time_page = NULL;
> > - }
> > break;
> > }
> > case MSR_KVM_ASYNC_PF_EN:
> > @@ -2616,7 +2605,7 @@ static int kvm_vcpu_ioctl_x86_set_xcrs(struct kvm_vcpu *vcpu,
> > static int kvm_set_guest_paused(struct kvm_vcpu *vcpu)
> > {
> > struct pvclock_vcpu_time_info *src = &vcpu->arch.hv_clock;
> > - if (!vcpu->arch.time_page)
> > + if (!vcpu->arch.pv_time_enabled)
> > return -EINVAL;
> > src->flags |= PVCLOCK_GUEST_STOPPED;
> > mark_page_dirty(vcpu->kvm, vcpu->arch.time >> PAGE_SHIFT);
> > @@ -6216,6 +6205,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> > if (!zalloc_cpumask_var(&vcpu->arch.wbinvd_dirty_mask, GFP_KERNEL))
> > goto fail_free_mce_banks;
> >
> > + vcpu->arch.pv_time_enabled = false;
> > kvm_async_pf_hash_reset(vcpu);
> > kvm_pmu_init(vcpu);
> >
>
> --
> Ben Hutchings
> Klipstein's 4th Law of Prototyping and Production:
> A fail-safe circuit will destroy others.
next prev parent reply other threads:[~2013-04-22 8:55 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-18 9:15 [ 3.5.y.z extended stable ] Linux 3.5.7.11 stable review Luis Henriques
2013-04-18 9:15 ` [PATCH 01/72] ASoC: imx-ssi: Fix occasional AC97 reset failure Luis Henriques
2013-04-18 9:15 ` [PATCH 02/72] ASoC: dma-sh7760: Fix compile error Luis Henriques
2013-04-18 9:15 ` [PATCH 03/72] spi/s3c64xx: modified error interrupt handling and init Luis Henriques
2013-04-18 9:15 ` [PATCH 04/72] spi/mpc512x-psc: optionally keep PSC SS asserted across xfer segmensts Luis Henriques
2013-04-18 9:15 ` [PATCH 05/72] EISA/PCI: Fix bus res reference Luis Henriques
2013-04-18 9:15 ` [PATCH 06/72] EISA/PCI: Init EISA early, before PNP Luis Henriques
2013-04-18 9:15 ` [PATCH 07/72] mwifiex: limit channel number not to overflow memory Luis Henriques
2013-04-18 9:15 ` [PATCH 08/72] ALSA: hda - bug fix on return value when getting HDMI ELD info Luis Henriques
2013-04-18 9:15 ` [PATCH 09/72] x86: remove the x32 syscall bitmask from syscall_get_nr() Luis Henriques
2013-04-18 9:15 ` [PATCH 10/72] ixgbe: fix registration order of driver and DCA nofitication Luis Henriques
2013-04-18 9:15 ` [PATCH 11/72] Revert "drivers/rtc/rtc-at91rm9200.c: use a variable for storing IMR" Luis Henriques
2013-04-18 9:15 ` [PATCH 12/72] alpha: Add irongate_io to PCI bus resources Luis Henriques
2013-04-18 9:15 ` [PATCH 13/72] crypto: gcm - fix assumption that assoc has one segment Luis Henriques
2013-04-18 9:15 ` [PATCH 14/72] libata: Use integer return value for atapi_command_packet_set Luis Henriques
2013-04-18 9:16 ` [PATCH 15/72] libata: Set max sector to 65535 for Slimtype DVD A DS8A8SH drive Luis Henriques
2013-04-18 9:16 ` [PATCH 16/72] ata_piix: Fix DVD not dectected at some Haswell platforms Luis Henriques
2013-04-18 9:16 ` [PATCH 17/72] remoteproc: fix error path of handle_vdev Luis Henriques
2013-04-18 9:16 ` [PATCH 18/72] hwspinlock: fix __hwspin_lock_request error path Luis Henriques
2013-04-18 9:16 ` [PATCH 19/72] remoteproc: fix FW_CONFIG typo Luis Henriques
2013-04-18 9:16 ` [PATCH 20/72] powerpc: pSeries_lpar_hpte_remove fails from Adjunct partition being performed before the ANDCOND test Luis Henriques
2013-04-18 9:16 ` [PATCH 21/72] ftrace: Consistently restore trace function on sysctl enabling Luis Henriques
2013-04-18 9:16 ` [PATCH 22/72] spinlocks and preemption points need to be at least compiler barriers Luis Henriques
2013-04-18 9:16 ` [PATCH 23/72] drm/mgag200: Index 24 in extended CRTC registers is 24 in hex, not decimal Luis Henriques
2013-04-18 9:16 ` [PATCH 24/72] panic: fix a possible deadlock in panic() Luis Henriques
2013-04-18 9:16 ` [PATCH 25/72] Bluetooth: Add support for IMC Networks [13d3:3393] Luis Henriques
2013-04-18 9:16 ` [PATCH 26/72] Bluetooth: Add support for GC-WB300D PCIe [04ca:3006] to ath3k Luis Henriques
2013-04-18 9:16 ` [PATCH 27/72] Bluetooth: Add support for Foxconn / Hon Hai [0489:e04e] Luis Henriques
2013-04-18 9:16 ` [PATCH 28/72] Bluetooth: Add support for Foxconn / Hon Hai [0489:e056] Luis Henriques
2013-04-18 9:16 ` [PATCH 29/72] Bluetooth device 04ca:3008 should use ath3k Luis Henriques
2013-04-18 9:16 ` [PATCH 30/72] Bluetooth: Add support for atheros 04ca:3004 device to ath3k Luis Henriques
2013-04-18 9:16 ` [PATCH 31/72] Bluetooth: Device 0cf3:3008 should map AR 3012 Luis Henriques
2013-04-18 9:16 ` [PATCH 32/72] ALSA: hda - Enabling Realtek ALC 671 codec Luis Henriques
2013-04-18 9:16 ` [PATCH 33/72] ALSA: hda - fix typo in proc output Luis Henriques
2013-04-18 9:16 ` [PATCH 34/72] KVM: x86: fix for buffer overflow in handling of MSR_KVM_SYSTEM_TIME (CVE-2013-1796) Luis Henriques
2013-04-18 9:16 ` [PATCH 35/72] KVM: x86: Convert MSR_KVM_SYSTEM_TIME to use gfn_to_hva_cache functions (CVE-2013-1797) Luis Henriques
2013-04-22 3:54 ` Ben Hutchings
2013-04-22 8:55 ` Luis Henriques [this message]
2013-04-18 9:16 ` [PATCH 36/72] KVM: Fix bounds checking in ioapic indirect register reads (CVE-2013-1798) Luis Henriques
2013-04-18 9:16 ` [PATCH 37/72] rt2x00: rt2x00pci_regbusy_read() - only print register access failure once Luis Henriques
2013-04-18 9:16 ` [PATCH 38/72] can: gw: use kmem_cache_free() instead of kfree() Luis Henriques
2013-04-18 9:16 ` [PATCH 39/72] tracing: Fix double free when function profile init failed Luis Henriques
2013-04-18 9:16 ` [PATCH 40/72] r8169: fix auto speed down issue Luis Henriques
2013-04-18 9:16 ` [PATCH 41/72] x86: Fix rebuild with EFI_STUB enabled Luis Henriques
2013-04-18 9:16 ` [PATCH 42/72] msi-wmi: Fix memory leak Luis Henriques
2013-04-18 9:16 ` [PATCH 43/72] DRM/i915: Add QUIRK_INVERT_BRIGHTNESS for NCR machines Luis Henriques
2013-04-18 9:16 ` [PATCH 44/72] drm/i915: add quirk to invert brightness on eMachines G725 Luis Henriques
2013-04-18 9:16 ` [PATCH 45/72] drm/i915: add quirk to invert brightness on eMachines e725 Luis Henriques
2013-04-18 9:16 ` [PATCH 46/72] drm/i915: add quirk to invert brightness on Packard Bell NCL20 Luis Henriques
2013-04-18 9:16 ` [PATCH 47/72] block: avoid using uninitialized value in from queue_var_store Luis Henriques
2013-04-18 9:16 ` [PATCH 48/72] ALSA: usb-audio: fix endianness bug in snd_nativeinstruments_* Luis Henriques
2013-04-18 9:16 ` [PATCH 49/72] PM / reboot: call syscore_shutdown() after disable_nonboot_cpus() Luis Henriques
2013-04-18 9:16 ` [PATCH 50/72] ASoC: wm8903: Fix the bypass to HP/LINEOUT when no DAC or ADC is running Luis Henriques
2013-04-18 9:16 ` [PATCH 51/72] drm/i915: Use the correct size of the GTT for placing the per-process entries Luis Henriques
2013-04-18 9:16 ` [PATCH 52/72] GFS2: Fix unlock of fcntl locks during withdrawn state Luis Henriques
2013-04-18 9:16 ` [PATCH 53/72] libsas: fix handling vacant phy in sas_set_ex_phy() Luis Henriques
2013-04-18 9:16 ` [PATCH 54/72] sched_clock: Prevent 64bit inatomicity on 32bit systems Luis Henriques
2013-04-18 9:16 ` [PATCH 55/72] x86, mm, paravirt: Fix vmalloc_fault oops during lazy MMU updates Luis Henriques
2013-04-18 9:16 ` [PATCH 56/72] x86, mm: Patch out arch_flush_lazy_mmu_mode() when running on bare metal Luis Henriques
2013-04-18 9:16 ` [PATCH 57/72] cifs: Allow passwords which begin with a delimitor Luis Henriques
2013-04-18 9:16 ` [PATCH 58/72] target: Fix incorrect fallthrough of ALUA Standby/Offline/Transition CDBs Luis Henriques
2013-04-18 9:16 ` [PATCH 59/72] udl: handle EDID failure properly Luis Henriques
2013-04-18 9:16 ` [PATCH 60/72] tracing: Fix possible NULL pointer dereferences Luis Henriques
2013-04-18 9:16 ` [PATCH 61/72] ftrace: Move ftrace_filter_lseek out of CONFIG_DYNAMIC_FTRACE section Luis Henriques
2013-04-18 9:16 ` [PATCH 62/72] Btrfs: make sure nbytes are right after log replay Luis Henriques
2013-04-18 9:16 ` [PATCH 63/72] kobject: fix kset_find_obj() race with concurrent last kobject_put() Luis Henriques
2013-04-18 9:16 ` [PATCH 64/72] vfs: Revert spurious fix to spinning prevention in prune_icache_sb Luis Henriques
2013-04-18 9:16 ` [PATCH 65/72] kref: Implement kref_get_unless_zero v3 Luis Henriques
2013-04-18 9:16 ` [PATCH 66/72] mtdchar: fix offset overflow detection Luis Henriques
2013-04-22 3:56 ` Ben Hutchings
2013-04-22 8:51 ` Luis Henriques
2013-04-18 9:16 ` [PATCH 67/72] fbcon: fix locking harder Luis Henriques
2013-04-18 9:16 ` [PATCH 68/72] hrtimer: Don't reinitialize a cpu_base lock on CPU_UP Luis Henriques
2013-04-18 9:16 ` [PATCH 69/72] ARM: Do 15e0d9e37c (ARM: pm: let platforms select cpu_suspend support) properly Luis Henriques
2013-04-18 9:16 ` [PATCH 70/72] efivars: Allow disabling use as a pstore backend Luis Henriques
2013-04-18 9:16 ` [PATCH 71/72] efivars: Add module parameter to disable " Luis Henriques
2013-04-18 9:16 ` [PATCH 72/72] efivars: Fix check for CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE Luis Henriques
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130422085551.GD3222@hercules \
--to=luis.henriques@canonical.com \
--cc=ahonig@google.com \
--cc=ben@decadent.org.uk \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox