x86/gdbsx: security audit of {,un}pausevcpu and domstatus hypercalls
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 25 Jul 2014 09:55:11 +0000 (11:55 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 25 Jul 2014 09:55:11 +0000 (11:55 +0200)
XEN_DOMCTL_gdbsx_domstatus is already safe.  It loops at most over every vcpu
in a domain and breaks at the first vcpu with an event pending, marking it as
not-pending.

XEN_DOMCTL_gdbsx_pausevcpu had an incorrect bounds check against the vcpu id,
allowing an overflow of d->vcpu[] with an id between d->max_vcpus and
MAX_VIRT_CPUS.  It was also able to overflow a vcpus pause count by many
repeated hypercalls.

The bounds check is fixed, and vcpu_pause() has been replaced with
vcpu_pause_by_systemcontroller() which cuts out at 255 uses.

XEN_DOMCTL_gdbsx_unpausevcpu suffered from the same bounds problems as its
pause counterpart, and is fixed in exactly the same way.  Despite the
atomic_read(&v->pause_count), this code didn't successfully prevent against an
underflow of the vcpu pause count.

The vcpu_unpause() has been replaced with vcpu_pause_by_systemcontroller()
which correctly prevents against underflow.  The printk() is updated to have a
proper guest logging level, and provide more useful information in the XSM
case of one domain having debugger privileges over another.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Tim Deegan <tim@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
docs/misc/xsm-flask.txt
xen/arch/x86/domctl.c

index 31b9d27e4fc1b93fdc8c544038f6c41b25848a82..9559028d9caf39f7f2fcf6a2da42e2656c66f0ed 100644 (file)
@@ -96,9 +96,6 @@ __HYPERVISOR_domctl (xen/include/public/domctl.h)
  * XEN_DOMCTL_set_broken_page_p2m
  * XEN_DOMCTL_setnodeaffinity
  * XEN_DOMCTL_gdbsx_guestmemio
- * XEN_DOMCTL_gdbsx_pausevcpu
- * XEN_DOMCTL_gdbsx_unpausevcpu
- * XEN_DOMCTL_gdbsx_domstatus
 
 __HYPERVISOR_sysctl (xen/include/public/sysctl.h)
 
index 243f42ffa9f38b78954bb730341e1e850b039375..d1517c47be0edc9a5539b0702b364cf2f1f779a9 100644 (file)
@@ -1030,11 +1030,10 @@ long arch_do_domctl(
         if ( !d->controller_pause_count )
             break;
         ret = -EINVAL;
-        if ( domctl->u.gdbsx_pauseunp_vcpu.vcpu >= MAX_VIRT_CPUS ||
+        if ( domctl->u.gdbsx_pauseunp_vcpu.vcpu >= d->max_vcpus ||
              (v = d->vcpu[domctl->u.gdbsx_pauseunp_vcpu.vcpu]) == NULL )
             break;
-        vcpu_pause(v);
-        ret = 0;
+        ret = vcpu_pause_by_systemcontroller(v);
     }
     break;
 
@@ -1046,13 +1045,14 @@ long arch_do_domctl(
         if ( !d->controller_pause_count )
             break;
         ret = -EINVAL;
-        if ( domctl->u.gdbsx_pauseunp_vcpu.vcpu >= MAX_VIRT_CPUS ||
+        if ( domctl->u.gdbsx_pauseunp_vcpu.vcpu >= d->max_vcpus ||
              (v = d->vcpu[domctl->u.gdbsx_pauseunp_vcpu.vcpu]) == NULL )
             break;
-        if ( !atomic_read(&v->pause_count) )
-            printk("WARN: Unpausing vcpu:%d which is not paused\n", v->vcpu_id);
-        vcpu_unpause(v);
-        ret = 0;
+        ret = vcpu_unpause_by_systemcontroller(v);
+        if ( ret == -EINVAL )
+            printk(XENLOG_G_WARNING
+                   "WARN: d%d attempting to unpause %pv which is not paused\n",
+                   current->domain->domain_id, v);
     }
     break;