libxc: Protect xc_domain_resume from clobbering domain registers
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.
---
Changes since RFC:
- Return -1 from modify_returncode
- Set errno to EINVAL
--- tools/libxc/xc_resume.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/libxc/xc_resume.c +7 -0
@@ -39,6 +39,13 @@ 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" ); + 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
Quoted 21 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]>---
Changes since RFC:
- Return -1 frommodify_returncode
- Set errno to EINVAL--- tools/libxc/xc_resume.c | 7 +++++++ 1 file changed, 7 insertions(+)tools/libxc/xc_resume.c +0
-0
tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 40
Quoted 2 lines
tools/libxc/xc_resume.c +0
-0@@ -39,6 +39,13 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; }
Having looked at this more closely, there is also a bug in the hunk above.
xc_domain_getinfo() being the 'special' function that it is doesn't always return the domain specified. If the given domid doesn't exist in the system, you will get back the first domain with a higher domid.
The only safe way to use it is
if ( xc_domain_getinfo(xch, domid, 1, &info) != 1 ||
info.domid != domid )
{
error...
}tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 44
Quoted 4 lines
tools/libxc/xc_resume.c +3
-0+if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" );
ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid, info.shutdown, info.shutdown_reason));
This way, someone unexpectedly finding this error message gets slightly more information than "something wasn't how I expected it to be".
~Andrew
Quoted 7 lines
tools/libxc/xc_resume.c +4
-0+ errno =EINVAL ; +return -1 ; + } +if ( info.hvm ) {/* HVM guests without PV drivers have no return code to modify. */
Quoted 31 lines · Andrew Cooper
Quoted 21 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]>---
Changes since RFC:
- Return -1 frommodify_returncode
- Set errno to EINVAL--- tools/libxc/xc_resume.c | 7 +++++++ 1 file changed, 7 insertions(+)tools/libxc/xc_resume.c +0
-0tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 40
Quoted 2 lines
tools/libxc/xc_resume.c +0
-0@@ -39,6 +39,13 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; }Having looked at this more closely, there is also a bug in the hunk above.
xc_domain_getinfo()being the 'special' function that it is doesn't always return the domain specified. If the given domid doesn't exist in the system, you will get back the first domain with a higher domid.
Quoted 7 lines
The only safe way to use it is
if (
xc_domain_getinfo(xch, domid, 1, &info)!= 1 ||info.domid != domid ) { error... }
I am ok making this change; I wasn't aware of the quirks of the function.
This patch copy & pasted the check from xc_domain_save.c:suspend_and_state(). That and other locations throughout libxc fail to compare info.domid to the requested domid, so there are lots of places that should be fixed up. Maybe a wrapper xc_domain_getinfo_one(xch, domid, &info) that checks the domid would be useful?
Quoted 10 lines
tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 44
Quoted 4 lines
tools/libxc/xc_resume.c +3
-0+if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" );
ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid, info.shutdown, info.shutdown_reason));This way, someone unexpectedly finding this error message gets slightly more information than "something wasn't how I expected it to be".
Yes, this is more informative. suspend_and_state could also be updated to the same message.
-Jason
Quoted 33 lines · Jason Andryuk
Quoted 32 lines · Andrew Cooper
Quoted 21 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]>---
Changes since RFC:
- Return -1 frommodify_returncode
- Set errno to EINVAL--- tools/libxc/xc_resume.c | 7 +++++++ 1 file changed, 7 insertions(+)tools/libxc/xc_resume.c +0
-0tools/libxc/xc_resume.c static int modify_returncode(xc_interface *xch, uint32_t domid) · line 40
Quoted 2 lines
tools/libxc/xc_resume.c +0
-0@@ -39,6 +39,13 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return -1 ; }Having looked at this more closely, there is also a bug in the hunk above.
xc_domain_getinfo()being the 'special' function that it is doesn't always return the domain specified. If the given domid doesn't exist in the system, you will get back the first domain with a higher domid.The only safe way to use it is
Quoted 8 lines
Quoted 5 lines
if (
xc_domain_getinfo(xch, domid, 1, &info)!= 1 ||info.domid != domid ) { error... }I am ok making this change; I wasn't aware of the quirks of the function.
This patch copy & pasted the check from xc_domain_save.c:suspend_and_state(). That and other locations throughout libxc fail to compare info.domid to the requested domid, so there are lots of places that should be fixed up. Maybe a wrapper
xc_domain_getinfo_one(xch, domid, &info)that checks the domid would be useful?
It certainly would be useful, although probably as a separate patch.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
tools/libxc/xc_resume.c +3
-0+if ( !info.shutdown || (info.shutdown_reason != SHUTDOWN_suspend) ) + { +ERROR ("Domain not in suspended state" );
Quoted 8 lines
Quoted 5 lines
ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid, info.shutdown, info.shutdown_reason));This way, someone unexpectedly finding this error message gets slightly more information than "something wasn't how I expected it to be".
Yes, this is more informative.
suspend_and_statecould also be updated to the same message.-Jason
Probably no need to worry about suspend_and_state(). It is about to disappear with the new migration protocol work.
~Andrew