Received: from eggs.gnu.org ([2001:4830:134:3::10]:37563) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjVGo-0002jM-TQ for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XjVGf-00047h-Me for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:34:46 -0400 Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]:34050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjVGf-00047H-9J for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:34:37 -0400 Received: by mail-lb0-f171.google.com with SMTP id u10so751879lbd.2 for ; Wed, 29 Oct 2014 08:34:36 -0700 (PDT) Date: Wed, 29 Oct 2014 15:34:32 +0000 From: Stefan Hajnoczi Message-ID: <20141029153432.GI19774@stefanha-thinkpad.redhat.com> References: <1414512220-19058-1-git-send-email-armbru@redhat.com> <1414512220-19058-3-git-send-email-armbru@redhat.com> <20141029101242.GA3719@noname.str.redhat.com> <877fzjc76v.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TA4f0niHM6tHt3xR" Content-Disposition: inline In-Reply-To: <877fzjc76v.fsf@blackfin.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH RFC 2/2] block: Warn on insecure format probing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Kevin Wolf , jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com --TA4f0niHM6tHt3xR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 29, 2014 at 02:54:32PM +0100, Markus Armbruster wrote: > Kevin Wolf writes: >=20 > > Am 28.10.2014 um 17:03 hat Markus Armbruster geschrieben: > >> If the user neglects to specify the image format, QEMU probes the > >> image to guess it automatically, for convenience. > >>=20 > >> Relying on format probing is insecure for raw images (CVE-2008-2004). > >> If the guest writes a suitable header to the device, the next probe > >> will recognize a format chosen by the guest. A malicious guest can > >> abuse this to gain access to host files, e.g. by crafting a QCOW2 > >> header with backing file /etc/shadow. > >>=20 > >> Commit 1e72d3b (April 2008) provided -drive parameter format to let > >> users disable probing. Commit f965509 (March 2009) extended QCOW2 to > >> optionally store the backing file format, to let users disable backing > >> file probing. QED has had a flag to suppress probing since the > >> beginning (2010), set whenever a raw backing file is assigned. > >>=20 > >> Despite all this work (and time!), we're still insecure by default. I > >> think we're doing our users a disservice by sticking to the fatally > >> flawed probing. "Broken by default" is just wrong, and "convenience" > >> is no excuse. > >>=20 > >> I believe we can retain 90% of the convenience without compromising > >> security by keying on image file name instead of image contents: if > >> the file name ends in .img or .iso, assume raw, if it ends in .qcow2, > >> assume qcow2, and so forth. > >>=20 > >> Naturally, this would break command lines where the filename doesn't > >> provide the correct clue. So don't do it just yet, only warn if the > >> the change would lead to a different result. Looks like this: > >>=20 > >> qemu: -drive file=3Dmy.img: warning: insecure format probing of im= age 'my.img' > >> To get rid of this warning, specify format=3Dqcow2 explicitly, or = change > >> the image name to end with '.qcow2' > >>=20 > >> This should steer users away from insecure format probing. After a > >> suitable grace period, we can hopefully drop format probing > >> alltogether. > >>=20 > >> Example 0: file=3DWHATEVER,format=3DF > >>=20 > >> Never warns, because the explicit format suppresses probing. > >>=20 > >> Example 1: file=3DFOO.img > >>=20 > >> Warns when probing of FOO.img results in anything but raw. In > >> particular, it warns when the guest just p0wned you. > >>=20 > >> Example 2: file=3DFOO.qcow2 with backing file name FOO.img and no > >> backing image format. > >>=20 > >> Warns when probing of FOO.qcow2 results in anything but qcow2, or > >> probing of FOO.img results in anything but raw. > >>=20 > >> This patch is RFC because of open questions: > >>=20 > >> * Should tools warn, too? Probing isn't insecure there, but a "this > >> may pick a different format in the future" warning may be > >> appropriate. > >>=20 > >> * I didn't specify recognized extensions for formats "bochs", "cloop", > >> "parallels", "vpc", because I have no idea which ones to recognize. > >>=20 > >> Additionally, some tests still need to be updated. > >>=20 > >> Signed-off-by: Markus Armbruster > > > > I still don't like this approach very much. > > > > The first of the reasons, and arguably the weakest one, is simply that I > > aesthetically dislike to encode semantics in filenames by relying on > > filename extensions. Feels like I'm being moved back to DOS times. >=20 > It's the least bad solution so far, in my opinion. >=20 > For what it's worth, gcc decides what to do with a file based on its > file name extension, too. >=20 > > The second one, though, is probably a show stopper for me. You assume > > that there even is a filename that could have an extension, and that it > > is passed in the legacy filename argument instead of the QDict. With yo= ur > > patches: > > > > $ qemu-img create -f qcow2 /tmp/test.img 64M > > Formatting '/tmp/test.img', fmt=3Dqcow2 size=3D67108864 encryption=3Doff > > cluster_size=3D65536 lazy_refcounts=3Doff > > $ qemu-system-x86_64 -drive file=3D/tmp/test.img > > qemu-system-x86_64: -drive file=3D/tmp/test.img: warning: insecure > > format probing of image '/tmp/test.img' > > To get rid of this warning, specify format=3Dqcow2 explicitly, or change > > the image name to end with '.qcow2' > > $ x86_64-softmmu/qemu-system-x86_64 -drive file.filename=3D/tmp/test.img > > Speicherzugriffsfehler (Speicherabzug geschrieben) > > > > Oops, dereferencing a NULL pointer. Now, that's surely fixable, but what > > I originally wanted to demonstrate is that you won't output a warning > > there. Even that would still be fixable, by adding code into raw-posix, > > but what do you do with '-drive file.driver=3Dnbd,file.host=3Dlocalhost= '? > > > > And how does your patch help for '-drive blkverify:hacked.img:good.img'? >=20 > I'll reply to this as soon as I've had time to think. If you are using fancy command-lines, you need to use format=3D. The probing feature is really useful for -hda test.qcow2. Anything fancier requires enough knowledge (and typing on the command-line) that format=3Dqcow2 really isn't too much to ask for. > > Instead, let me try once more to sell my old proposal [1] from the > > thread you mentioned: > > > >> What if we let the raw driver know that it was probed and then it > >> enables a check that returns -EIO for any write on the first 2k if that > >> write would make the image look like a different format? > > > > Attacks the problem where it arises instead of trying to detect the > > outcome of it, and works in whatever way it is nested in the BDS graph > > and whatever way is used to address the image file. I think this is too clever. It's another thing to debug if a guest starts hitting EIO. My opinion on probing is: it's ugly but let's leave it for QEMU 3.0 at which point we implement Markus solution with exit(1). In the meantime the CVE has been known for a long time so vulnerable users (VM hosting, cloud, etc) have the information they need. Many are automatically protected by libvirt. Stefan --TA4f0niHM6tHt3xR Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUUQkIAAoJEJykq7OBq3PI/lQH/1N3kIM3+NuP1kvXn2270OLs +f/AtZgGihaYPEqhg7ip+hY95iRa9wBBCDcyWQO1o7QTK48jKO+TDS06JVvFfKew NaPrXVQUXileojcZ8FXhF7+94xd2UgrG0jYyaoDGfNk0N+7r246wUDlUbI148EOo KVICrCS2rYy8562lk1M6ANFN2rdp3RhTJn21rDXgW4O98y7w+xVuaeP2+wZYaoxM E8Y/zqvqlSEdT9KRJLCOdSUEpMj8+WNRnGKDtmgn4wHA3VxfoBhcVWzu89itF5Py biArKDITrVrSfFq/v5sgOS6ozlegkig7gI/DW6jrZTmD2B+hEZDKAN6mczVY1Xc= =MDmb -----END PGP SIGNATURE----- --TA4f0niHM6tHt3xR--