Skip to contentSkip to conversation

libxl: don't segfault when creating domain with invalid pvusb device

PATCH Superseded Juergen Gross 2 participants 3 messages Feb 7, 2017 – Feb 8, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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

---
 tools/libxl/libxl_usb.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
tools/libxl/libxl_usb.c +7 -6
index ea7a2ab..b235507 100644
@@ -651,12 +651,13 @@ 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);                              \
-        if (rc) goto out;                                               \
-        (char *)tmp;                                                    \
+#define READ_SUBPATH(path, subpath) ({                                      \
+        tmp = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/" subpath, path)); \
+        if (!tmp) {                                                         \
+            rc = ERROR_FAIL;                                                \
+            goto out;                                                       \
+        }                                                                   \
+        (char *)tmp;                                                        \
     })
 
 #define READ_SUBPATH_INT(path, subpath) ({                              \
Signature · 7 lines
2.10.2


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

Juergen Gross writes ("[PATCH] libxl: don't segfault when creating domain with invalid pvusb device"):

Quoted 5 lines

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 should be done by adding a test of tmp for NULL. libxl__xs_read does no logging so is not really an improvement.

If you felt like inventing libxl__xs_read_must or something (maybe Wei has a suggestion for a better name) that calls ENOENT a failure instead, I'd be happy with that.

Thanks,
Ian.

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

#2 lore raw
Quoted 7 lines · Ian Jackson

Juergen Gross writes ("[PATCH] libxl: don't segfault when creating domain with invalid pvusb device"):

Quoted 5 lines

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.

Quoted 6 lines

This should be done by adding a test of tmp for NULL. libxl__xs_read does no logging so is not really an improvement.

If you felt like inventing libxl__xs_read_must or something (maybe Wei has a suggestion for a better name) that calls ENOENT a failure instead, I'd be happy with that.

Okay. I think I'll name it libxl__xs_read_mandatory().

Juergen

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