From 717bc4ace3e1830bf283861368352cc8545f3275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 13 Feb 2018 04:53:39 +0100 Subject: [PATCH] vm/appvm: forbid changing template if the are children DispVMs Changing AppVM's template will not update root volume reference in DispVMs based on it. For now forbid such change. Fixes QubesOS/qubes-issues#3576 --- qubes/vm/appvm.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index befc569b..856d9e7c 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -97,6 +97,15 @@ class AppVM(qubes.vm.qubesvm.QubesVM): super(AppVM, self).__init__(app, xml, **kwargs) + @property + def dispvms(self): + ''' Returns a generator containing all Disposable VMs based on the + current AppVM. + ''' + for vm in self.app.domains: + if hasattr(vm, 'template') and vm.template is self: + yield vm + @qubes.events.handler('domain-load') def on_domain_loaded(self, event): ''' When domain is loaded assert that this vm has a template. @@ -117,6 +126,9 @@ class AppVM(qubes.vm.qubesvm.QubesVM): if not self.is_halted(): raise qubes.exc.QubesVMNotHaltedError(self, 'Cannot change template while qube is running') + if any(self.dispvms): + raise qubes.exc.QubesVMInUseError(self, + 'Cannot change template while there are DispVMs based on this qube') @qubes.events.handler('property-set:template') def on_property_set_template(self, event, name, newvalue, oldvalue=None):