Received: from eggs.gnu.org ([2001:4830:134:3::10]:39691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZD8ow-0007Yt-Tb for qemu-devel@nongnu.org; Thu, 09 Jul 2015 06:12:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZD8ot-0008RI-LM for qemu-devel@nongnu.org; Thu, 09 Jul 2015 06:12:46 -0400 Date: Thu, 9 Jul 2015 11:12:39 +0100 From: Stefan Hajnoczi Message-ID: <20150709101239.GB28530@stefanha-thinkpad.redhat.com> References: <4273ff9b577ffc2b2b3ff7137beabfb831a38d65.1435175476.git.jcody@redhat.com> <20150625142835.GP4419@stefanha-thinkpad.redhat.com> <20150625150520.GB13877@localhost.localdomain> <20150626095705.GH15457@stefanha-thinkpad.redhat.com> <20150708115534.GH4117@noname.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8GpibOaaTibBMecb" Content-Disposition: inline In-Reply-To: <20150708115534.GH4117@noname.redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] block: vpc - prevent overflow if max_table_entries >= 0x40000000 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Jeff Cody , qemu-devel@nongnu.org, qemu-block@nongnu.org --8GpibOaaTibBMecb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 08, 2015 at 01:55:34PM +0200, Kevin Wolf wrote: > Am 26.06.2015 um 11:57 hat Stefan Hajnoczi geschrieben: > > On Thu, Jun 25, 2015 at 11:05:20AM -0400, Jeff Cody wrote: > > > On Thu, Jun 25, 2015 at 03:28:35PM +0100, Stefan Hajnoczi wrote: > > > > On Wed, Jun 24, 2015 at 03:54:27PM -0400, Jeff Cody wrote: > > > > > @@ -269,7 +270,9 @@ static int vpc_open(BlockDriverState *bs, QDi= ct *options, int flags, > > > > > goto fail; > > > > > } > > > > > =20 > > > > > - s->pagetable =3D qemu_try_blockalign(bs->file, s->max_ta= ble_entries * 4); > > > > > + pagetable_size =3D (size_t) s->max_table_entries * 4; > > > > > + > > > > > + s->pagetable =3D qemu_try_blockalign(bs->file, pagetable= _size); > > > >=20 > > > > On 32-bit hosts size_t is 32-bit so the overflow hasn't been solved. > > > >=20 > > > > Does it make sense to impose a limit on pagetable_size? > > >=20 > > > Good point. Yes, it does. > > >=20 > > > The VHD spec says that the "Max Table Entries" field should be equal > > > to the disk size / block size. I don't know if there are images out > > > there that treat that as ">=3D disk size / block size" rather than "= =3D=3D", > > > however. But if we assume max size of 2TB for a VHD disk, and a > > > minimal block size of 512 bytes, that would give us a > > > max_table_entries of 0x100000000, which exceeds 32 bits by itself. > > >=20 > > > For pagetable_size to fit in a 32-bit, that means to support 2TB on a > > > 32-bit host in the current implementation, the minimum block size is > > > 4096. > > >=20 > > > We could check during open / create that=20 > > > (disk_size / block_size) * 4 < SIZE_MAX, and refuse to open if this is > > > not true (and also validate max_table_entries to fit in the same). > >=20 > > Sounds good. >=20 > Jeff, I couldn't find a v2 anywhere. Are you still planning to send it? Jeff is on vacation. I think he's back next week. --8GpibOaaTibBMecb Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVnkkXAAoJEJykq7OBq3PIuOoH/0zUi3RDzIw16B+bsxMiHeZX 5TiVBjTnfBdMWfkDaN2Y/X8+Mfe5sKLfL1R5E9t/pHlzDr78GLRVwsWb2A80KHeh k/PsF3eJpKRyuNw14F1UMiImErRm/5I7/bWLwkpX0zdzXJnOvnUlNuxOtxVGNKYf ShXWBx3s15cyVMW1EQxKl1w1c133s1G+ZUbQHwD6zPcywgOmHhCN9s6AxB/p2q6Y Km1Cv3dkD2XdZGXpc5DcP2HxosiplZO7qNusD3Mo5fQ3zd6tq5uzBSwVgRyC6t0L f1ycPbF9X+IT4WLeCsSVkVfxbXByDxxIaAagt+Gejxb5jdJh6w7zQIaIuMWDfyk= =xa6c -----END PGP SIGNATURE----- --8GpibOaaTibBMecb--