xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl: don't segfault when creating domain with invalid pvusb device
@ 2017-02-07 11:51 Juergen Gross
  2017-02-07 18:36 ` Ian Jackson
  0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2017-02-07 11:51 UTC (permalink / raw)
  To: xen-devel; +Cc: Juergen Gross, wei.liu2, ian.jackson

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.

Signed-of-by: Juergen Gross <jgross@suse.com>
---
This patch is a backport candidate for 4.8
---
 tools/libxl/libxl_usb.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl_usb.c b/tools/libxl/libxl_usb.c
index ea7a2ab..b235507 100644
--- a/tools/libxl/libxl_usb.c
+++ b/tools/libxl/libxl_usb.c
@@ -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) ({                              \
-- 
2.10.2


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] libxl: don't segfault when creating domain with invalid pvusb device
  2017-02-07 11:51 [PATCH] libxl: don't segfault when creating domain with invalid pvusb device Juergen Gross
@ 2017-02-07 18:36 ` Ian Jackson
  2017-02-08  6:41   ` Juergen Gross
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Jackson @ 2017-02-07 18:36 UTC (permalink / raw)
  To: Juergen Gross; +Cc: xen-devel, wei.liu2

Juergen Gross writes ("[PATCH] 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 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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libxl: don't segfault when creating domain with invalid pvusb device
  2017-02-07 18:36 ` Ian Jackson
@ 2017-02-08  6:41   ` Juergen Gross
  0 siblings, 0 replies; 3+ messages in thread
From: Juergen Gross @ 2017-02-08  6:41 UTC (permalink / raw)
  To: Ian Jackson; +Cc: xen-devel, wei.liu2

On 07/02/17 19:36, Ian Jackson wrote:
> Juergen Gross writes ("[PATCH] 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 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
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-08  6:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-07 11:51 [PATCH] libxl: don't segfault when creating domain with invalid pvusb device Juergen Gross
2017-02-07 18:36 ` Ian Jackson
2017-02-08  6:41   ` Juergen Gross

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).