From nobody Mon Apr 29 14:53:53 2024 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504766039696864.2714156462033; Wed, 6 Sep 2017 23:33:59 -0700 (PDT) Received: from localhost ([::1]:39005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpqNx-0003kw-VT for importer@patchew.org; Thu, 07 Sep 2017 02:33:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpqN9-0003R8-2k for qemu-devel@nongnu.org; Thu, 07 Sep 2017 02:33:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpqN5-0001OK-VZ for qemu-devel@nongnu.org; Thu, 07 Sep 2017 02:33:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpqN5-0001O7-Q2 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 02:33:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AE4D8046A; Thu, 7 Sep 2017 06:33:02 +0000 (UTC) Received: from javelin.redhat.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C942918817; Thu, 7 Sep 2017 06:32:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8AE4D8046A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ppandit@redhat.com From: P J P To: Qemu Developers Date: Thu, 7 Sep 2017 12:02:56 +0530 Message-Id: <20170907063256.7418-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Sep 2017 06:33:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v1] multiboot: validate multiboot header address values 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: Paolo Bonzini , Prasad J Pandit , Eduardo Habkost , Thomas Garnier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit While loading kernel via multiboot-v1 image, (flags & 0x00010000) indicates that multiboot header contains valid addresses to load the kernel image. These addresses are used to compute kernel size and kernel text offset in the OS image. Validate these address values to avoid an OOB access issue. This is CVE-2017-14167. Reported-by: Thomas Garnier Signed-off-by: Prasad J Pandit --- hw/i386/multiboot.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) Update: add CVE-ID to the commit message. diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index 6001f4caa2..c7b70c91d5 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -221,15 +221,34 @@ int load_multiboot(FWCfgState *fw_cfg, uint32_t mh_header_addr =3D ldl_p(header+i+12); uint32_t mh_load_end_addr =3D ldl_p(header+i+20); uint32_t mh_bss_end_addr =3D ldl_p(header+i+24); + mh_load_addr =3D ldl_p(header+i+16); + if (mh_header_addr < mh_load_addr) { + fprintf(stderr, "invalid mh_load_addr address\n"); + exit(1); + } + uint32_t mb_kernel_text_offset =3D i - (mh_header_addr - mh_load_a= ddr); uint32_t mb_load_size =3D 0; mh_entry_addr =3D ldl_p(header+i+28); =20 if (mh_load_end_addr) { + if (mh_bss_end_addr < mh_load_addr) { + fprintf(stderr, "invalid mh_bss_end_addr address\n"); + exit(1); + } mb_kernel_size =3D mh_bss_end_addr - mh_load_addr; + + if (mh_load_end_addr < mh_load_addr) { + fprintf(stderr, "invalid mh_load_end_addr address\n"); + exit(1); + } mb_load_size =3D mh_load_end_addr - mh_load_addr; } else { + if (kernel_file_size < mb_kernel_text_offset) { + fprintf(stderr, "invalid kernel_file_size\n"); + exit(1); + } mb_kernel_size =3D kernel_file_size - mb_kernel_text_offset; mb_load_size =3D mb_kernel_size; } --=20 2.13.5