Received: from eggs.gnu.org ([2001:4830:134:3::10]:41652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCnx9-0000pO-8L for qemu-devel@nongnu.org; Wed, 08 Jul 2015 07:55:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCnx6-0000Vq-Gg for qemu-devel@nongnu.org; Wed, 08 Jul 2015 07:55:51 -0400 Date: Wed, 8 Jul 2015 13:55:34 +0200 From: Kevin Wolf Message-ID: <20150708115534.GH4117@noname.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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline In-Reply-To: <20150626095705.GH15457@stefanha-thinkpad.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: Stefan Hajnoczi Cc: Jeff Cody , qemu-devel@nongnu.org, qemu-block@nongnu.org --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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, QDict= *options, int flags, > > > > goto fail; > > > > } > > > > =20 > > > > - s->pagetable =3D qemu_try_blockalign(bs->file, s->max_tabl= e_entries * 4); > > > > + pagetable_size =3D (size_t) s->max_table_entries * 4; > > > > + > > > > + s->pagetable =3D qemu_try_blockalign(bs->file, pagetable_s= ize); > > >=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. Jeff, I couldn't find a v2 anywhere. Are you still planning to send it? Kevin --9jxsPFA5p3P2qPhR Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJVnQ+2AAoJEH8JsnLIjy/WeMoP/2B/Lmshx/X8kOHCJQ/Yt1la y0Il3RBidcBKON+JLsbX5qH4pVAYB7nOxjs6pwqgusxd31n2FpatbJHYB4xLgQ0V P9N5ouuLc+ieUB4uxlRIsGKqqO43oY4cJ1sbNu7OWVEzlMIPySjfiP8ZdjHDf7iC zt/8FbmpAAhPWYBnP16ETk7+1BIvN7QDHQ8i4DAPJ/PvgpL5fGnKs+b0Y/lJCIDN pHhZ6mklVeyzVlHGMmHJyD3K4tB4eL9lSWwLjULyyFc/qPzeqnFDlcSsWHvBe9qM rD1qxc9sZ1aZQjeIS8R9kDRZGPsxl2fXQ300SRWd/nztxkYXq/kXSzl/dok2KyA4 YKhZZ1i9fXzYh29IoD2R6JrZlCSGo93JVpWNgmmjNbXAcaCJPQsbNK7fb0yGPmaV 67LOhDOw0FzU3vP7IXqp4fCozpLiukDk1AQ9f1CY1osMtrz8pdbLLFLCLFg3pZxr yneOw8ibcw560GVB2qY5oLx09xg8Nz75K/hq71icoq1PvLjQgmlTBq2jhjzwE+8B KSxf11FVS5Pe8W9oiApf2OvO0kP8AgBs/gm4oAMN0n7eZ1pSR4hDoMvt7vbC+uF9 sdzKmj+iQJD2gIqd46b2YAv2z6fyBHLdMXEICCKTikyZHoE+hRxrPhxSMKHgu2YA U5sqtyrBw56kkXoLEfmc =c1+d -----END PGP SIGNATURE----- --9jxsPFA5p3P2qPhR--