Skip to contentSkip to conversation

[6699] monitor: Rework early disk password inquiry (Jan Kiszka)

Qemu-devel Anthony Liguori 1 participant 1 message Mar 5, 2009

lore
Share & tools
lore
#0 lore raw

Revision: 6699

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6699
Author:   aliguori
Date:     2009-03-05 19:42:40 +0000 (Thu, 05 Mar 2009)

Log Message:
-----------
monitor: Rework early disk password inquiry (Jan Kiszka)

Reading the passwords for encrypted hard disks during early startup is broken (I guess for quiet a while now):
- No monitor terminal is ready for input at this point
- Forcing all mux'ed terminals into monitor mode can confuse other users of that channels

To overcome these issues and to lay the ground for a clean decoupling of monitor terminals, this patch changes the initial password inquiry as follows:
- Prevent autostart if there is some encrypted disk
- Once the user tries to resume the VM, prompt for all missing passwords
- Only resume if all passwords were accepted

Modified Paths:
--------------

    branches/stable_0_10_0/block.c
    branches/stable_0_10_0/block.h
    branches/stable_0_10_0/block_int.h
    branches/stable_0_10_0/console.h
    branches/stable_0_10_0/hw/usb-msd.c
    branches/stable_0_10_0/hw/usb.h
    branches/stable_0_10_0/monitor.c
    branches/stable_0_10_0/vl.c

Modified: branches/stable_0_10_0/block.c
===================================================================

stable_0_10_0/block.c +13 -1
@@ -336,6 +336,7 @@
     bs->read_only = 0;
     bs->is_temporary = 0;
     bs->encrypted = 0;
+    bs->valid_key = 0;
 
     if (flags & BDRV_O_SNAPSHOT) {
         BlockDriverState *bs1;
@@ -966,6 +967,15 @@
     return bs->encrypted;
 }
 
+int bdrv_key_required(BlockDriverState *bs)
+{
+    BlockDriverState *backing_hd = bs->backing_hd;
+
+    if (backing_hd && backing_hd->encrypted && !backing_hd->valid_key)
+        return 1;
+    return (bs->encrypted && !bs->valid_key);
+}
+
 int bdrv_set_key(BlockDriverState *bs, const char *key)
 {
     int ret;
@@ -978,7 +988,9 @@
     }
     if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key)
         return -1;
-    return bs->drv->bdrv_set_key(bs, key);
+    ret = bs->drv->bdrv_set_key(bs, key);
+    bs->valid_key = (ret == 0);
+    return ret;
 }
 
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size)

Modified: branches/stable_0_10_0/block.h
===================================================================

stable_0_10_0/block.h +2 -2
@@ -103,8 +103,6 @@
                                  BlockDriverCompletionFunc *cb, void *opaque);
 void bdrv_aio_cancel(BlockDriverAIOCB *acb);
 
-int qemu_key_check(BlockDriverState *bs, const char *name);
-
 /* Ensure contents are flushed to disk.  */
 void bdrv_flush(BlockDriverState *bs);
 void bdrv_flush_all(void);
@@ -144,7 +142,9 @@
 void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
                   void *opaque);
 int bdrv_is_encrypted(BlockDriverState *bs);
+int bdrv_key_required(BlockDriverState *bs);
 int bdrv_set_key(BlockDriverState *bs, const char *key);
+int bdrv_query_missing_keys(void);
 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
                          void *opaque);
 const char *bdrv_get_device_name(BlockDriverState *bs);

Modified: branches/stable_0_10_0/block_int.h
===================================================================

stable_0_10_0/block_int.h +1 -0
@@ -96,6 +96,7 @@
     int removable; /* if true, the media can be removed */
     int locked;    /* if true, the media cannot temporarily be ejected */
     int encrypted; /* if true, the media is encrypted */
+    int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
     /* event callback when inserting/removing */
     void (*change_cb)(void *opaque);

Modified: branches/stable_0_10_0/console.h
===================================================================

stable_0_10_0/console.h +1 -2
@@ -302,10 +302,9 @@
 void term_print_filename(const char *filename);
 void term_flush(void);
 void term_print_help(void);
-void monitor_readline(const char *prompt, int is_password,
-                      char *buf, int buf_size);
 void monitor_suspend(void);
 void monitor_resume(void);
+int monitor_read_bdrv_key(BlockDriverState *bs);
 
 /* readline.c */
 typedef void ReadLineFunc(void *opaque, const char *str);

Modified: branches/stable_0_10_0/hw/usb-msd.c
===================================================================

stable_0_10_0/hw/usb-msd.c +3 -3
@@ -11,6 +11,7 @@
 #include "usb.h"
 #include "block.h"
 #include "scsi-disk.h"
+#include "console.h"
 
 //#define DEBUG_MSD
 
@@ -513,7 +514,7 @@
     qemu_free(s);
 }
 
-USBDevice *usb_msd_init(const char *filename)
+USBDevice *usb_msd_init(const char *filename, BlockDriverState **pbs)
 {
     MSDState *s;
     BlockDriverState *bdrv;
@@ -552,9 +553,8 @@
     bdrv = bdrv_new("usb");
     if (bdrv_open2(bdrv, filename, 0, drv) < 0)
         goto fail;
-    if (qemu_key_check(bdrv, filename))
-        goto fail;
     s->bs = bdrv;
+    *pbs = bdrv;
 
     s->dev.speed = USB_SPEED_FULL;
     s->dev.handle_packet = usb_generic_handle_packet;

Modified: branches/stable_0_10_0/hw/usb.h
===================================================================

stable_0_10_0/hw/usb.h +4 -1
@@ -21,6 +21,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#include "block.h"
+
 #define USB_TOKEN_SETUP 0x2d
 #define USB_TOKEN_IN    0x69 /* device -> host */
 #define USB_TOKEN_OUT   0xe1 /* host -> device */
@@ -250,7 +253,7 @@
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
 
 /* usb-msd.c */
-USBDevice *usb_msd_init(const char *filename);
+USBDevice *usb_msd_init(const char *filename, BlockDriverState **pbs);
 
 /* usb-net.c */
 USBDevice *usb_net_init(NICInfo *nd);

Modified: branches/stable_0_10_0/monitor.c
===================================================================

stable_0_10_0/monitor.c +40 -4

73 lines not on this page · raw message

Modified: branches/stable_0_10_0/vl.c
===================================================================

stable_0_10_0/vl.c +21 -52

131 lines not on this page · raw message