Skip to contentSkip to conversation

libxc: Protect xc_domain_resume from clobbering domain registers

PATCH In review Jason Andryuk 3 participants 3 messages May 20, 2014 – May 21, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libxc: Protect xc_domain_resume from clobbering domain registers

xc_domain_resume() expects the guest to be in state SHUTDOWN_suspend. However, nothing verifies the state before modify_returncode() modifies the domain's registers. This will crash guest processes or the kernel itself.

This can be demonstrated with LIBXL_SAVE_HELPER=/bin/false xl migrate.

---
v2:
- Verify domid
- Improve error message

---
 tools/libxc/xc_resume.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/libxc/xc_resume.c +10 -1
index 18b4818..e423814 100644
@@ -33,12 +33,21 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
     struct domain_info_context *dinfo = &_dinfo;
     int rc;
 
-    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
+         info.domid != domid )
     {
         PERROR("Could not get domain info");
         return -1;
     }
 
+    if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) )
+    {
+        ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid,
+              info.shutdown, info.shutdown_reason);
+        errno = EINVAL;
+        return -1;
+    }
+
     if ( info.hvm )
     {
         /* HVM guests without PV drivers have no return code to modify. */
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Jason Andryuk

xc_domain_resume() expects the guest to be in state SHUTDOWN_suspend. However, nothing verifies the state before modify_returncode() modifies the domain's registers. This will crash guest processes or the kernel itself.

This can be demonstrated with LIBXL_SAVE_HELPER=/bin/false xl migrate.

Quoted 35 lines

---
v2:
- Verify domid
- Improve error message

---
 tools/libxc/xc_resume.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/libxc/xc_resume.c +10 -1
index 18b4818..e423814 100644
@@ -33,12 +33,21 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
     struct domain_info_context *dinfo = &_dinfo;
     int rc;
 
-    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 )
+    if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
+         info.domid != domid )
     {
         PERROR("Could not get domain info");
         return -1;
     }
 
+    if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) )
+    {
+        ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid,
+              info.shutdown, info.shutdown_reason);
+        errno = EINVAL;
+        return -1;
+    }
+
     if ( info.hvm )
     {
         /* HVM guests without PV drivers have no return code to modify. */
#2 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 8 lines · Jason Andryuk

xc_domain_resume() expects the guest to be in state SHUTDOWN_suspend. However, nothing verifies the state before modify_returncode() modifies the domain's registers. This will crash guest processes or the kernel itself.

This can be demonstrated with LIBXL_SAVE_HELPER=/bin/false xl migrate.

Acked + applied.