libxl: Do not trust frontend for disk eject event

Use the /libxl path for interpreting disk eject watch events: do not
read the backend path out of the frontend.  Instead, use the version
in /libxl.  That avoids us relying on the guest-modifiable
$frontend/backend pointer.

To implement this we store the path
  /libxl/$guest/device/vbd/$devid/backend
in the evgen structure.

This is part of XSA-175.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Ian Jackson authored and Ian Jackson committed 2016-06-02 15:53:28 +01:00
1 parent f9a7931b0d
commit e4dccc73a3
2 files changed
+22 -6

No files matched your search

+21 -5
View File
@@ -1312,9 +1312,10 @@ static void disk_eject_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
const char *wpath, const char *epath) {
EGC_GC;
libxl_evgen_disk_eject *evg = (void*)w;
char *backend;
const char *backend;
char *value;
char backend_type[BACKEND_STRING_SIZE+1];
int rc;
value = libxl__xs_read(gc, XBT_NULL, wpath);
@@ -1330,9 +1331,16 @@ static void disk_eject_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
libxl_event *ev = NEW_EVENT(egc, DISK_EJECT, evg->domid, evg->user);
libxl_device_disk *disk = &ev->u.disk_eject.disk;
backend = libxl__xs_read(gc, XBT_NULL,
GCSPRINTF("%.*s/backend", (int)strlen(wpath)-6,
wpath));
rc = libxl__xs_read_checked(gc, XBT_NULL, evg->be_ptr_path, &backend);
if (rc) {
LIBXL__EVENT_DISASTER(egc, "xs_read failed reading be_ptr_path",
errno, LIBXL_EVENT_TYPE_DISK_EJECT);
return;
}
if (!backend) {
/* device has been removed, not simply ejected */
return;
}
sscanf(backend,
"/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE)
@@ -1381,11 +1389,18 @@ int libxl_evenable_disk_eject(libxl_ctx *ctx, uint32_t guest_domid,
if (!domid)
domid = guest_domid;
int devid = libxl__device_disk_dev_number(vdev, NULL, NULL);
path = GCSPRINTF("%s/device/vbd/%d/eject",
libxl__xs_get_dompath(gc, domid),
libxl__device_disk_dev_number(vdev, NULL, NULL));
devid);
if (!path) { rc = ERROR_NOMEM; goto out; }
const char *libxl_path = GCSPRINTF("%s/device/vbd/%d",
libxl__xs_libxl_path(gc, domid),
devid);
evg->be_ptr_path = libxl__sprintf(NOGC, "%s/backend", libxl_path);
rc = libxl__ev_xswatch_register(gc, &evg->watch,
disk_eject_xswatch_callback, path);
if (rc) goto out;
@@ -1412,6 +1427,7 @@ void libxl__evdisable_disk_eject(libxl__gc *gc, libxl_evgen_disk_eject *evg) {
libxl__ev_xswatch_deregister(gc, &evg->watch);
free(evg->vdev);
free(evg->be_ptr_path);
free(evg);
CTX_UNLOCK;
+1 -1
View File
@@ -360,7 +360,7 @@ struct libxl__evgen_disk_eject {
uint32_t domid;
LIBXL_LIST_ENTRY(libxl_evgen_disk_eject) entry;
libxl_ev_user user;
char *vdev;
char *vdev, *be_ptr_path;
};
_hidden void
libxl__evdisable_disk_eject(libxl__gc*, libxl_evgen_disk_eject*);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.