From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Andy Honig" <ahonig@google.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>
Subject: [72/75] KVM: x86: Convert MSR_KVM_SYSTEM_TIME to use gfn_to_hva_cache functions (CVE-2013-1797)
Date: Mon, 22 Apr 2013 15:25:59 +0100 [thread overview]
Message-ID: <lsq.1366640759.112111845@decadent.org.uk> (raw)
In-Reply-To: <lsq.1366640759.151900666@decadent.org.uk>
3.2.44-rc1 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>
[bwh: Backported to 3.2:
- Adjust context
- We do not implement the PVCLOCK_GUEST_STOPPED flag]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -393,8 +393,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;
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1105,7 +1105,6 @@ static int kvm_guest_time_update(struct
{
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;
@@ -1141,7 +1140,7 @@ static int kvm_guest_time_update(struct
local_irq_restore(flags);
- if (!vcpu->time_page)
+ if (!vcpu->pv_time_enabled)
return 0;
/*
@@ -1199,14 +1198,9 @@ static int kvm_guest_time_update(struct
*/
vcpu->hv_clock.version += 2;
- shared_kaddr = kmap_atomic(vcpu->time_page, KM_USER0);
-
- memcpy(shared_kaddr + vcpu->time_offset, &vcpu->hv_clock,
- sizeof(vcpu->hv_clock));
-
- kunmap_atomic(shared_kaddr, KM_USER0);
-
- 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;
}
@@ -1496,10 +1490,7 @@ static int kvm_pv_enable_async_pf(struct
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)
@@ -1591,6 +1582,7 @@ int kvm_set_msr_common(struct kvm_vcpu *
break;
case MSR_KVM_SYSTEM_TIME_NEW:
case MSR_KVM_SYSTEM_TIME: {
+ u64 gpa_offset;
kvmclock_reset(vcpu);
vcpu->arch.time = data;
@@ -1600,21 +1592,17 @@ int kvm_set_msr_common(struct kvm_vcpu *
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 (is_error_page(vcpu->arch.time_page)) {
- kvm_release_page_clean(vcpu->arch.time_page);
- vcpu->arch.time_page = NULL;
- }
+ 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;
break;
}
case MSR_KVM_ASYNC_PF_EN:
@@ -6554,6 +6542,7 @@ int kvm_arch_vcpu_init(struct kvm_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);
return 0;
next prev parent reply other threads:[~2013-04-22 14:29 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-22 14:25 [00/75] 3.2.44-rc1 review Ben Hutchings
2013-04-22 14:25 ` [58/75] drm/i915: panel: invert brightness acer aspire 5734z Ben Hutchings
2013-04-22 14:25 ` [59/75] DRM/i915: Add QUIRK_INVERT_BRIGHTNESS for NCR machines Ben Hutchings
2013-04-22 14:25 ` [34/75] x86, mm, paravirt: Fix vmalloc_fault oops during lazy MMU updates Ben Hutchings
2013-04-22 14:25 ` [18/75] crypto: gcm - fix assumption that assoc has one segment Ben Hutchings
2013-04-22 14:25 ` [03/75] USB: ark3116: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [46/75] can: sja1000: fix handling on dt properties on little endian systems Ben Hutchings
2013-04-22 14:25 ` [28/75] ftrace: Consistently restore trace function on sysctl enabling Ben Hutchings
2013-04-22 14:25 ` [38/75] tracing: Fix possible NULL pointer dereferences Ben Hutchings
2013-04-22 14:25 ` [40/75] kref: Implement kref_get_unless_zero v3 Ben Hutchings
2013-04-22 14:25 ` [75/75] sched: Convert BUG_ON()s in try_to_wake_up_local() to WARN_ON_ONCE()s Ben Hutchings
2013-04-22 14:25 ` [09/75] USB: mct_u232: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [61/75] drm/i915: add quirk to invert brightness on eMachines e725 Ben Hutchings
2013-04-22 14:25 ` [25/75] alpha: Add irongate_io to PCI bus resources Ben Hutchings
2013-04-22 14:25 ` [45/75] of: introduce helper to manage boolean Ben Hutchings
2013-04-22 14:25 ` [63/75] msi-wmi: Fix memory leak Ben Hutchings
2013-04-22 14:25 ` [08/75] USB: io_ti: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [27/75] sched_clock: Prevent 64bit inatomicity on 32bit systems Ben Hutchings
2013-04-22 14:25 ` [37/75] target: Fix incorrect fallthrough of ALUA Standby/Offline/Transition CDBs Ben Hutchings
2013-04-22 14:25 ` [62/75] drm/i915: add quirk to invert brightness on Packard Bell NCL20 Ben Hutchings
2013-04-22 14:25 ` [26/75] powerpc: pSeries_lpar_hpte_remove fails from Adjunct partition being performed before the ANDCOND test Ben Hutchings
2013-04-22 14:25 ` [57/75] drm/i915: panel: invert brightness via quirk Ben Hutchings
2013-04-22 14:25 ` [12/75] USB: oti6858: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [74/75] KVM: Allow cross page reads and writes from cached translations Ben Hutchings
2013-04-22 14:25 ` [50/75] hugetlbfs: add swap entry check in follow_hugetlb_page() Ben Hutchings
2013-04-22 14:25 ` [06/75] USB: ftdi_sio: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [21/75] libata: Set max sector to 65535 for Slimtype DVD A DS8A8SH drive Ben Hutchings
2013-04-22 14:25 ` [48/75] ARM: 7696/1: Fix kexec by setting outer_cache.inv_all for Feroceon Ben Hutchings
2013-04-22 14:25 ` [19/75] rt2x00: rt2x00pci_regbusy_read() - only print register access failure once Ben Hutchings
2013-04-22 14:25 ` [31/75] ASoC: wm8903: Fix the bypass to HP/LINEOUT when no DAC or ADC is running Ben Hutchings
2013-04-22 14:25 ` [66/75] block: avoid using uninitialized value in from queue_var_store Ben Hutchings
2013-04-22 14:25 ` [29/75] PM / reboot: call syscore_shutdown() after disable_nonboot_cpus() Ben Hutchings
2013-04-22 14:25 ` [71/75] KVM: x86: fix for buffer overflow in handling of MSR_KVM_SYSTEM_TIME (CVE-2013-1796) Ben Hutchings
2013-04-22 14:25 ` [22/75] ata_piix: Fix DVD not dectected at some Haswell platforms Ben Hutchings
2013-04-22 14:25 ` [69/75] fbcon: fix locking harder Ben Hutchings
2013-04-22 14:25 ` [10/75] USB: mos7840: fix broken TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [20/75] libata: Use integer return value for atapi_command_packet_set Ben Hutchings
2013-04-22 14:25 ` [44/75] ath9k_htc: accept 1.x firmware newer than 1.3 Ben Hutchings
2013-04-22 14:25 ` [42/75] vfs: Revert spurious fix to spinning prevention in prune_icache_sb Ben Hutchings
2013-04-22 14:25 ` [54/75] writeback: fix dirtied pages accounting on redirty Ben Hutchings
2013-04-22 14:25 ` [11/75] USB: mos7840: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [07/75] USB: io_edgeport: " Ben Hutchings
2013-04-22 14:25 ` [15/75] USB: ssu100: " Ben Hutchings
2013-04-22 14:25 ` [65/75] ALSA: hda - fix typo in proc output Ben Hutchings
2013-04-22 14:25 ` [68/75] mtd: Disable mtdchar mmap on MMU systems Ben Hutchings
2013-04-22 14:25 ` Ben Hutchings [this message]
2013-04-22 14:25 ` [04/75] USB: ch341: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [14/75] USB: spcp8x5: " Ben Hutchings
2013-04-22 14:25 ` [60/75] drm/i915: add quirk to invert brightness on eMachines G725 Ben Hutchings
2013-04-22 14:25 ` [73/75] KVM: Fix bounds checking in ioapic indirect register reads (CVE-2013-1798) Ben Hutchings
2013-04-22 14:25 ` [55/75] Btrfs: fix race between mmap writes and compression Ben Hutchings
2013-04-22 14:25 ` [02/75] USB: serial: fix hang when opening port Ben Hutchings
2013-04-22 14:25 ` [05/75] USB: cypress_m8: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [52/75] net: fix incorrect credentials passing Ben Hutchings
2013-04-22 14:25 ` [17/75] hrtimer: Don't reinitialize a cpu_base lock on CPU_UP Ben Hutchings
2013-04-22 14:25 ` [33/75] tracing: Fix double free when function profile init failed Ben Hutchings
2013-04-22 14:25 ` [16/75] USB: ti_usb_3410_5052: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [35/75] x86, mm: Patch out arch_flush_lazy_mmu_mode() when running on bare metal Ben Hutchings
2013-04-22 14:25 ` [56/75] drm/i915: panel: invert brightness via parameter Ben Hutchings
2013-04-22 14:25 ` [23/75] hwspinlock: fix __hwspin_lock_request error path Ben Hutchings
2013-04-22 14:25 ` [47/75] ath9k_hw: change AR9580 initvals to fix a stability issue Ben Hutchings
2013-04-22 14:25 ` [24/75] ALSA: usb-audio: fix endianness bug in snd_nativeinstruments_* Ben Hutchings
2013-04-22 14:25 ` [39/75] Btrfs: make sure nbytes are right after log replay Ben Hutchings
2013-04-22 14:25 ` [67/75] r8169: fix auto speed down issue Ben Hutchings
2013-04-22 14:25 ` [36/75] target: Fix MAINTENANCE_IN service action CDB checks to use lower 5 bits Ben Hutchings
2013-04-22 14:25 ` [43/75] ARM: Do 15e0d9e37c (ARM: pm: let platforms select cpu_suspend support) properly Ben Hutchings
2013-04-22 14:25 ` [49/75] ARM: 7698/1: perf: fix group validation when using enable_on_exec Ben Hutchings
2013-04-22 14:25 ` [30/75] can: gw: use kmem_cache_free() instead of kfree() Ben Hutchings
2013-04-22 14:25 ` [13/75] USB: pl2303: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-04-22 14:25 ` [64/75] ALSA: hda - Enabling Realtek ALC 671 codec Ben Hutchings
2013-04-22 14:25 ` [41/75] kobject: fix kset_find_obj() race with concurrent last kobject_put() Ben Hutchings
2013-04-22 14:25 ` [51/75] kernel/signal.c: stop info leak via the tkill and the tgkill syscalls Ben Hutchings
2013-04-22 14:25 ` [01/75] USB: serial: add modem-status-change wait queue Ben Hutchings
2013-04-22 14:25 ` [53/75] thermal: return an error on failure to register thermal class Ben Hutchings
2013-04-22 14:25 ` [32/75] spinlocks and preemption points need to be at least compiler barriers Ben Hutchings
2013-04-22 14:25 ` [70/75] hfsplus: fix potential overflow in hfsplus_file_truncate() Ben Hutchings
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=lsq.1366640759.112111845@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=ahonig@google.com \
--cc=akpm@linux-foundation.org \
--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
all inboxes | Powered by JetHome®