Received: from eggs.gnu.org ([2001:4830:134:3::10]:35207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLBHd-00055e-34 for qemu-devel@nongnu.org; Wed, 05 Mar 2014 07:50:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLBHX-00051M-PQ for qemu-devel@nongnu.org; Wed, 05 Mar 2014 07:50:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38007) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLBHX-00051F-BI for qemu-devel@nongnu.org; Wed, 05 Mar 2014 07:50:43 -0500 From: Markus Armbruster References: <87wqgflzno.fsf@blackfin.pond.sub.org> <20140303105837.GD4850@dhcp-200-207.str.redhat.com> <87zjl56nog.fsf@blackfin.pond.sub.org> <5316EF5F.2040003@suse.de> <87k3c9ylss.fsf@blackfin.pond.sub.org> <5316FF3A.3050801@redhat.com> Date: Wed, 05 Mar 2014 13:50:28 +0100 In-Reply-To: <5316FF3A.3050801@redhat.com> (Paolo Bonzini's message of "Wed, 05 Mar 2014 11:40:58 +0100") Message-ID: <878usox10r.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] The unholy encrypted image key mess List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , Gerd Hoffmann , Andreas =?utf-8?Q?F=C3=A4rber?= , Stefan Hajnoczi , qemu-devel@nongnu.org Paolo Bonzini writes: > Il 05/03/2014 11:36, Markus Armbruster ha scritto: >> Andreas F=C3=A4rber writes: >> >>> Am 05.03.2014 09:43, schrieb Markus Armbruster: >>>> Kevin Wolf writes: >>>> >>>>> 'change' is a bit trickier because it involves several low-level acti= ons >>>>> at once, and device_add is not one of them. >>>> >>>> The problem is that it can run while a device model is attached. >>> >>> What exactly is the problem here? 'change' is for floppy and CD, right? >>> The device stays realized/connected and guest-visible during that time, >>> and the guest should be able to live with no media while the new drive >>> is not yet decrypted. Are we just lacking a QMP command to enter the >>> password and complete the change while the guest is executing? >> >> Here's how change works (both HMP and QMP): >> >> 1. bdrv_close(); now we have no medium. >> >> 2. If a device model is attached, tell it the medium has been ejected. >> A device model supporting notification (anything but floppy, I guess) >> in turn notifies the guest. >> >> 3. bdrv_open(); now we again have a medium, we're in state NOKEY if the >> image is unencrypted, and in state NEEDKEY if it's encrypted. >> >> 4. Only in state NOKEY: if a device model is attached, tell it a medium >> has been loaded. A device model supporting notification in turn >> notifies the guest. >> >> 5. Only in state NEEDKEY: >> >> If QMP, fail the command with error DeviceEncrypted. >> >> If HMP, prompt user for password. >> >> In QMP, the client needs to follow up with a block_passwd command. In >> HMP, the user neeeds to enter a password. In both cases, time passes, >> guest can run, and even other monitor commands can be executed, possibly >> in other monitors. When the password arrives: >> >> 7. Set the key, state is now GOTKEY. >> >> 8. If a device model is attached, tell it a medium has been loaded. A >> device model supporting notification in turn notifies the guest. >> >> Shit happens for encrypted images if anything reads or writes between >> 3. and 8. > > You could use bdrv_new before step 3, to open the new medium on a new > temporary BDS. Then before step 8 you use bdrv_swap and delete the > temporary BDS. If we can't get rid of state NEEDKEY entirely, then we need to hide BDSs in this state from anything but the QMP command to set the key. As long as we don't have BlockBackend, we need to do something like you described to keep NEEDKEY hidden from the device model even though the device model has a direct reference to its backing BDS.