Commit c0f4ce77 authored by Anthony Liguori's avatar Anthony Liguori
Browse files

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

Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6707 c046a42c-6fe2-441c-8c8c-71466251a162
parent 430eb509
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -336,6 +336,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
    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 @@ int bdrv_is_encrypted(BlockDriverState *bs)
    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 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
    }
    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)
+2 −2
Original line number Diff line number Diff line
@@ -103,8 +103,6 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
                                 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 @@ BlockDriverState *bdrv_find(const char *name);
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);
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ struct BlockDriverState {
    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);
+1 −2
Original line number Diff line number Diff line
@@ -302,10 +302,9 @@ void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1
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);
+3 −3
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include "usb.h"
#include "block.h"
#include "scsi-disk.h"
#include "console.h"

//#define DEBUG_MSD

@@ -513,7 +514,7 @@ static void usb_msd_handle_destroy(USBDevice *dev)
    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 @@ USBDevice *usb_msd_init(const char *filename)
    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;
Loading