x86: Tighten MSR access checks so only dom0 can access cpufreq MSRs,
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 16 Jan 2009 15:43:59 +0000 (15:43 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 16 Jan 2009 15:43:59 +0000 (15:43 +0000)
and then only when it is the cpufreq controller.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen/arch/x86/traps.c

index 226cc899dad579703c432a03780f9337ba830aac..f6e0eaf59d3d957d9b5d764804c9f17388f53de0 100644 (file)
@@ -1632,6 +1632,12 @@ void (*pv_post_outb_hook)(unsigned int port, u8 value);
 # define read_sreg(regs, sr) read_segment_register(sr)
 #endif
 
+static int is_cpufreq_controller(struct domain *d)
+{
+    return ((cpufreq_controller == FREQCTL_dom0_kernel) &&
+            (d->domain_id == 0));
+}
+
 static int emulate_privileged_op(struct cpu_user_regs *regs)
 {
     struct vcpu *v = current;
@@ -2143,7 +2149,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
         case MSR_K8_PSTATE7:
             if ( boot_cpu_data.x86_vendor != X86_VENDOR_AMD )
                 goto fail;
-            if ( cpufreq_controller != FREQCTL_dom0_kernel )
+            if ( !is_cpufreq_controller(v->domain) )
                 break;
             if ( wrmsr_safe(regs->ecx, eax, edx) != 0 )
                 goto fail;
@@ -2181,16 +2187,11 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
         case MSR_IA32_MPERF:
         case MSR_IA32_APERF:
         case MSR_IA32_PERF_CTL:
-            if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL )
-                goto fail;
-            if ( cpufreq_controller != FREQCTL_dom0_kernel )
-                break;
-            if ( wrmsr_safe(regs->ecx, eax, edx) != 0 )
-                goto fail;
-            break;
         case MSR_IA32_THERM_CONTROL:
             if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL )
                 goto fail;
+            if ( !is_cpufreq_controller(v->domain) )
+                break;
             if ( wrmsr_safe(regs->ecx, eax, edx) != 0 )
                 goto fail;
             break;
@@ -2249,7 +2250,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
         case MSR_K8_PSTATE7:
             if ( boot_cpu_data.x86_vendor != X86_VENDOR_AMD )
                 goto fail;
-            if ( cpufreq_controller != FREQCTL_dom0_kernel )
+            if ( !is_cpufreq_controller(v->domain) )
             {
                 regs->eax = regs->edx = 0;
                 break;
@@ -2267,7 +2268,6 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
                          MSR_IA32_MISC_ENABLE_XTPR_DISABLE;
             break;
         case MSR_EFER:
-        case MSR_IA32_THERM_CONTROL:
         case MSR_AMD_PATCHLEVEL:
         default:
             if ( rdmsr_hypervisor_regs(regs->ecx, &l, &h) )