libxl: don't segfault when creating domain with invalid pvusb device
PATCH v3 1/1 libxl: don't segfault when creating domain with invalid pvusb device
Creating a domain with an invalid controller specification for a pvusb device will currently segfault.
Avoid this by bailing out early in case of a mandatory xenstore path not existing.
---
This patch is a backport candidate for 4.8
V2: introduce libxl__xs_read_mandatory() as suggested by Ian Jackson
V3: adjust comment as requested by Wei Liu
--- tools/libxl/libxl_internal.h | 7 +++++++ tools/libxl/libxl_usb.c | 6 +++--- tools/libxl/libxl_xshelp.c | 12 ++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-)
tools/libxl/libxl_internal.h +7 -0
@@ -738,6 +738,13 @@ int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,/* On success, *result_out came from the gc. * On error, *result_out is undefined. +* ENOENT is regarded as error. +*/ +int libxl__xs_read_mandatory (libxl__gc *gc,xs_transaction_t t, +const char *path,const char **result_out); + +/* On success, *result_out came from the gc. +* On error, *result_out is undefined. * ENOENT counts as success but sets *result_out=0 */ int libxl__xs_read_checked(libxl__gc *gc, xs_transaction_t t,
tools/libxl/libxl_usb.c +3 -3
@@ -652,9 +652,9 @@ int libxl_device_usbctrl_getinfo(libxl_ctx *ctx, uint32_t domid, usbctrlinfo->devid = usbctrl->devid;#define READ_SUBPATH (path, subpath) ({ \ - rc = libxl__xs_read_checked(gc, XBT_NULL, \ - GCSPRINTF("%s/" subpath, path), \ - &tmp); \ + rc = libxl__xs_read_mandatory(gc, XBT_NULL, \ + GCSPRINTF("%s/" subpath, path), \ + &tmp); \ if (rc) goto out; \ (char *)tmp; \ })
tools/libxl/libxl_xshelp.c +12 -0
@@ -193,6 +193,18 @@ char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)return s; } +int libxl__xs_read_mandatory (libxl__gc *gc,xs_transaction_t t, +const char *path,const char **result_out) +{ +char *result =libxl__xs_read (gc, t, path); +if (!result) { +LOGE (ERROR ,"xenstore read failed: `%s'" , path); +return ERROR_FAIL ; + } + *result_out = result; +return 0 ; +} +int libxl__xs_read_checked (libxl__gc *gc,xs_transaction_t t,const char *path,const char **result_out) {
Signature · 7 lines
2.10.2 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Juergen Gross writes ("[PATCH v3] libxl: don't segfault when creating domain with invalid pvusb device"):
Quoted 2 lines
Creating a domain with an invalid controller specification for a pvusb device will currently segfault.
Good choice of function name, thanks.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu
AppliedQuoted 5 lines · Ian Jackson
Juergen Gross writes ("[PATCH v3] libxl: don't segfault when creating domain with invalid pvusb device"):
Quoted 2 lines
Creating a domain with an invalid controller specification for a pvusb device will currently segfault.
Acked-by Ian Jackson <[email protected]>
Applied.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel