libxc: Protect xc_domain_resume from clobbering domain registers
RFC PATCH 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.
---
This change stops xc_domain_resume from killing my domUs on a failed migration. I'm using a wrapper around libxl-save-helper which may fail before libxl-save-helper is invoked, so xc_domain_save has not been called. The idle Linux domU kernels would BUG coming out of SCHEDOP_block in xen_safe_halt() since modify_returncode set EAX to 1. journald was also observed to segfault.
As written, this code treats calling xc_domain_resume on a running domain as an error. Do we want it silently ignored? Output with this patch looks like:
"""
Migration failed, resuming at sender.
xc: error: Domain not in suspended state: Internal error
libxl: error: libxl.c:402:libxl__domain_resume: xc_domain_resume failed for domain 92: Interrupted system call """
libxl__domain_resume prints errno, but it is stale for this case. xc_domain_resume_cooperative could swallow modify_returncode's error, bypass issuing XEN_DOMCTL_resumedomain, and return success to avoid the libxl error message.
--- tools/libxc/xc_resume.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/libxc/xc_resume.c +6 -0
@@ -39,6 +39,12 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; } +if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" ); +return 1 ; + } +if ( info.hvm ) {/* HVM guests without PV drivers have no return code to modify. */
Signature · 1 line
1.8.3.1
Quoted 8 lines · Jason Andryuk
xc_domain_resume()expects the guest to be in stateSHUTDOWN_suspend. However, nothing verifies the state beforemodify_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.Signed-off-by Jason Andryuk <[email protected]>
Hmm.
There is no possible way whatsoever that migration can work if a PV guest is not in SHUTDOWN_suspend. PV guests have to leave an MFN in edx which the toolstack rewrites with a new MFN on resume.
By default, there is no need for knowledge from the HVM guest for migrate. XenServer is perfectly capable of migrating HVM VMs without PV drivers. I suspect therefore that we never use cooperative resume.
This cooperative resume which modifies guest register state therefore imposes the same SHUTDOWN_suspend restriction on HVM guests as it does for PV guests. As a result, your patch below is correct as a fallback safety measure, and should be taken.
However the caller of modify_returncode is also at fault for attempting to resume an already-running domain. I think there needs to be a bugfix there as well. I presume that some piece of code is assuming that despite libxl-save-helper failing, xc_domain_safe() paused the guest, which is clearly not true in this case.
~Andrew
Quoted 45 lines
---
This change stops
xc_domain_resumefrom killing my domUs on a failed migration. I'm using a wrapper around libxl-save-helper which may fail before libxl-save-helper is invoked, soxc_domain_savehas not been called. The idle Linux domU kernels would BUG coming out ofSCHEDOP_blockinxen_safe_halt()sincemodify_returncodeset EAX to 1. journald was also observed to segfault.As written, this code treats calling
xc_domain_resumeon a running domain as an error. Do we want it silently ignored? Output with this patch looks like:"""
Migration failed, resuming at sender.
xc: error: Domain not in suspended state: Internal error
libxl: error: libxl.c:402:libxl__domain_resume:xc_domain_resumefailed for domain 92: Interrupted system call """
libxl__domain_resumeprints errno, but it is stale for this case.xc_domain_resume_cooperativecould swallow modify_returncode's error, bypass issuingXEN_DOMCTL_resumedomain, and return success to avoid the libxl error message.--- tools/libxc/xc_resume.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/libxc/xc_resume.c +6
-0@@ -39,6 +39,12 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; } +if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" ); +return 1 ; + } +if ( info.hvm ) {/* HVM guests without PV drivers have no return code to modify. */
Quoted 24 lines · Andrew Cooper
Quoted 8 lines · Jason Andryuk
xc_domain_resume()expects the guest to be in stateSHUTDOWN_suspend. However, nothing verifies the state beforemodify_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.Signed-off-by Jason Andryuk <[email protected]>Hmm.
There is no possible way whatsoever that migration can work if a PV guest is not in
SHUTDOWN_suspend. PV guests have to leave an MFN in edx which the toolstack rewrites with a new MFN on resume.By default, there is no need for knowledge from the HVM guest for migrate. XenServer is perfectly capable of migrating HVM VMs without PV drivers. I suspect therefore that we never use cooperative resume.
This cooperative resume which modifies guest register state therefore imposes the same
SHUTDOWN_suspendrestriction on HVM guests as it does for PV guests. As a result, your patch below is correct as a fallback safety measure, and should be taken.
Quoted 7 lines
However the caller of
modify_returncodeis also at fault for attempting to resume an already-running domain. I think there needs to be a bugfix there as well. I presume that some piece of code is assuming that despite libxl-save-helper failing,xc_domain_safe()paused the guest, which is clearly not true in this case.~Andrew
And here, I actually mean xc_domain_save()
~Andrew
Quoted 51 lines
Quoted 36 lines
---
This change stops
xc_domain_resumefrom killing my domUs on a failed migration. I'm using a wrapper around libxl-save-helper which may fail before libxl-save-helper is invoked, soxc_domain_savehas not been called. The idle Linux domU kernels would BUG coming out ofSCHEDOP_blockinxen_safe_halt()sincemodify_returncodeset EAX to 1. journald was also observed to segfault.As written, this code treats calling
xc_domain_resumeon a running domain as an error. Do we want it silently ignored? Output with this patch looks like:"""
Migration failed, resuming at sender.
xc: error: Domain not in suspended state: Internal error
libxl: error: libxl.c:402:libxl__domain_resume:xc_domain_resumefailed for domain 92: Interrupted system call """
libxl__domain_resumeprints errno, but it is stale for this case.xc_domain_resume_cooperativecould swallow modify_returncode's error, bypass issuingXEN_DOMCTL_resumedomain, and return success to avoid the libxl error message.--- tools/libxc/xc_resume.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/libxc/xc_resume.c +0
-0@@ -39,6 +39,12 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; }tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 50
Quoted 10 lines
tools/libxc/xc_resume.c +6
-0+if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" ); +return 1 ; + } +if ( info.hvm ) {/* HVM guests without PV drivers have no return code to modify. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 12 lines · Andrew Cooper
Quoted 8 lines · Jason Andryuk
xc_domain_resume()expects the guest to be in stateSHUTDOWN_suspend. However, nothing verifies the state beforemodify_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.Signed-off-by Jason Andryuk <[email protected]>Hmm.
Quoted 7 lines
There is no possible way whatsoever that migration can work if a PV guest is not in
SHUTDOWN_suspend. PV guests have to leave an MFN in edx which the toolstack rewrites with a new MFN on resume.By default, there is no need for knowledge from the HVM guest for migrate. XenServer is perfectly capable of migrating HVM VMs without PV drivers. I suspect therefore that we never use cooperative resume.
I've only used 64-bit PV domUs, so I haven't really thought about HVM. If info.shutdown_reason == SHUTDOWN_suspend is expected for all HVM cases, then the hunk can stand. Otherwise it should be moved later after HVM without PV drivers has exited.
Quoted 10 lines
This cooperative resume which modifies guest register state therefore imposes the same
SHUTDOWN_suspendrestriction on HVM guests as it does for PV guests. As a result, your patch below is correct as a fallback safety measure, and should be taken.However the caller of
modify_returncodeis also at fault for attempting to resume an already-running domain. I think there needs to be a bugfix there as well. I presume that some piece of code is assuming that despite libxl-save-helper failing,xc_domain_safe()paused the guest, which is clearly not true in this case.
Agreed. modify_returncode was already making the call to xc_domain_info (and doing the damage), so adding a check there was easy.
The patch was posted RFC since I was looking for guidance on whether xc_domain_resume on a running domain is an error or should it be treated as success? The original modify_returncode returns 0 on success or -1 on error. This patch returns 1 for the already running case. This could be handled differently by the caller to bypass XEN_DOMCTL_resumedomain without returning an error.
-Jason
Quoted 54 lines
~Andrew
Quoted 35 lines
---
This change stops
xc_domain_resumefrom killing my domUs on a failed migration. I'm using a wrapper around libxl-save-helper which may fail before libxl-save-helper is invoked, soxc_domain_savehas not been called. The idle Linux domU kernels would BUG coming out ofSCHEDOP_blockinxen_safe_halt()sincemodify_returncodeset EAX to 1. journald was also observed to segfault.As written, this code treats calling
xc_domain_resumeon a running domain as an error. Do we want it silently ignored? Output with this patch looks like:"""
Migration failed, resuming at sender.
xc: error: Domain not in suspended state: Internal error
libxl: error: libxl.c:402:libxl__domain_resume:xc_domain_resumefailed for domain 92: Interrupted system call """
libxl__domain_resumeprints errno, but it is stale for this case.xc_domain_resume_cooperativecould swallow modify_returncode's error, bypass issuingXEN_DOMCTL_resumedomain, and return success to avoid the libxl error message.--- tools/libxc/xc_resume.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/libxc/xc_resume.c +0
-0@@ -39,6 +39,12 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; }tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 50
Quoted 10 lines
tools/libxc/xc_resume.c +6
-0+if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" ); +return 1 ; + } +if ( info.hvm ) {/* HVM guests without PV drivers have no return code to modify. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 12 lines · Jason Andryuk
Quoted 11 lines · Andrew Cooper
Quoted 8 lines · Jason Andryuk
xc_domain_resume()expects the guest to be in stateSHUTDOWN_suspend. However, nothing verifies the state beforemodify_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.Signed-off-by Jason Andryuk <[email protected]>Hmm.
Quoted 8 lines
Quoted 7 lines
There is no possible way whatsoever that migration can work if a PV guest is not in
SHUTDOWN_suspend. PV guests have to leave an MFN in edx which the toolstack rewrites with a new MFN on resume.By default, there is no need for knowledge from the HVM guest for migrate. XenServer is perfectly capable of migrating HVM VMs without PV drivers. I suspect therefore that we never use cooperative resume.
I've only used 64-bit PV domUs, so I haven't really thought about HVM. If info.shutdown_reason ==
SHUTDOWN_suspendis expected for all HVM cases, then the hunk can stand. Otherwise it should be moved later after HVM without PV drivers has exited.
I disagree. It is unconditionally an error to be in this function with a guest which is not in SHUTDOWN_suspend, even if there is a codepath through the function which would not corrupt state. I would leave the hunk as it stands, although you might consider setting errno so EINVAL (or something more appropriate).
Quoted 11 lines
Quoted 11 lines
This cooperative resume which modifies guest register state therefore imposes the same
SHUTDOWN_suspendrestriction on HVM guests as it does for PV guests. As a result, your patch below is correct as a fallback safety measure, and should be taken.However the caller of
modify_returncodeis also at fault for attempting to resume an already-running domain. I think there needs to be a bugfix there as well. I presume that some piece of code is assuming that despite libxl-save-helper failing,xc_domain_safe()paused the guest, which is clearly not true in this case.
Quoted 5 lines
Agreed.
modify_returncodewas already making the call toxc_domain_info(and doing the damage), so adding a check there was easy.The patch was posted RFC since I was looking for guidance on whether
xc_domain_resumeon a running domain is an error or should it be treated as success? The originalmodify_returncodereturns 0 on success or -1 on error. This patch returns 1 for the already running case. This could be handled differently by the caller to bypassXEN_DOMCTL_resumedomainwithout returning an error.-Jason
I still think the real problem is higher up. The toolstack absolutely shouldn't running xc_domain_resume() on a running domain.
~Andrew
Jason Andryuk writes ("[PATCH RFC] libxc: Protect xc_domain_resume from clobbering domain registers"):
Quoted 4 lines
xc_domain_resume()expects the guest to be in stateSHUTDOWN_suspend. However, nothing verifies the state beforemodify_returncode()modifies the domain's registers. This will crash guest processes or the kernel itself.
I think this patch is a step in the right direction and would have applied it if you hadn't tagged it "RFC".
Thanks,
Ian.