From ba4dec5383902fb2e5d123568532f76758e7219b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 23 Nov 2016 03:25:03 +0100 Subject: [PATCH] qvm-block: fix checking attached status of disk image files Libvirt do not show actual block device (loop*) choosen for the device - only original (file) path. But file path is available in device description. Please note that VM can provide any description (withing allowed limits), effectively breaking this check again (hidding the attachment status). But even without this bug it could do that - by hidding the whole device from QubesDB. Fixes QubesOS/qubes-issues#2453 --- core/qubesutils.py | 4 +++- qvm-tools/qvm-block | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/qubesutils.py b/core/qubesutils.py index ce15dc10..bd080559 100644 --- a/core/qubesutils.py +++ b/core/qubesutils.py @@ -372,7 +372,9 @@ def block_check_attached(qvmc, device): "VM '%s'" % (source.get('type'), vm.name) continue - if backend_name == device['vm'] and path == device['device']: + if backend_name == device['vm'] and (path == device['device'] + or not path.startswith('/dev/') and path == device[ + 'desc']): return { "frontend": disk.find('target').get('dev'), "vm": vm} diff --git a/qvm-tools/qvm-block b/qvm-tools/qvm-block index 3d7a6df8..2a1e9578 100755 --- a/qvm-tools/qvm-block +++ b/qvm-tools/qvm-block @@ -87,6 +87,7 @@ def main(): if options.do_file_attach: dev = {} (dev['vm'], dev['device']) = args[1].split(":") + dev['desc'] = dev['device'] dev['mode'] = 'w' else: dev_list = block_list(qvm_collection)