Skip to content

Commit a1f688f

Browse files
Markus Armbrusterkevmw
Markus Armbruster
authored andcommitted
block: Deprecate QCOW/QCOW2 encryption
We've steered users away from QCOW/QCOW2 encryption for a while, because it's a flawed design (commit 136cd19 Describe flaws in qcow/qcow2 encryption in the docs). In addition to flawed crypto, we have comically bad usability, and plain old bugs. Let me show you. = Example images = I'm going to use a raw image as backing file, and two QCOW2 images, one encrypted, and one not: $ qemu-img create -f raw backing.img 4m Formatting 'backing.img', fmt=raw size=4194304 $ qemu-img create -f qcow2 -o encryption,backing_file=backing.img,backing_fmt=raw geheim.qcow2 4m Formatting 'geheim.qcow2', fmt=qcow2 size=4194304 backing_file='backing.img' backing_fmt='raw' encryption=on cluster_size=65536 lazy_refcounts=off $ qemu-img create -f qcow2 -o backing_file=backing.img,backing_fmt=raw normal.qcow2 4m Formatting 'normal.qcow2', fmt=qcow2 size=4194304 backing_file='backing.img' backing_fmt='raw' encryption=off cluster_size=65536 lazy_refcounts=off = Usability issues = == Confusing startup == When no image is encrypted, and you don't give -S, QEMU starts the guest immediately: $ qemu-system-x86_64 -nodefaults -display none -monitor stdio normal.qcow2 QEMU 2.2.50 monitor - type 'help' for more information (qemu) info status VM status: running But as soon as there's an encrypted image in play, the guest is *not* started, with no notification whatsoever: $ qemu-system-x86_64 -nodefaults -display none -monitor stdio geheim.qcow2 QEMU 2.2.50 monitor - type 'help' for more information (qemu) info status VM status: paused (prelaunch) If the user figured out that he needs to type "cont" to enter his keys, the confusion enters the next level: "cont" asks for at most *one* key. If more are needed, it then silently does nothing. The user has to type "cont" once per encrypted image: $ qemu-system-x86_64 -nodefaults -display none -monitor stdio -drive if=none,file=geheim.qcow2 -drive if=none,file=geheim.qcow2 QEMU 2.2.50 monitor - type 'help' for more information (qemu) info status VM status: paused (prelaunch) (qemu) c none0 (geheim.qcow2) is encrypted. Password: ****** (qemu) info status VM status: paused (prelaunch) (qemu) c none1 (geheim.qcow2) is encrypted. Password: ****** (qemu) info status VM status: running == Incorrect passwords not caught == All existing encryption schemes give you the GIGO treatment: garbage password in, garbage data out. Guests usually refuse to mount garbage, but other usage is prone to data loss. == Need to stop the guest to add an encrypted image == $ qemu-system-x86_64 -nodefaults -display none -monitor stdio QEMU 2.2.50 monitor - type 'help' for more information (qemu) info status VM status: running (qemu) drive_add "" if=none,file=geheim.qcow2 Guest must be stopped for opening of encrypted image (qemu) stop (qemu) drive_add "" if=none,file=geheim.qcow2 OK Commit c3adb58 added this restriction. Before, we could expose images lacking an encryption key to guests, with potentially catastrophic results. See also "Use without key is not always caught". = Bugs = == Use without key is not always caught == Encrypted images can be in an intermediate state "opened, but no key". The weird startup behavior and the need to stop the guest are there to ensure the guest isn't exposed to that state. But other things still are! * drive_backup $ qemu-system-x86_64 -nodefaults -display none -monitor stdio geheim.qcow2 QEMU 2.2.50 monitor - type 'help' for more information (qemu) drive_backup -f ide0-hd0 out.img raw Formatting 'out.img', fmt=raw size=4194304 I guess this writes encrypted data to raw image out.img. Good luck with figuring out how to decrypt that again. * commit $ qemu-system-x86_64 -nodefaults -display none -monitor stdio geheim.qcow2 QEMU 2.2.50 monitor - type 'help' for more information (qemu) commit ide0-hd0 I guess this writes encrypted data into the unencrypted raw backing image, effectively destroying it. == QMP device_add of usb-storage fails when it shouldn't == When the image is encrypted, device_add creates the device, defers actually attaching it to when the key becomes available, then fails. This is wrong. device_add must either create the device and succeed, or do nothing and fail. $ 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"}} {"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": {}} This stuff is worse than useless, it's a trap for users. If people become sufficiently interested in encrypted images to contribute a cryptographically sane implementation for QCOW2 (or whatever other format), then rewriting the necessary support around it from scratch will likely be easier and yield better results than fixing up the existing mess. Let's deprecate the mess now, drop it after a grace period, and move on. Signed-off-by: Markus Armbruster <[email protected]> Reviewed-by: Eric Blake <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent 97a2ca7 commit a1f688f

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Diff for: block.c

+7
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,13 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
10651065
goto free_and_fail;
10661066
}
10671067

1068+
if (bs->encrypted) {
1069+
error_report("Encrypted images are deprecated");
1070+
error_printf("Support for them will be removed in a future release.\n"
1071+
"You can use 'qemu-img convert' to convert your image"
1072+
" to an unencrypted one.\n");
1073+
}
1074+
10681075
ret = refresh_total_sectors(bs, bs->total_sectors);
10691076
if (ret < 0) {
10701077
error_setg_errno(errp, -ret, "Could not refresh total sector count");

Diff for: qemu-doc.texi

+6-5
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ storage.
539539
@item qcow2
540540
QEMU image format, the most versatile format. Use it to have smaller
541541
images (useful if your filesystem does not supports holes, for example
542-
on Windows), optional AES encryption, zlib based compression and
543-
support of multiple VM snapshots.
542+
on Windows), zlib based compression and support of multiple VM
543+
snapshots.
544544

545545
Supported options:
546546
@table @code
@@ -574,9 +574,10 @@ original file must then be securely erased using a program like shred,
574574
though even this is ineffective with many modern storage technologies.
575575
@end itemize
576576

577-
Use of qcow / qcow2 encryption is thus strongly discouraged. Users are
578-
recommended to use an alternative encryption technology such as the
579-
Linux dm-crypt / LUKS system.
577+
Use of qcow / qcow2 encryption with QEMU is deprecated, and support for
578+
it will go away in a future release. Users are recommended to use an
579+
alternative encryption technology such as the Linux dm-crypt / LUKS
580+
system.
580581

581582
@item cluster_size
582583
Changes the qcow2 cluster size (must be between 512 and 2M). Smaller cluster

Diff for: tests/qemu-iotests/049.out

+6
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ qemu-img create -f qcow2 -o encryption=off TEST_DIR/t.qcow2 64M
188188
Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
189189

190190
qemu-img create -f qcow2 -o encryption=on TEST_DIR/t.qcow2 64M
191+
qemu-img: Encrypted images are deprecated
192+
Support for them will be removed in a future release.
193+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
194+
qemu-img: Encrypted images are deprecated
195+
Support for them will be removed in a future release.
196+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
191197
Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 encryption=on cluster_size=65536 lazy_refcounts=off refcount_bits=16
192198

193199
== Check lazy_refcounts option (only with v3) ==

Diff for: tests/qemu-iotests/087.out

+18
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@ QMP_VERSION
4444

4545
=== Encrypted image ===
4646

47+
qemu-img: Encrypted images are deprecated
48+
Support for them will be removed in a future release.
49+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
50+
qemu-img: Encrypted images are deprecated
51+
Support for them will be removed in a future release.
52+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
4753
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on
4854
Testing: -S
4955
QMP_VERSION
5056
{"return": {}}
57+
Encrypted images are deprecated
58+
Support for them will be removed in a future release.
59+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
5160
{"error": {"class": "GenericError", "desc": "blockdev-add doesn't support encrypted devices"}}
5261
{"return": {}}
5362
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
@@ -57,6 +66,9 @@ QMP_VERSION
5766
Testing:
5867
QMP_VERSION
5968
{"return": {}}
69+
Encrypted images are deprecated
70+
Support for them will be removed in a future release.
71+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
6072
{"error": {"class": "GenericError", "desc": "Guest must be stopped for opening of encrypted image"}}
6173
{"return": {}}
6274
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
@@ -66,6 +78,12 @@ QMP_VERSION
6678

6779
=== Missing driver ===
6880

81+
qemu-img: Encrypted images are deprecated
82+
Support for them will be removed in a future release.
83+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
84+
qemu-img: Encrypted images are deprecated
85+
Support for them will be removed in a future release.
86+
You can use 'qemu-img convert' to convert your image to an unencrypted one.
6987
Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 encryption=on
7088
Testing: -S
7189
QMP_VERSION

0 commit comments

Comments
 (0)