public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Andrew Honig <ahonig@google.com>, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [068/126] KVM: x86: Convert MSR_KVM_SYSTEM_TIME to use gfn_to_hva_cache functions (CVE-2013-1797)
Date: Mon, 06 May 2013 23:58:20 -0400	[thread overview]
Message-ID: <20130507035852.261093152@goodmis.org> (raw)
In-Reply-To: 20130507035712.909872333@goodmis.org

[-- Attachment #1: 0068-KVM-x86-Convert-MSR_KVM_SYSTEM_TIME-to-use-gfn_to_hv.patch --]
[-- Type: text/plain, Size: 4708 bytes --]

3.6.11.3 stable review patch.
If anyone has any objections, please let me know.

------------------

From: Andy Honig <ahonig@google.com>

[ Upstream commit 0b79459b482e85cb7426aa7da683a9f2c97aeae1 ]

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>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 arch/x86/include/asm/kvm_host.h |    4 ++--
 arch/x86/kvm/x86.c              |   41 ++++++++++++++-------------------------
 2 files changed, 17 insertions(+), 28 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 09155d6..69c9a92 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -418,8 +418,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 142e18a..2bf95c0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1136,7 +1136,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;
@@ -1172,7 +1171,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;
 
 	/*
@@ -1230,14 +1229,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;
 }
 
@@ -1526,10 +1520,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)
@@ -1624,6 +1615,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;
@@ -1633,21 +1625,17 @@ 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 (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:
@@ -2641,7 +2629,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);
@@ -6237,6 +6225,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);
 
-- 
1.7.10.4



  parent reply	other threads:[~2013-05-07  3:58 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-07  3:57 [000/126] 3.6.11.3-stable review Steven Rostedt
2013-05-07  3:57 ` [001/126] ASoC: imx-ssi: Fix occasional AC97 reset failure Steven Rostedt
2013-05-07  3:57 ` [002/126] ASoC: dma-sh7760: Fix compile error Steven Rostedt
2013-05-07  3:57 ` [003/126] ASoC: spear_pcm: Update to new pcm_new() API Steven Rostedt
2013-05-07  3:57 ` [004/126] regmap: cache Fix regcache-rbtree sync Steven Rostedt
2013-05-07  3:57 ` [005/126] spi/s3c64xx: modified error interrupt handling and init Steven Rostedt
2013-05-07  3:57 ` [006/126] spi/mpc512x-psc: optionally keep PSC SS asserted across xfer segmensts Steven Rostedt
2013-05-07  3:57 ` [007/126] UBIFS: make space fixup work in the remount case Steven Rostedt
2013-05-07  3:57 ` [008/126] ALSA: hda - Enabling Realtek ALC 671 codec Steven Rostedt
2013-05-07  3:57 ` [009/126] ALSA: hda - fix typo in proc output Steven Rostedt
2013-05-07  3:57 ` [010/126] mm: prevent mmap_cache race in find_vma() Steven Rostedt
2013-05-07  3:57 ` [011/126] EISA/PCI: Init EISA early, before PNP Steven Rostedt
2013-05-07  3:57 ` [012/126] EISA/PCI: Fix bus res reference Steven Rostedt
2013-05-07  3:57 ` [013/126] libata: Use integer return value for atapi_command_packet_set Steven Rostedt
2013-05-07  3:57 ` [014/126] libata: Set max sector to 65535 for Slimtype DVD A DS8A8SH drive Steven Rostedt
2013-05-07  3:57 ` [015/126] alpha: Add irongate_io to PCI bus resources Steven Rostedt
2013-05-07  3:57 ` [016/126] PCI/PM: Disable runtime PM of PCIe ports Steven Rostedt
2013-05-07  3:57 ` [017/126] ata_piix: Fix DVD not dectected at some Haswell platforms Steven Rostedt
2013-05-07  3:57 ` [018/126] ftrace: Consistently restore trace function on sysctl enabling Steven Rostedt
2013-05-07  3:57 ` [019/126] powerpc: pSeries_lpar_hpte_remove fails from Adjunct partition being performed before the ANDCOND test Steven Rostedt
2013-05-07  3:57 ` [020/126] mwifiex: limit channel number not to overflow memory Steven Rostedt
2013-05-07  3:57 ` [021/126] mac80211: fix remain-on-channel cancel crash Steven Rostedt
2013-05-07  3:57 ` [022/126] x86: remove the x32 syscall bitmask from syscall_get_nr() Steven Rostedt
2013-05-07  3:57 ` [023/126] hwspinlock: fix __hwspin_lock_request error path Steven Rostedt
2013-05-07  3:57 ` [024/126] remoteproc: fix error path of handle_vdev Steven Rostedt
2013-05-07  3:57 ` [025/126] remoteproc: fix FW_CONFIG typo Steven Rostedt
2013-05-07  3:57 ` [026/126] spinlocks and preemption points need to be at least compiler barriers Steven Rostedt
2013-05-07  3:57 ` [027/126] crypto: ux500 - add missing comma Steven Rostedt
2013-05-07  3:57 ` [028/126] crypto: gcm - fix assumption that assoc has one segment Steven Rostedt
2013-05-07  3:57 ` [029/126] drm/mgag200: Index 24 in extended CRTC registers is 24 in hex, not decimal Steven Rostedt
2013-05-07  3:57 ` [030/126] block: avoid using uninitialized value in from queue_var_store Steven Rostedt
2013-05-07  3:57 ` [031/126] x86: Fix rebuild with EFI_STUB enabled Steven Rostedt
2013-05-07  3:57 ` [032/126] thermal: return an error on failure to register thermal class Steven Rostedt
2013-05-07  3:57 ` [033/126] msi-wmi: Fix memory leak Steven Rostedt
2013-05-07  3:57 ` [034/126] cpufreq: exynos: Get booting freq value in exynos_cpufreq_init Steven Rostedt
2013-05-07  3:57 ` [035/126] drm/i915: add quirk to invert brightness on eMachines G725 Steven Rostedt
2013-05-07  3:57 ` [036/126] drm/i915: add quirk to invert brightness on eMachines e725 Steven Rostedt
2013-05-07  3:57 ` [037/126] drm/i915: add quirk to invert brightness on Packard Bell NCL20 Steven Rostedt
2013-05-07  3:57 ` [038/126] r8169: fix auto speed down issue Steven Rostedt
2013-05-07  3:57 ` [039/126] vfio-pci: Fix possible integer overflow Steven Rostedt
2013-05-07  3:57 ` [040/126] can: gw: use kmem_cache_free() instead of kfree() Steven Rostedt
2013-05-07  3:57 ` [041/126] rt2x00: rt2x00pci_regbusy_read() - only print register access failure once Steven Rostedt
2013-05-07  3:57 ` [042/126] ALSA: usb-audio: fix endianness bug in snd_nativeinstruments_* Steven Rostedt
2013-05-07  3:57 ` [043/126] ASoC: wm8903: Fix the bypass to HP/LINEOUT when no DAC or ADC is running Steven Rostedt
2013-05-07  3:57 ` [044/126] tracing: Fix double free when function profile init failed Steven Rostedt
2013-05-07  3:57 ` [045/126] PM / reboot: call syscore_shutdown() after disable_nonboot_cpus() Steven Rostedt
2013-05-07  3:57 ` [046/126] GFS2: Fix unlock of fcntl locks during withdrawn state Steven Rostedt
2013-05-07  3:57 ` [047/126] libsas: fix handling vacant phy in sas_set_ex_phy() Steven Rostedt
2013-05-07  3:58 ` [048/126] cifs: Allow passwords which begin with a delimitor Steven Rostedt
2013-05-07  3:58 ` [049/126] target: Fix incorrect fallthrough of ALUA Standby/Offline/Transition CDBs Steven Rostedt
2013-05-07  3:58 ` [050/126] vfs: Revert spurious fix to spinning prevention in prune_icache_sb Steven Rostedt
2013-05-07  3:58 ` [051/126] kref: Implement kref_get_unless_zero v3 Steven Rostedt
2013-05-07  3:58 ` [052/126] kobject: fix kset_find_obj() race with concurrent last kobject_put() Steven Rostedt
2013-05-07  3:58 ` [053/126] x86-32: Fix possible incomplete TLB invalidate with PAE pagetables Steven Rostedt
2013-05-07  3:58 ` [054/126] tracing: Fix possible NULL pointer dereferences Steven Rostedt
2013-05-07  3:58 ` [055/126] udl: handle EDID failure properly Steven Rostedt
2013-05-07  3:58 ` [056/126] ftrace: Move ftrace_filter_lseek out of CONFIG_DYNAMIC_FTRACE section Steven Rostedt
2013-05-07  3:58 ` [057/126] sched_clock: Prevent 64bit inatomicity on 32bit systems Steven Rostedt
2013-05-07  3:58 ` [058/126] x86, mm, paravirt: Fix vmalloc_fault oops during lazy MMU updates Steven Rostedt
2013-05-07  3:58 ` [059/126] x86, mm: Patch out arch_flush_lazy_mmu_mode() when running on bare metal Steven Rostedt
2013-05-07  3:58 ` [060/126] ARM: Do 15e0d9e37c (ARM: pm: let platforms select cpu_suspend support) properly Steven Rostedt
2013-05-07  3:58 ` [061/126] hrtimer: Dont reinitialize a cpu_base lock on CPU_UP Steven Rostedt
2013-05-07  3:58 ` [062/126] can: mcp251x: add missing IRQF_ONESHOT to request_threaded_irq Steven Rostedt
2013-05-07  3:58 ` [063/126] can: sja1000: fix handling on dt properties on little endian systems Steven Rostedt
2013-05-07  3:58 ` [064/126] hugetlbfs: add swap entry check in follow_hugetlb_page() Steven Rostedt
2013-05-07  3:58 ` [065/126] kernel/signal.c: stop info leak via the tkill and the tgkill syscalls Steven Rostedt
2013-05-07  3:58 ` [066/126] hfsplus: fix potential overflow in hfsplus_file_truncate() Steven Rostedt
2013-05-07  3:58 ` [067/126] KVM: x86: fix for buffer overflow in handling of MSR_KVM_SYSTEM_TIME (CVE-2013-1796) Steven Rostedt
2013-05-07  3:58 ` Steven Rostedt [this message]
2013-05-07  3:58 ` [069/126] KVM: Fix bounds checking in ioapic indirect register reads (CVE-2013-1798) Steven Rostedt
2013-05-07  3:58 ` [070/126] KVM: Allow cross page reads and writes from cached translations Steven Rostedt
2013-05-07  3:58 ` [071/126] ARM: i.MX35: enable MAX clock Steven Rostedt
2013-05-07  3:58 ` [072/126] ARM: clk-imx35: Bugfix iomux clock Steven Rostedt
2013-05-07  3:58 ` [073/126] tg3: Add 57766 device support Steven Rostedt
2013-05-07  3:58 ` [074/126] sched: Convert BUG_ON()s in try_to_wake_up_local() to WARN_ON_ONCE()s Steven Rostedt
2013-05-07  3:58 ` [075/126] ARM: 7696/1: Fix kexec by setting outer_cache.inv_all for Feroceon Steven Rostedt
2013-05-07  3:58 ` [076/126] ARM: 7698/1: perf: fix group validation when using enable_on_exec Steven Rostedt
2013-05-07  3:58 ` [077/126] ath9k_htc: accept 1.x firmware newer than 1.3 Steven Rostedt
2013-05-07  3:58 ` [078/126] ath9k_hw: change AR9580 initvals to fix a stability issue Steven Rostedt
2013-05-07  3:58 ` [079/126] mac80211: fix cfg80211 interaction on auth/assoc request Steven Rostedt
2013-05-07  3:58 ` [080/126] ssb: implement spurious tone avoidance Steven Rostedt
2013-05-07  3:58 ` [081/126] crypto: algif - suppress sending source address information in recvmsg Steven Rostedt
2013-05-07  3:58 ` [082/126] perf: Treat attr.config as u64 in perf_swevent_init() Steven Rostedt
2013-05-07  3:58 ` [083/126] perf/x86: Fix offcore_rsp valid mask for SNB/IVB Steven Rostedt
2013-05-07  3:58 ` [084/126] vm: add vm_iomap_memory() helper function Steven Rostedt
2013-05-07  3:58 ` [085/126] vm: convert snd_pcm_lib_mmap_iomem() to vm_iomap_memory() helper Steven Rostedt
2013-05-07  3:58 ` [086/126] vm: convert fb_mmap " Steven Rostedt
2013-05-07  3:58 ` [087/126] vm: convert HPET mmap " Steven Rostedt
2013-05-07  3:58 ` [088/126] mtd: Disable mtdchar mmap on MMU systems Steven Rostedt
2013-05-07  3:58 ` [089/126] vm: convert mtdchar mmap to vm_iomap_memory() helper Steven Rostedt
2013-05-07  3:58 ` [090/126] Btrfs: make sure nbytes are right after log replay Steven Rostedt
2013-05-07  3:58 ` [091/126] Add file_ns_capable() helper function for open-time capability checking Steven Rostedt
2013-05-07  3:58 ` [092/126] aio: fix possible invalid memory access when DEBUG is enabled Steven Rostedt
2013-05-07  3:58 ` [093/126] TTY: do not update atime/mtime on read/write Steven Rostedt
2013-05-07  3:58 ` [094/126] TTY: fix atime/mtime regression Steven Rostedt
2013-05-07  7:03   ` Jiri Slaby
2013-05-07 12:30     ` Steven Rostedt
2013-05-07  3:58 ` [095/126] atm: update msg_namelen in vcc_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [096/126] ax25: fix info leak via msg_name in ax25_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [097/126] Bluetooth: fix possible info leak in bt_sock_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [098/126] Bluetooth: RFCOMM - Fix missing msg_namelen update in rfcomm_sock_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [099/126] caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [100/126] irda: Fix missing msg_namelen update in irda_recvmsg_dgram() Steven Rostedt
2013-05-07  3:58 ` [101/126] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [102/126] l2tp: fix info leak in l2tp_ip6_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [103/126] llc: Fix missing msg_namelen update in llc_ui_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [104/126] netrom: fix info leak via msg_name in nr_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [105/126] netrom: fix invalid use of sizeof " Steven Rostedt
2013-05-07  3:58 ` [106/126] NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg() Steven Rostedt
2013-05-07  3:58 ` [107/126] rose: fix info leak via msg_name in rose_recvmsg() Steven Rostedt
2013-05-07  3:59 ` [108/126] tipc: fix info leaks via msg_name in recv_msg/recv_stream Steven Rostedt
2013-05-07  3:59 ` [109/126] cbq: incorrect processing of high limits Steven Rostedt
2013-05-07  3:59 ` [110/126] net IPv6 : Fix broken IPv6 routing table after loopback down-up Steven Rostedt
2013-05-07  3:59 ` [111/126] net: count hw_addr syncs so that unsync works properly Steven Rostedt
2013-05-07  3:59 ` [112/126] atl1e: limit gso segment size to prevent generation of wrong ip length fields Steven Rostedt
2013-05-07  3:59 ` [113/126] bonding: fix bonding_masters race condition in bond unloading Steven Rostedt
2013-05-07  3:59 ` [114/126] bonding: IFF_BONDING is not stripped on enslave failure Steven Rostedt
2013-05-07  3:59 ` [115/126] af_unix: If we dont care about credentials coallesce all messages Steven Rostedt
2013-05-07  3:59 ` [116/126] ipv6/tcp: Stop processing ICMPv6 redirect messages Steven Rostedt
2013-05-07  3:59 ` [117/126] rtnetlink: Call nlmsg_parse() with correct header length Steven Rostedt
2013-05-07  3:59 ` [118/126] tcp: incoming connections might use wrong route under synflood Steven Rostedt
2013-05-07  3:59 ` [119/126] tcp: Reallocate headroom if it would overflow csum_start Steven Rostedt
2013-05-07  3:59 ` [120/126] esp4: fix error return code in esp_output() Steven Rostedt
2013-05-07  3:59 ` [121/126] tcp: call tcp_replace_ts_recent() from tcp_ack() Steven Rostedt
2013-05-07  3:59 ` [122/126] net: rate-limit warn-bad-offload splats Steven Rostedt
2013-05-07  3:59 ` [123/126] net: fix incorrect credentials passing Steven Rostedt
2013-05-07  3:59 ` [124/126] net: drop dst before queueing fragments Steven Rostedt
2013-05-07  3:59 ` [125/126] ARM: 7699/1: sched_clock: Add more notrace to prevent recursion Steven Rostedt
2013-05-07  3:59 ` [126/126] ARM: 7692/1: iop3xx: move IOP3XX_PERIPHERAL_VIRT_BASE Steven Rostedt
2013-05-07  4:05 ` [000/126] 3.6.11.3-stable review Steven Rostedt
2013-05-07 20:17 ` Aaro Koskinen
2013-05-07 20:28   ` Steven Rostedt

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=20130507035852.261093152@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=ahonig@google.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