From nobody Sat May 18 14:25:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95476+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95476+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1666402438; cv=none; d=zohomail.com; s=zohoarc; b=GVquFgaD2tXa3lyjBvZC7XT++NdVhtnKlt4P3L9zMHPQnUMfHX56MYLCLAzvINgHmlm8S11ji5OrphlKDJq2WcOTXkJhsR+M+WZGXr4eqZJ1C5G7/9Qq0JLh14BA8fzilZkG7KYt5WJXitFZGzUCuFbnmmCHZU/Ap1V2MUaKZ8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666402438; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=dRepsythrThfn7y8bzVenXv8aaEoRp2cHu6RRurwaGY=; b=L8Iw/e/gfUeFgpGya1WYBbXTz7qrxI1RyhI1hlQ5exa9g8qwrvvUhu2F5fA5eUYfotvrwuoVhq5taG0GsnQ5/e4dbHT1bluJuXELOJm6FEo1oSClRzlKq0w3suONKhfOo9xsFgHSLSCn18PWTrsUfzfhGL7yYWotZLO/OSX/ues= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95476+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666402438283574.6137658299342; Fri, 21 Oct 2022 18:33:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ixa5YY1788612xSNZtQWDgIM; Fri, 21 Oct 2022 18:33:57 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web09.2334.1666402435957930030 for ; Fri, 21 Oct 2022 18:33:56 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="369211321" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="369211321" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 18:33:55 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="625547368" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="625547368" X-Received: from nldesimo-desk1.amr.corp.intel.com ([10.24.80.62]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 18:33:55 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Liming Gao , Guomin Jiang , Jian J Wang , Michael D Kinney Subject: [edk2-devel] [PATCH V3] MdeModulePkg: Memory Corruption Error in CapsuleRuntimeDxe Date: Fri, 21 Oct 2022 18:33:30 -0700 Message-Id: <20221022013330.2308-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,nathaniel.l.desimone@intel.com X-Gm-Message-State: 6mKQCpGnVXvfAVWjhSBPbMsYx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666402437; bh=dlNopugU3sI9DbfmanYWJf7WY8t4cmimBzBLWDpPXzg=; h=Cc:Date:From:Reply-To:Subject:To; b=OvF4D0LxKboeb8t4Xuwbp4KwRX1BEMJvalfuz9YaEnzI/8FkI2ZNVszZ72gglBM7hIQ UKEKzAszOa3KPDreq0dHwow2RA3SL/6BAjGoK8WO9RvZJoLSOi6r5hTmH+tqdcgoablKv r0XJKrCSSjyxtYY3o/cyudoxWch4Vy2zqRk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666402440223100003 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4112 In AllocateReservedMemoryBelow4G(), if gBS->AllocatePages() returns an error, and ASSERTs are disabled, then the function will overwrite memory from 0xFFFFFFFF -> (0xFFFFFFFF + Size). Cc: Liming Gao Cc: Guomin Jiang Cc: Jian J Wang Cc: Michael D Kinney Signed-off-by: Nate DeSimone Reviewed-by: Michael Kubacki --- .../X64/SaveLongModeContext.c | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeConte= xt.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c index dab297dd0a..a1bac730bf 100644 --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c @@ -59,7 +59,15 @@ AllocateReservedMemoryBelow4G ( Pages, &Address ); - ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): %r\n", St= atus)); + return NULL; + } + + if (Address =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): AllocateP= ages() returned NULL")); + return NULL; + } =20 Buffer =3D (VOID *)(UINTN)Address; ZeroMem (Buffer, Size); @@ -159,14 +167,23 @@ PrepareContextForCapsulePei ( DEBUG ((DEBUG_INFO, "CapsuleRuntimeDxe X64 TotalPagesNum - 0x%x pages\n"= , TotalPagesNum)); =20 LongModeBuffer.PageTableAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Allocat= eReservedMemoryBelow4G (EFI_PAGES_TO_SIZE (TotalPagesNum)); - ASSERT (LongModeBuffer.PageTableAddress !=3D 0); + if (LongModeBuffer.PageTableAddress =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be sav= ed, ")); + DEBUG ((DEBUG_ERROR, "PageTableAddress allocation failed. Capsule in P= EI may fail!\n")); + return; + } =20 // // Allocate stack // LongModeBuffer.StackSize =3D PcdGet32 (PcdCapsulePeiLongModeStack= Size); LongModeBuffer.StackBaseAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Allocat= eReservedMemoryBelow4G (PcdGet32 (PcdCapsulePeiLongModeStackSize)); - ASSERT (LongModeBuffer.StackBaseAddress !=3D 0); + if (LongModeBuffer.StackBaseAddress =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be sav= ed, ")); + DEBUG ((DEBUG_ERROR, "StackBaseAddress allocation failed. Capsule in P= EI may fail!\n")); + gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum); + return; + } =20 Status =3D gRT->SetVariable ( EFI_CAPSULE_LONG_MODE_BUFFER_NAME, @@ -189,6 +206,7 @@ PrepareContextForCapsulePei ( ); } else { DEBUG ((DEBUG_ERROR, "FATAL ERROR: CapsuleLongModeBuffer cannot be sav= ed: %r. Capsule in PEI may fail!\n", Status)); + gBS->FreePages (LongModeBuffer.PageTableAddress, TotalPagesNum); gBS->FreePages (LongModeBuffer.StackBaseAddress, EFI_SIZE_TO_PAGES (Lo= ngModeBuffer.StackSize)); } } --=20 2.27.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95476): https://edk2.groups.io/g/devel/message/95476 Mute This Topic: https://groups.io/mt/94489383/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-