From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B86E321959CB2 for ; Tue, 26 Feb 2019 21:52:05 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2019 21:52:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,418,1544515200"; d="scan'208";a="121121460" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga008.jf.intel.com with ESMTP; 26 Feb 2019 21:52:04 -0800 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 26 Feb 2019 21:52:02 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 26 Feb 2019 21:52:02 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.110]) with mapi id 14.03.0415.000; Wed, 27 Feb 2019 13:52:00 +0800 From: "Ni, Ray" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Wang, Jian J" , "Zeng, Star" , Laszlo Ersek Thread-Topic: [PATCH v3 2/2] MdeModulePkg/RamDiskDxe: Restrict on RAM disk size (CVE-2018-12180) Thread-Index: AQHUzdLKcjEUDfh8zEqaiVXctm1+mKXzJVCg Date: Wed, 27 Feb 2019 05:48:44 +0000 Deferred-Delivery: Wed, 27 Feb 2019 05:52:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C03978F@SHSMSX104.ccr.corp.intel.com> References: <20190226125651.14260-1-hao.a.wu@intel.com> <20190226125651.14260-3-hao.a.wu@intel.com> In-Reply-To: <20190226125651.14260-3-hao.a.wu@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 2/2] MdeModulePkg/RamDiskDxe: Restrict on RAM disk size (CVE-2018-12180) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Feb 2019 05:52:05 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Wu, Hao A > Sent: Tuesday, February 26, 2019 8:57 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Wang, Jian J ; > Ni, Ray ; Zeng, Star ; Laszlo Erse= k > > Subject: [PATCH v3 2/2] MdeModulePkg/RamDiskDxe: Restrict on RAM disk > size (CVE-2018-12180) >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1134 >=20 > Originally, the block size of created Ram disks is hard-coded to 512 byte= s. > However, if the total size of the Ram disk is not a multiple of 512 bytes= , there > will be potential memory access issues when dealing with the last block o= f > the Ram disk. >=20 > This commit will adjust the block size of the Ram disks to ensure that th= e total > size is a multiple of the block size. >=20 > Cc: Jian J Wang > Cc: Ray Ni > Cc: Star Zeng > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Hao Wu > --- > MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h | 6 +++--- > MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c | 20 > ++++++++++++++------ > MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c | 5 +++-- > 3 files changed, 20 insertions(+), 11 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h > b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h > index 08a8ca94c9..72f2bfe179 100644 > --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h > +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h > @@ -1,7 +1,7 @@ > /** @file > The header file of RamDiskDxe driver. >=20 > - Copyright (c) 2016, Intel Corporation. All rights reserved.
> + Copyright (c) 2016 - 2019, Intel Corporation. All rights > + reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at @@ -49,9 +49,9 @@ /// >=20 > // > -// Block size for RAM disk > +// Default block size for RAM disk > // > -#define RAM_DISK_BLOCK_SIZE 512 > +#define RAM_DISK_DEFAULT_BLOCK_SIZE 512 >=20 > // > // Iterate through the double linked list. NOT delete safe diff --git > a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c > b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c > index 4f74b5ef15..8926ad7d2f 100644 > --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c > +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c > @@ -1,7 +1,7 @@ > /** @file > Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device. >=20 > - Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
> + Copyright (c) 2016 - 2019, Intel Corporation. All rights > + reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at @@ -54,6 +54,7 @@ RamDiskInitBlockIo ( > EFI_BLOCK_IO_PROTOCOL *BlockIo; > EFI_BLOCK_IO2_PROTOCOL *BlockIo2; > EFI_BLOCK_IO_MEDIA *Media; > + UINT32 Remainder; >=20 > BlockIo =3D &PrivateData->BlockIo; > BlockIo2 =3D &PrivateData->BlockIo2; > @@ -69,11 +70,18 @@ RamDiskInitBlockIo ( > Media->LogicalPartition =3D FALSE; > Media->ReadOnly =3D FALSE; > Media->WriteCaching =3D FALSE; > - Media->BlockSize =3D RAM_DISK_BLOCK_SIZE; > - Media->LastBlock =3D DivU64x32 ( > - PrivateData->Size + RAM_DISK_BLOCK_SIZE - = 1, > - RAM_DISK_BLOCK_SIZE > - ) - 1; > + > + for (Media->BlockSize =3D RAM_DISK_DEFAULT_BLOCK_SIZE; > + Media->BlockSize >=3D 1; > + Media->BlockSize =3D Media->BlockSize >> 1) { > + Media->LastBlock =3D DivU64x32Remainder (PrivateData->Size, Media- > >BlockSize, &Remainder) - 1; > + if (Remainder =3D=3D 0) { > + break; > + } > + } > + ASSERT (Media->BlockSize !=3D 0); > + > + return; > } >=20 >=20 > diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c > b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c > index 6784e2b2f1..e8250d5c1b 100644 > --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c > +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c > @@ -1,7 +1,7 @@ > /** @file > The realization of EFI_RAM_DISK_PROTOCOL. >=20 > - Copyright (c) 2016, Intel Corporation. All rights reserved.
> + Copyright (c) 2016 - 2019, Intel Corporation. All rights > + reserved.
> (C) Copyright 2016 Hewlett Packard Enterprise Development LP
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License @@ -613,7 +613,8 @@ RamDiskRegister ( > // > // Add check to prevent data read across the memory boundary > // > - if (RamDiskBase + RamDiskSize > ((UINTN) -1) - RAM_DISK_BLOCK_SIZE + 1= ) > { > + if ((RamDiskSize > MAX_UINTN) || > + (RamDiskBase > MAX_UINTN - RamDiskSize + 1)) { > return EFI_INVALID_PARAMETER; > } >=20 > -- > 2.12.0.windows.1