Patchwork [09/12] kvm: validate context for kvm cpu get/put operations

login
register
mail settings
Submitter Marcelo Tosatti
Date May 12, 2010, 9:25 p.m.
Message ID <dbaa07c404d05676df8a081e60b6e66344eafc51.1273699506.git.mtosatti@redhat.com>
Download mbox | patch
Permalink /patch/52434/
State New
Headers show

Comments

Marcelo Tosatti - May 12, 2010, 9:25 p.m.
From: Jan Kiszka <jan.kiszka@siemens.com>

Validate that KVM vcpu state is only read/written from cpu thread itself
or that cpu is stopped.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 target-i386/kvm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f73b47b..c9ec72e 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -949,6 +949,8 @@  int kvm_arch_put_registers(CPUState *env, int level)
 {
     int ret;
 
+    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+
     ret = kvm_getput_regs(env, 1);
     if (ret < 0)
         return ret;
@@ -991,6 +993,8 @@  int kvm_arch_get_registers(CPUState *env)
 {
     int ret;
 
+    assert(cpu_is_stopped(env) || qemu_cpu_self(env));
+
     ret = kvm_getput_regs(env, 0);
     if (ret < 0)
         return ret;