[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/13] usb/dev-storage: Fix QMP device_add missing en
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 08/13] usb/dev-storage: Fix QMP device_add missing encryption key failure |
Date: |
Wed, 18 Mar 2015 14:07:50 +0100 |
From: Markus Armbruster <address@hidden>
When the image is encrypted, QMP device_add creates the device, defers
actually attaching it to when the key becomes available, then returns
an error. This is wrong. device_add must either create the device
and succeed, or do nothing and fail.
The bug is in usb_msd_realize_storage(). It posts an error with
qerror_report_err(), and returns success. Device realization relies
on the return value, and completes. The QMP monitor, however, relies
on the posted error, and sends it in an error reply.
Reproducer:
$ qemu-system-x86_64 -nodefaults -display none -usb -qmp stdio -drive
if=none,id=foo,file=geheim.qcow2
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 2, "major": 2},
"package": ""}, "capabilities": []}}
{ "execute": "qmp_capabilities" }
{"return": {}}
{ "execute": "device_add", "arguments": { "driver": "usb-storage", "id":
"bar", "drive": "foo" } }
{"error": {"class": "DeviceEncrypted", "desc": "'foo' (geheim.qcow2) is
encrypted"}}
Even though we got an error back, the device got created just fine.
To demonstrate, let's unplug it again:
{"execute":"device_del","arguments": { "id": "bar" } }
{"timestamp": {"seconds": 1426003440, "microseconds": 237181}, "event":
"DEVICE_DELETED", "data": {"path": "/machine/peripheral/bar/bar.0/legacy[0]"}}
{"timestamp": {"seconds": 1426003440, "microseconds": 238231}, "event":
"DEVICE_DELETED", "data": {"device": "bar", "path": "/machine/peripheral/bar"}}
{"return": {}}
Fix by making usb_msd_realize_storage() fail properly.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/usb/dev-storage.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index f47c856..f50bcb8 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -610,6 +610,23 @@ static void usb_msd_realize_storage(USBDevice *dev, Error
**errp)
return;
}
+ bdrv_add_key(blk_bs(blk), NULL, &err);
+ if (err) {
+ if (monitor_cur_is_qmp()) {
+ error_propagate(errp, err);
+ return;
+ }
+ error_free(err);
+ err = NULL;
+ if (cur_mon) {
+ monitor_read_bdrv_key_start(cur_mon, blk_bs(blk),
+ usb_msd_password_cb, s);
+ s->dev.auto_attach = 0;
+ } else {
+ autostart = 0;
+ }
+ }
+
blkconf_serial(&s->conf, &dev->serial);
blkconf_blocksizes(&s->conf);
@@ -638,25 +655,6 @@ static void usb_msd_realize_storage(USBDevice *dev, Error
**errp)
}
usb_msd_handle_reset(dev);
s->scsi_dev = scsi_dev;
-
- if (bdrv_key_required(blk_bs(blk))) {
- if (cur_mon) {
- bdrv_add_key(blk_bs(blk), NULL, &err);
- if (!err) {
- usb_msd_password_cb(s, 0);
- } else if (monitor_cur_is_qmp()) {
- qerror_report_err(err);
- error_free(err);
- } else {
- error_free(err);
- monitor_read_bdrv_key_start(cur_mon, blk_bs(blk),
- usb_msd_password_cb, s);
- }
- s->dev.auto_attach = 0;
- } else {
- autostart = 0;
- }
- }
}
static void usb_msd_realize_bot(USBDevice *dev, Error **errp)
--
1.8.3.1
- [Qemu-devel] [PULL for-2.3 00/13] usb patch queue., Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 02/13] usb: Improve companion configuration error messages, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 13/13] ehci: fix segfault when hot-unplugging ehci controller, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 11/13] uhci: fix segfault when hot-unplugging uhci controller, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 12/13] ohci: fix resource cleanup leak, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 03/13] ohci: Complete conversion to realize, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 08/13] usb/dev-storage: Fix QMP device_add missing encryption key failure,
Gerd Hoffmann <=
- [Qemu-devel] [PULL 04/13] uhci: Convert to realize, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 06/13] monitor: Plug memory leak in monitor_read_bdrv_key_start(), Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 07/13] monitor usb: Inline monitor_read_bdrv_key_start()'s first part, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 05/13] monitor: Drop dead QMP check from monitor_read_password(), Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 10/13] hw/usb: Include USB files only if necessary, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 09/13] usb/dev-storage: Avoid qerror_report_err() outside QMP handlers, Gerd Hoffmann, 2015/03/18
- [Qemu-devel] [PULL 01/13] usb: Propagate errors through usb_register_companion(), Gerd Hoffmann, 2015/03/18
- Re: [Qemu-devel] [PULL for-2.3 00/13] usb patch queue., Peter Maydell, 2015/03/19