Skip to contentSkip to conversation

libxc: check in xc_get_tot_pages() that the proper domain is reported

PATCH Applied Vitaly Kuznetsov 6 participants 6 messages Dec 2, 2014 – Dec 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: check in xc_get_tot_pages() that the proper domain is reported

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

---
 tools/libxc/xc_private.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_private.c +4 -2
index 1c214dd..e2441ad 100644
@@ -613,8 +613,10 @@ int xc_get_pfn_list(xc_interface *xch,
 long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
 {
     xc_dominfo_t info;
-    return (xc_domain_getinfo(xch, domid, 1, &info) != 1) ?
-        -1 : info.nr_pages;
+    if ( (xc_domain_getinfo(xch, domid, 1, &info) != 1) ||
+         (info.domid != domid) )
+        return -1;
+    return info.nr_pages;
 }
 
 int xc_copy_to_domain_page(xc_interface *xch,
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Vitaly Kuznetsov

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

---
  tools/libxc/xc_private.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_private.c +0 -0
index 1c214dd..e2441ad 100644
@@ -613,8 +613,10 @@ int xc_get_pfn_list(xc_interface *xch,
  long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
  {

tools/libxc/xc_private.c int xc_get_pfn_list(xc_interface *xch, · line 622

Quoted 10 lines
tools/libxc/xc_private.c +4 -2
      xc_dominfo_t info;
-    return (xc_domain_getinfo(xch, domid, 1, &info) != 1) ?
-        -1 : info.nr_pages;
+    if ( (xc_domain_getinfo(xch, domid, 1, &info) != 1) ||
+         (info.domid != domid) )
+        return -1;
+    return info.nr_pages;
  }
 
  int xc_copy_to_domain_page(xc_interface *xch,

Looks good to me.

-Don Slutz

Reviewed-by on v1 1/1
#2 lore raw
In reply to Vitaly Kuznetsov
Quoted 9 lines · Vitaly Kuznetsov

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

CCing Konrad as this really should get a 4.5 release ack. It is a straight bugfix.

Quoted 21 lines
---
 tools/libxc/xc_private.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_private.c +4 -2
index 1c214dd..e2441ad 100644
@@ -613,8 +613,10 @@ int xc_get_pfn_list(xc_interface *xch,
 long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
 {
     xc_dominfo_t info;
-    return (xc_domain_getinfo(xch, domid, 1, &info) != 1) ?
-        -1 : info.nr_pages;
+    if ( (xc_domain_getinfo(xch, domid, 1, &info) != 1) ||
+         (info.domid != domid) )
+        return -1;
+    return info.nr_pages;
 }
 
 int xc_copy_to_domain_page(xc_interface *xch,
Acked-by on v1 1/1
#3 lore raw
In reply to Vitaly Kuznetsov
Quoted 9 lines · Vitaly Kuznetsov

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

Quoted 23 lines
---
 tools/libxc/xc_private.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_private.c +4 -2
index 1c214dd..e2441ad 100644
@@ -613,8 +613,10 @@ int xc_get_pfn_list(xc_interface *xch,
 long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
 {
     xc_dominfo_t info;
-    return (xc_domain_getinfo(xch, domid, 1, &info) != 1) ?
-        -1 : info.nr_pages;
+    if ( (xc_domain_getinfo(xch, domid, 1, &info) != 1) ||
+         (info.domid != domid) )
+        return -1;
+    return info.nr_pages;
 }
 
 int xc_copy_to_domain_page(xc_interface *xch,
Signature · 1 line
1.9.3
#4 lore raw
Quoted 9 lines · Wei Liu
Quoted 8 lines · Vitaly Kuznetsov

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

Quoted 3 lines
Quoted 1 line

Lets add another Ack to this party..

Quoted 29 lines
Quoted 24 lines
---
 tools/libxc/xc_private.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/libxc/xc_private.c +4 -2
index 1c214dd..e2441ad 100644
@@ -613,8 +613,10 @@ int xc_get_pfn_list(xc_interface *xch,
 long xc_get_tot_pages(xc_interface *xch, uint32_t domid)
 {
     xc_dominfo_t info;
-    return (xc_domain_getinfo(xch, domid, 1, &info) != 1) ?
-        -1 : info.nr_pages;
+    if ( (xc_domain_getinfo(xch, domid, 1, &info) != 1) ||
+         (info.domid != domid) )
+        return -1;
+    return info.nr_pages;
 }
 
 int xc_copy_to_domain_page(xc_interface *xch,
Signature · 1 line
1.9.3

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Applied
#5 lore raw
Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 9 lines · Wei Liu
Quoted 8 lines · Vitaly Kuznetsov

XEN_DOMCTL_getdomaininfo, which is being used by xc_domain_getinfo(), has strange interface: it reports first domain which has domid >= requested domid so all callers are supposed to check that the proper domain(s) was queried by checking domid. xc_get_tot_pages() doesn't do that. In case the requested domain was destroyed it will report first domain with domid > requested domid which is apparently misleading as there is no way xc_get_tot_pages() callers can figure out that they got tot_pages for some other domain.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Lets add another Ack to this party..

Applied, thanks.