Allow VMs to query their own grant table version.
authorPaul Durrant <paul.durrant@citrix.com>
Sun, 18 Dec 2011 14:38:32 +0000 (14:38 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Sun, 18 Dec 2011 14:38:32 +0000 (14:38 +0000)
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Committed-by: Keir Fraser <keir@xen.org>
xen/arch/x86/hvm/hvm.c
xen/common/grant_table.c

index bae369680facdcbc4e0443f2f37476e1a3a9e7b2..160a47f4b684942cb30e4ff79d7a49a43a9dd44a 100644 (file)
@@ -2857,6 +2857,7 @@ static int grant_table_op_is_allowed(unsigned int cmd)
     case GNTTABOP_query_size:
     case GNTTABOP_setup_table:
     case GNTTABOP_set_version:
+    case GNTTABOP_get_version:
     case GNTTABOP_copy:
     case GNTTABOP_map_grant_ref:
     case GNTTABOP_unmap_grant_ref:
index fefa8383b2f01936f8d01542e6d0241dac8bb2d8..014734d24050ea5ab1e00472c5e9113fadc3c8d9 100644 (file)
@@ -2253,30 +2253,29 @@ gnttab_get_version(XEN_GUEST_HANDLE(gnttab_get_version_t uop))
 {
     gnttab_get_version_t op;
     struct domain *d;
+    int rc;
 
     if ( copy_from_guest(&op, uop, 1) )
         return -EFAULT;
-    d = rcu_lock_domain_by_id(op.dom);
-    if ( d == NULL )
-        return -ESRCH;
-    if ( !IS_PRIV_FOR(current->domain, d) )
-    {
-        rcu_unlock_domain(d);
-        return -EPERM;
-    }
+
+    rc = rcu_lock_target_domain_by_id(op.dom, &d);
+    if ( rc < 0 )
+        return rc;
+
     if ( xsm_grant_query_size(current->domain, d) )
     {
         rcu_unlock_domain(d);
         return -EPERM;
     }
+
     spin_lock(&d->grant_table->lock);
     op.version = d->grant_table->gt_version;
     spin_unlock(&d->grant_table->lock);
 
     if ( copy_to_guest(uop, &op, 1) )
         return -EFAULT;
-    else
-        return 0;
+
+    return 0;
 }
 
 long