From nobody Mon Feb 9 00:20:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584041414; cv=none; d=zohomail.com; s=zohoarc; b=ENR+NlpbB683SuEIav3N99jklfmlZP0TAGNw94F8nmB4djycimlvdZAgXsgXem33ZafsA+3prRld7L7CrVZTm6TZl4J3zL5A70uz2mSFjQOk/++nEjILxi/S8s03yMmF0ERjqMk4eZcG9MP6NYpme0Cne7h8VMRETwPXSZ83pOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584041414; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WPQJMhKCIltmCwLBq1efoswkULp2OXJsD9R0TiXVou8=; b=P+6tkzSwVwEEtB34K9dco35iEqBUosvVwY2b/uM67C7P/eXDmcRoES88lkFufpOW852DxKZSIZhq6iVUfLy+HvDg7mcQpGstnOZ1pERz6T/Qu5IZuMKLkntvM+d2gW1ewDEDEathzCSX0LsXED0vZCaborUhjRzlxmDxHcQNBPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1584041414038129.1915697806013; Thu, 12 Mar 2020 12:30:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-qQxbcECuM4mIMn3jvUu2jw-1; Thu, 12 Mar 2020 15:29:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 019561922962; Thu, 12 Mar 2020 19:29:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6DD29A6A; Thu, 12 Mar 2020 19:29:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7CDA685EC9; Thu, 12 Mar 2020 19:29:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02CJTCSW003490 for ; Thu, 12 Mar 2020 15:29:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B0C45DA83; Thu, 12 Mar 2020 19:29:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-177.phx2.redhat.com [10.3.116.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 738345DA76; Thu, 12 Mar 2020 19:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584041407; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=WPQJMhKCIltmCwLBq1efoswkULp2OXJsD9R0TiXVou8=; b=M6AMe7e93N0rTQIU4HpBM9zkjBZLoO8s6NP5vmGDDPbnkQuQYLtAQ59kLEbcpJ+6qTtGsj T2mrrQAEDGXcGouyd+5icx9liUFq/xlupS7fONFPV9QSeHtTDgTVqX0TmzzaNV2+p62xvi Wlak8Fc8y2NU4jMF8RTdWVAKUyJAo1g= X-MC-Unique: qQxbcECuM4mIMn3jvUu2jw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 7/7] qemu-img: Deprecate use of -b without -F Date: Thu, 12 Mar 2020 14:28:22 -0500 Message-Id: <20200312192822.3739399-8-eblake@redhat.com> In-Reply-To: <20200312192822.3739399-1-eblake@redhat.com> References: <20200312192822.3739399-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, libvir-list@redhat.com, mreitz@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Creating an image that requires format probing of the backing image is inherently unsafe (we've had several CVEs over the years based on probes leaking information to the guest on a subsequent boot, although these days tools like libvirt are aware of the issue enough to prevent the worst effects). However, if our probing algorithm ever changes, or if other tools like libvirt determine a different probe result than we do, then subsequent use of that backing file under a different format will present corrupted data to the guest. Start a deprecation clock so that future qemu-img can refuse to create unsafe backing chains that would rely on probing. The warnings are intentionally emitted from the block layer rather than qemu-img (thus, all paths into image creation or rewriting perform the check). However, there is one time where probing is safe: if we probe raw, then it is safe to record that implicitly in the image (but we still warn, as it's better to teach the user to supply -F always than to make them guess when it is safe). iotest 114 specifically wants to create an unsafe image for later amendment rather than defaulting to our new default of recording a probed format, so it needs an update. While touching it, expand it to cover all of the various warnings enabled by this patch. iotest 290 also shows a change to qcow messages; note that the fact that we now make a probed format of 'raw' explicit now results in a double warning, but no one should be creating new qcow images so it is not worth cleaning up. Signed-off-by: Eric Blake --- docs/system/deprecated.rst | 19 +++++++++++++++++++ block.c | 21 ++++++++++++++++++++- qemu-img.c | 2 +- tests/qemu-iotests/114 | 11 +++++++++++ tests/qemu-iotests/114.out | 8 ++++++++ tests/qemu-iotests/290.out | 5 ++++- 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst index 4261d5589e6a..b541d52c7dc0 100644 --- a/docs/system/deprecated.rst +++ b/docs/system/deprecated.rst @@ -382,6 +382,25 @@ image). Rather, any changes to the backing chain shou= ld be performed with ``qemu-img rebase -u`` either before or after the remaining changes being performed by amend, as appropriate. +qemu-img backing file without format (since 5.0.0) +'''''''''''''''''''''''''''''''''''''''''''''''''' + +The use of ``qemu-img create``, ``qemu-img rebase``, or ``qemu-img +convert`` to create or modify an image that depends on a backing file +now recommends that an explicit backing format be provided. This is +for safety: if qemu probes a different format than what you thought, +the data presented to the guest will be corrupt; similarly, presenting +a raw image to a guest allows a potential security exploit if a future +probe sees a non-raw image based on guest writes. To avoid the +warning message, or even future refusal to create an unsafe image, you +must pass ``-o backing_fmt=3D`` (or the shorthand ``-F`` during create) +to specify the intended backing format. You may use ``qemu-img rebase +-u`` to retroactively add a backing format to an existing image. +However, be aware that there are already potential security risks to +blindly using ``qemu-img info`` to probe the format of an untrusted +backing image, when deciding what format to add into an existing +image. + ``qemu-img convert -n -o`` (since 4.2.0) '''''''''''''''''''''''''''''''''''''''' diff --git a/block.c b/block.c index cd3277ab86fd..69955f53f35a 100644 --- a/block.c +++ b/block.c @@ -6064,6 +6064,20 @@ void bdrv_img_create(const char *filename, const cha= r *fmt, "Could not open backing image to determine s= ize.\n"); goto out; } else { + if (!backing_fmt) { + warn_report("Deprecated use of backing file without explic= it " + "backing format (detected format of %s)", + bs->drv->format_name); + if (bs->drv =3D=3D &bdrv_raw) { + /* + * A probe of raw is always correct, so in this one + * case, we can write that into the image. + */ + backing_fmt =3D bs->drv->format_name; + qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, backing_fmt, + NULL); + } + } if (size =3D=3D -1) { /* Opened BS, have no size */ size =3D bdrv_getlength(bs); @@ -6077,7 +6091,12 @@ void bdrv_img_create(const char *filename, const cha= r *fmt, } bdrv_unref(bs); } - } /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */ + /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */ + } else if (backing_file && !backing_fmt) { + warn_report("Deprecated use of unopened backing file without " + "explicit backing format, use of this image requires " + "potentially unsafe format probing"); + } if (size =3D=3D -1) { error_setg(errp, "Image creation needs a size parameter"); diff --git a/qemu-img.c b/qemu-img.c index 4ca1d2db7307..e977dd7e1e62 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3639,7 +3639,7 @@ static int img_rebase(int argc, char **argv) * doesn't change when we switch the backing file. */ if (out_baseimg && *out_baseimg) { - ret =3D bdrv_change_backing_file(bs, out_baseimg, out_basefmt, fal= se); + ret =3D bdrv_change_backing_file(bs, out_baseimg, out_basefmt, tru= e); } else { ret =3D bdrv_change_backing_file(bs, NULL, NULL, false); } diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114 index 26104fff6c67..5b06eab0ceee 100755 --- a/tests/qemu-iotests/114 +++ b/tests/qemu-iotests/114 @@ -42,9 +42,15 @@ _unsupported_proto vxhs # qcow2.py does not work too well with external data files _unsupported_imgopts data_file +# Intentionally specify backing file without backing format; demonstrate +# the difference in warning messages when backing file could be probed. +# Note that only a raw probe result will affect the resulting image. +truncate --size=3D64M "$TEST_IMG.orig" +_make_test_img -b "$TEST_IMG.orig" 64M TEST_IMG=3D"$TEST_IMG.base" _make_test_img 64M _make_test_img -b "$TEST_IMG.base" 64M +_make_test_img -u -b "$TEST_IMG.base" 64M # Set an invalid backing file format $PYTHON qcow2.py "$TEST_IMG" add-header-ext 0xE2792ACA "foo" @@ -55,6 +61,11 @@ _img_info $QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filt= er_testdir $QEMU_IO -c "open -o backing.driver=3D$IMGFMT $TEST_IMG" -c "read 0 4k" | = _filter_qemu_io +# Rebase the image, to show that omitting backing format triggers a warnin= g, +# but probing now lets us use the backing file. +$QEMU_IMG rebase -u -b "$TEST_IMG.base" "$TEST_IMG" +$QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filt= er_testdir + # success, all done echo '*** done' rm -f $seq.full diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out index 67adef37a4f6..59673abcd5e3 100644 --- a/tests/qemu-iotests/114.out +++ b/tests/qemu-iotests/114.out @@ -1,5 +1,10 @@ QA output created by 114 +qemu-img: warning: Deprecated use of backing file without explicit backing= format (detected format of raw) +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.orig backing_fmt=3Draw Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D67108864 +qemu-img: warning: Deprecated use of backing file without explicit backing= format (detected format of IMGFMT) +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base +qemu-img: warning: Deprecated use of unopened backing file without explici= t backing format, use of this image requires potentially unsafe format prob= ing Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base image: TEST_DIR/t.IMGFMT file format: IMGFMT @@ -11,4 +16,7 @@ qemu-io: can't open device TEST_DIR/t.qcow2: Could not op= en backing file: Unknow no file open, try 'help open' read 4096/4096 bytes at offset 0 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +qemu-img: warning: Deprecated use of backing file without explicit backing= format, use of this image requires potentially unsafe format probing +read 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done diff --git a/tests/qemu-iotests/290.out b/tests/qemu-iotests/290.out index 5b4ae3196d04..f80a5d982726 100644 --- a/tests/qemu-iotests/290.out +++ b/tests/qemu-iotests/290.out @@ -2,6 +2,7 @@ QA output created by 290 =3D=3D qcow backed by qcow =3D=3D Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D134217728 +qemu-img: warning: Deprecated use of backing file without explicit backing= format (detected format of IMGFMT) Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 backing_file= =3DTEST_DIR/t.IMGFMT.base image: TEST_DIR/t.IMGFMT file format: IMGFMT @@ -26,7 +27,9 @@ cluster_size: 512 backing file: TEST_DIR/t.IMGFMT.base =3D=3D qcow backed by raw =3D=3D -Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 backing_file= =3DTEST_DIR/t.IMGFMT.base +qemu-img: warning: Deprecated use of backing file without explicit backing= format (detected format of raw) +qemu-img: TEST_DIR/t.IMGFMT: IMGFMT cannot store backing format; an explic= it backing format of raw is unsafe +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 backing_file= =3DTEST_DIR/t.IMGFMT.base backing_fmt=3Draw image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128 MiB (134217728 bytes) --=20 2.25.1