From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 22956D80144 for ; Fri, 12 Jan 2024 02:25:36 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lS07jaxcIXHKTp+WvWGeI/FKl3bfPgDT4WEaEegcbbs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1705026335; v=1; b=GbetU4PzQe8VlzG6cRTJ8y0cAFZEXwBmfzwNCf7PjWbq1nYRJFC7UwBb8cIDWu/4V7GsA382 YsFx7TWlpJVrtgDMkDxfx1B0hEA5GtAL0sL/U9whOJcJ1xFOqvkhZnPU30O8xSL2XAtbPyAh8Jn VvuzMwXG7zn8SscpJEAG4FqU= X-Received: by 127.0.0.2 with SMTP id cnyqYY7687511xO0GiEiscli; Thu, 11 Jan 2024 18:25:35 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.10551.1705026335263380174 for ; Thu, 11 Jan 2024 18:25:35 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10950"; a="6423572" X-IronPort-AV: E=Sophos;i="6.04,188,1695711600"; d="scan'208";a="6423572" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2024 18:25:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10950"; a="873233195" X-IronPort-AV: E=Sophos;i="6.04,188,1695711600"; d="scan'208";a="873233195" X-Received: from gguo-desk.gar.corp.intel.com ([10.225.76.26]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jan 2024 18:25:31 -0800 From: "Guo, Gua" To: devel@edk2.groups.io Cc: gua.guo@intel.com, Marc Beatove , Ard Biesheuvel , Sami Mujawar , Ray Ni , John Mathew , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 2/4] StandaloneMmPkg/Hob: Integer Overflow in CreateHob() Date: Fri, 12 Jan 2024 10:25:18 +0800 Message-Id: <20240112022521.710-3-gua.guo@intel.com> In-Reply-To: <20240112022521.710-1-gua.guo@intel.com> References: <20240112022521.710-1-gua.guo@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gua.guo@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: khEd7v4zTEvzObCTFBfhujSQx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=GbetU4Pz; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) From: Gua Guo REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4166 Fix integer overflow in various CreateHob instances. Fixes: CVE-2022-36765 The CreateHob() function aligns the requested size to 8 performing the following operation: ``` HobLength =3D (UINT16)((HobLength + 0x7) & (~0x7)); ``` No checks are performed to ensure this value doesn't overflow, and could lead to CreateHob() returning a smaller HOB than requested, which could lead to OOB HOB accesses. Reported-by: Marc Beatove Reviewed-by: Ard Biesheuvel Cc: Sami Mujawar Cc: Ray Ni Cc: John Mathew Authored-by: Gerd Hoffmann Signed-off-by: Gua Guo --- .../Arm/StandaloneMmCoreHobLib.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneM= mCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/Standalo= neMmCoreHobLib.c index 1550e1babc..59473e28fe 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHo= bLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHo= bLib.c @@ -34,6 +34,13 @@ CreateHob ( =0D HandOffHob =3D GetHobList ();=0D =0D + //=0D + // Check Length to avoid data overflow.=0D + //=0D + if (HobLength > MAX_UINT16 - 0x7) {=0D + return NULL;=0D + }=0D +=0D HobLength =3D (UINT16)((HobLength + 0x7) & (~0x7));=0D =0D FreeMemory =3D HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryB= ottom;=0D @@ -89,6 +96,10 @@ BuildModuleHob ( );=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMOR= Y_ALLOCATION_MODULE));=0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModule= Guid);=0D Hob->MemoryAllocationHeader.MemoryBaseAddress =3D MemoryAllocationModule= ;=0D @@ -129,6 +140,9 @@ BuildResourceDescriptorHob ( =0D Hob =3D CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RES= OURCE_DESCRIPTOR));=0D ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D Hob->ResourceType =3D ResourceType;=0D Hob->ResourceAttribute =3D ResourceAttribute;=0D @@ -167,6 +181,11 @@ BuildGuidHob ( ASSERT (DataLength <=3D (0xffff - sizeof (EFI_HOB_GUID_TYPE)));=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof (EFI_HOB= _GUID_TYPE) + DataLength));=0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return NULL;=0D + }=0D +=0D CopyGuid (&Hob->Name, Guid);=0D return Hob + 1;=0D }=0D @@ -226,6 +245,10 @@ BuildFvHob ( EFI_HOB_FIRMWARE_VOLUME *Hob;=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));=0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D Hob->BaseAddress =3D BaseAddress;=0D Hob->Length =3D Length;=0D @@ -255,6 +278,10 @@ BuildFv2Hob ( EFI_HOB_FIRMWARE_VOLUME2 *Hob;=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));= =0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D Hob->BaseAddress =3D BaseAddress;=0D Hob->Length =3D Length;=0D @@ -282,6 +309,10 @@ BuildCpuHob ( EFI_HOB_CPU *Hob;=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));=0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D Hob->SizeOfMemorySpace =3D SizeOfMemorySpace;=0D Hob->SizeOfIoSpace =3D SizeOfIoSpace;=0D @@ -319,6 +350,10 @@ BuildMemoryAllocationHob ( );=0D =0D Hob =3D CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMOR= Y_ALLOCATION));=0D + ASSERT (Hob !=3D NULL);=0D + if (Hob =3D=3D NULL) {=0D + return;=0D + }=0D =0D ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));=0D Hob->AllocDescriptor.MemoryBaseAddress =3D BaseAddress;=0D --=20 2.39.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113641): https://edk2.groups.io/g/devel/message/113641 Mute This Topic: https://groups.io/mt/103675962/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-