From nobody Sat May 18 20:15:33 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+95475+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+95475+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1666399060; cv=none; d=zohomail.com; s=zohoarc; b=GMRI5rNYrq7HE/2Rk0qmpOuZldrM7EowRE6sOsXZwvc75jYHl4qHQeME+F40RLt44ODOO/rnCIF+sbgxf3nbKuKnNmB4RCtqqZGtuI8D2c34D+iFXdc1pN5bx98yPolGLvEtFQPDOKJT8jsqBroyLrSrLVj/lsMIOisgNSrJpdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666399060; 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=AqBiCT6fQ27qNZwMd12lWGiE9I+rWERiRbT8cjzRpPg=; b=PnHYBp3uin3I14ASRDOWKyF1m7nlPF/MxfwRIfE0M/6VMPX9SW1OKHLa0mhdIr6V3le8wTiki/QyObAzrGbq1q3CI1UaUh1Ebeo8M2fdbhR6HQ5fIxSvIa8LWTWAdYjCVW3ztAKkKTFoYpVxao88+68jk6mwFHttIlHRvFDmckc= 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+95475+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 1666399060043224.54536871660105; Fri, 21 Oct 2022 17:37:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UbOoYY1788612xGDholObyP7; Fri, 21 Oct 2022 17:37:39 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web08.1946.1666399058559904008 for ; Fri, 21 Oct 2022 17:37:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="308821294" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="308821294" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 17:37:38 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10507"; a="633136796" X-IronPort-AV: E=Sophos;i="5.95,203,1661842800"; d="scan'208";a="633136796" X-Received: from nldesimo-desk1.amr.corp.intel.com ([10.24.80.62]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2022 17:37:37 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Liming Gao , Guomin Jiang , Jian J Wang , Michael D Kinney Subject: [edk2-devel] [PATCH V2] MdeModulePkg: Memory Corruption Error in CapsuleRuntimeDxe Date: Fri, 21 Oct 2022 17:37:34 -0700 Message-Id: <20221022003734.2134-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: yNOyMTRi3DfbX8AMfpEffxFPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666399059; bh=ntG1/sB+lK0Y+zjx1NGDgky4FOTOusb4HP/lN7y09I4=; h=Cc:Date:From:Reply-To:Subject:To; b=lyn6HMBkMoNuEGULA9p95VWjjSpLy/vUrjQ17dCesKl5z9/ekyV0i98GJ+PLw40THW0 jLM5kaMN4SdPixK2QyMr18mAa2AOP/Uhq9rH8qarsmCtIWt91wZuYVAhWVE/ZRgQLH1hQ oYJec+j5t/YzG6yUQCJdXelp1N5t5cWn640= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666399061407100001 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 --- .../X64/SaveLongModeContext.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeConte= xt.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c index dab297dd0a..616e142e23 100644 --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/X64/SaveLongModeContext.c @@ -59,7 +59,14 @@ 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 NULL) { + DEBUG ((DEBUG_ERROR, "ERROR AllocateReservedMemoryBelow4G(): AllocateP= ages() returned NULL")); + return NULL; + } =20 Buffer =3D (VOID *)(UINTN)Address; ZeroMem (Buffer, Size); @@ -159,14 +166,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 +205,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 (#95475): https://edk2.groups.io/g/devel/message/95475 Mute This Topic: https://groups.io/mt/94488664/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-