From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBOUi-0006aS-Ik for qemu-devel@nongnu.org; Wed, 14 Jan 2015 09:00:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YBOUd-0001BJ-Fz for qemu-devel@nongnu.org; Wed, 14 Jan 2015 09:00:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44763) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YBOUd-0001B9-9I for qemu-devel@nongnu.org; Wed, 14 Jan 2015 09:00:19 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0EE0IE1029589 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 14 Jan 2015 09:00:18 -0500 Date: Wed, 14 Jan 2015 15:00:16 +0100 From: Kevin Wolf Message-ID: <20150114140016.GH5136@noname.redhat.com> References: <1421065893-18875-1-git-send-email-stefanha@redhat.com> <1421065893-18875-2-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1421065893-18875-2-git-send-email-stefanha@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] qed: check for header size overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, mreitz@redhat.com Am 12.01.2015 um 13:31 hat Stefan Hajnoczi geschrieben: > Header size is denoted in clusters. The maximum cluster size is 64 MB > but there is no limit on header size. Check for uint32_t overflow in > case the header size field has a whacky value. > > Signed-off-by: Stefan Hajnoczi > --- > block/qed.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/block/qed.c b/block/qed.c > index 80f18d8..d2c6045 100644 > --- a/block/qed.c > +++ b/block/qed.c > @@ -440,6 +440,12 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *options, int flags, > s->l2_mask = s->table_nelems - 1; > s->l1_shift = s->l2_shift + ffs(s->table_nelems) - 1; > > + /* Header size calculation must not overflow uint32_t */ > + if ((uint64_t)s->header.cluster_size * s->header.header_size != > + s->header.cluster_size * s->header.header_size) { Generally, I find checks that don't exercise the integer overflow easier to read, i.e. in this case: if (s->header.header_size > UINT32_MAX / s->header.cluster_size) Or even just INT_MAX to be on the safe side. But I'll admit that it's a matter of taste. > + return -EINVAL; > + } > + > if ((s->header.features & QED_F_BACKING_FILE)) { > if ((uint64_t)s->header.backing_filename_offset + > s->header.backing_filename_size > Series: Reviewed-by: Kevin Wolf