From nobody Wed Nov 5 16:38:16 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154145421124580.76593512395573; Mon, 5 Nov 2018 13:43:31 -0800 (PST) Received: from localhost ([::1]:37713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJmef-00036o-Vi for importer@patchew.org; Mon, 05 Nov 2018 16:43:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJmaL-0007ES-1q for qemu-devel@nongnu.org; Mon, 05 Nov 2018 16:39:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJmaH-0003Ac-AS for qemu-devel@nongnu.org; Mon, 05 Nov 2018 16:39:00 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:50430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJma2-0002ex-4o; Mon, 05 Nov 2018 16:38:42 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA5LSwQT143526; Mon, 5 Nov 2018 21:38:32 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2nh33tsr4k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Nov 2018 21:38:32 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wA5LcWOa024794 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 5 Nov 2018 21:38:32 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA5LcVYN000436; Mon, 5 Nov 2018 21:38:31 GMT Received: from ol7.uk.oracle.com (/10.175.201.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Nov 2018 13:38:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=sR0kWLfw37B8VgfUxXHVoBebY67ofMAmCBAwqRUXJGM=; b=UG0wVZsDffaqvfHiRs29ydcR3mTm5DTifYnrx42g8uo9I7inwwoxRxvm+1YqoXQooShN si+WVzL+OkVRn9Q7AtvZCp5SGF4qIO3CR4xEex1pHinEPq4scxdSjJevXIc2iIcwgWba RXo7uJzGkJiTKsnFDDsRDIQgzQnuhr4pQOpqSTwCqV+r1sSDEfXmEmh7xWFiM9cSOvLG ZBEjsZinUGP4aY5iWxbhcpYSsmtq8dOuQo9xvmOXpTzu429Pv9Gj6jYQxz1arbIezloH KFDxkrDsbQGVo4YGnAbFAZfYun+X51IImQT+FQ3vpY+3kIFFd57hlLktnfr/PIX6VS+G /w== From: Liam Merwick To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2018 21:38:39 +0000 Message-Id: <1541453919-25973-6-git-send-email-Liam.Merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1541453919-25973-1-git-send-email-Liam.Merwick@oracle.com> References: <1541453919-25973-1-git-send-email-Liam.Merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9068 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=838 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811050190 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v5 5/5] qcow2: Read outside array bounds in qcow2_pre_write_overlap_check() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jsnow@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The commit for 0e4e4318eaa5 increments QCOW2_OL_MAX_BITNR but does not add an array entry for QCOW2_OL_BITMAP_DIRECTORY_BITNR to metadata_ol_names= []. As a result, an array dereference of metadata_ol_names[8] in qcow2_pre_write_overlap_check() could result in a read outside of the array= bounds. Fixes: 0e4e4318eaa5 ('qcow2: add overlap check for bitmap directory') Cc: Vladimir Sementsov-Ogievskiy Signed-off-by: Liam Merwick Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3c539f02e5ec..46082aeac1d6 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -2719,15 +2719,17 @@ int qcow2_check_metadata_overlap(BlockDriverState *= bs, int ign, int64_t offset, } =20 static const char *metadata_ol_names[] =3D { - [QCOW2_OL_MAIN_HEADER_BITNR] =3D "qcow2_header", - [QCOW2_OL_ACTIVE_L1_BITNR] =3D "active L1 table", - [QCOW2_OL_ACTIVE_L2_BITNR] =3D "active L2 table", - [QCOW2_OL_REFCOUNT_TABLE_BITNR] =3D "refcount table", - [QCOW2_OL_REFCOUNT_BLOCK_BITNR] =3D "refcount block", - [QCOW2_OL_SNAPSHOT_TABLE_BITNR] =3D "snapshot table", - [QCOW2_OL_INACTIVE_L1_BITNR] =3D "inactive L1 table", - [QCOW2_OL_INACTIVE_L2_BITNR] =3D "inactive L2 table", + [QCOW2_OL_MAIN_HEADER_BITNR] =3D "qcow2_header", + [QCOW2_OL_ACTIVE_L1_BITNR] =3D "active L1 table", + [QCOW2_OL_ACTIVE_L2_BITNR] =3D "active L2 table", + [QCOW2_OL_REFCOUNT_TABLE_BITNR] =3D "refcount table", + [QCOW2_OL_REFCOUNT_BLOCK_BITNR] =3D "refcount block", + [QCOW2_OL_SNAPSHOT_TABLE_BITNR] =3D "snapshot table", + [QCOW2_OL_INACTIVE_L1_BITNR] =3D "inactive L1 table", + [QCOW2_OL_INACTIVE_L2_BITNR] =3D "inactive L2 table", + [QCOW2_OL_BITMAP_DIRECTORY_BITNR] =3D "bitmap directory", }; +QEMU_BUILD_BUG_ON(QCOW2_OL_MAX_BITNR !=3D ARRAY_SIZE(metadata_ol_names)); =20 /* * First performs a check for metadata overlaps (through --=20 1.8.3.1