From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjsXj-00072w-6v for qemu-devel@nongnu.org; Mon, 12 May 2014 11:53:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjsXa-0006pA-4z for qemu-devel@nongnu.org; Mon, 12 May 2014 11:53:31 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:47912 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjsXZ-0006p5-QK for qemu-devel@nongnu.org; Mon, 12 May 2014 11:53:22 -0400 Date: Mon, 12 May 2014 17:53:56 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140512155356.GH7858@irqsave.net> References: <1399899851-5641-1-git-send-email-kwolf@redhat.com> <1399899851-5641-6-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1399899851-5641-6-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 5/5] qcow1: Stricter backing file length check* List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, stefanha@redhat.com, ppandit@redhat.com The Monday 12 May 2014 =E0 15:04:11 (+0200), Kevin Wolf wrote : > Like qcow2 since commit 6d33e8e7, error out on invalid lengths instead > of silently truncating them to 1023. >=20 > Also don't rely on bdrv_pread() catching integer overflows that make le= n > negative, but use unsigned variables in the first place. >=20 > Signed-off-by: Kevin Wolf > --- > block/qcow.c | 7 +++++-- > tests/qemu-iotests/092 | 11 +++++++++++ > tests/qemu-iotests/092.out | 7 +++++++ > 3 files changed, 23 insertions(+), 2 deletions(-) >=20 > diff --git a/block/qcow.c b/block/qcow.c > index 3566c05..7fd57d7 100644 > --- a/block/qcow.c > +++ b/block/qcow.c > @@ -97,7 +97,8 @@ static int qcow_open(BlockDriverState *bs, QDict *opt= ions, int flags, > Error **errp) > { > BDRVQcowState *s =3D bs->opaque; > - int len, i, shift, ret; > + unsigned int len, i, shift; > + int ret; > QCowHeader header; > =20 > ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); > @@ -202,7 +203,9 @@ static int qcow_open(BlockDriverState *bs, QDict *o= ptions, int flags, > if (header.backing_file_offset !=3D 0) { > len =3D header.backing_file_size; > if (len > 1023) { > - len =3D 1023; > + error_setg(errp, "Backing file name too long"); > + ret =3D -EINVAL; > + goto fail; > } > ret =3D bdrv_pread(bs->file, header.backing_file_offset, > bs->backing_file, len); > diff --git a/tests/qemu-iotests/092 b/tests/qemu-iotests/092 > index 26a1324..b1333a0 100755 > --- a/tests/qemu-iotests/092 > +++ b/tests/qemu-iotests/092 > @@ -43,6 +43,8 @@ _supported_fmt qcow > _supported_proto generic > _supported_os Linux > =20 > +offset_backing_file_offset=3D8 > +offset_backing_file_size=3D16 > offset_size=3D24 > offset_cluster_bits=3D32 > offset_l2_bits=3D33 > @@ -73,6 +75,15 @@ poke_file "$TEST_IMG" "$offset_size" "\xee\xee\xee\x= ee\xee\xee\xee\xee" > poke_file "$TEST_IMG" "$offset_size" "\x7f\xff\xff\xff\xff\xff\xff\xff= " > { $QEMU_IO -c "write 0 64M" $TEST_IMG; } 2>&1 | _filter_qemu_io | _fil= ter_testdir > =20 > +echo > +echo "=3D=3D Invalid backing file length =3D=3D" > +_make_test_img 64M > +poke_file "$TEST_IMG" "$offset_backing_file_offset" "\x00\x00\x00\xff" > +poke_file "$TEST_IMG" "$offset_backing_file_size" "\xff\xff\xff\xff" > +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filt= er_testdir > +poke_file "$TEST_IMG" "$offset_backing_file_size" "\x7f\xff\xff\xff" > +{ $QEMU_IO -c "read 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filt= er_testdir > + > # success, all done > echo "*** done" > rm -f $seq.full > diff --git a/tests/qemu-iotests/092.out b/tests/qemu-iotests/092.out > index c3678a0..e957887 100644 > --- a/tests/qemu-iotests/092.out > +++ b/tests/qemu-iotests/092.out > @@ -20,4 +20,11 @@ qemu-io: can't open device TEST_DIR/t.qcow: Image to= o large > no file open, try 'help open' > qemu-io: can't open device TEST_DIR/t.qcow: Image too large > no file open, try 'help open' > + > +=3D=3D Invalid backing file length =3D=3D > +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864=20 > +qemu-io: can't open device TEST_DIR/t.qcow: Backing file name too long > +no file open, try 'help open' > +qemu-io: can't open device TEST_DIR/t.qcow: Backing file name too long > +no file open, try 'help open' > *** done > --=20 > 1.8.3.1 >=20 >=20 Reviewed-by: Benoit Canet