From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.15793.1639182168454878176 for ; Fri, 10 Dec 2021 16:22:48 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=HIPBA/fI; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (c-73-27-179-174.hsd1.fl.comcast.net [73.27.179.174]) by linux.microsoft.com (Postfix) with ESMTPSA id 1D32120B7179; Fri, 10 Dec 2021 16:22:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1D32120B7179 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1639182167; bh=8hNIGPfOw6qnQiDipQtzlqxBiEUmonoXfy1TdzVCZ20=; h=From:To:Cc:Subject:Date:From; b=HIPBA/fIxatvpdPimHvWnerJVzhMe75zmgB3dd1lkuSH1dY8VxUUuI5x4d9JHM00f GRHJxFtHQBgdeiCtgKR98+Gj/vkTxOMZyeoH9AEKIotE/zKfJQJM/NyDWGkteLUsow JlD3ZRUZpIS2UqLyP/tTeZpzK/F36kY99XLiFfx0= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [edk2-platforms][PATCH v2 1/1] MinPlatformPkg/TestPointCheckLib: Fix DMAR structure length calculation Date: Fri, 10 Dec 2021 19:22:16 -0500 Message-Id: <20211211002216.4464-1-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3768 When processing DMAR structures of type EFI_ACPI_DMAR_STRUCTURE_HEADER within the ACPI DMAR table, the code determines the structure length by subtracting the DMAR structure headers present from the overall DMAR ACPI table size. The terminating condition is that the remaining total DMAR length is greater than zero. However, the current DMAR structure length is subtracted after the DMAR structure pointer has already been assigned to the next structure. This change subtracts the current DMAR structure length before transitioning to the next structure. The terminating condition is also updated to ensure the remaining size is at least as large as the expected structure header size. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Michael Kubacki --- Notes: V2 Changes: =20 - Updated the terminating condition to ensure the remaining size is at least as large as the expected structure size. Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcp= iDmar.c | 8 ++++---- Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckDma= Protection.c | 4 ++-- Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiCheckDma= Protection.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib= /DxeCheckAcpiDmar.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPoin= tCheckLib/DxeCheckAcpiDmar.c index b2279966d8ed..e0b7aaa48527 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckAcpiDmar.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckAcpiDmar.c @@ -133,7 +133,7 @@ DumpAcpiDmar ( // DmarLen =3D Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); - while (DmarLen > 0) { + while (DmarLen >=3D sizeof (*DmarStructHeader)) { switch (DmarStructHeader->Type) { case EFI_ACPI_DMAR_TYPE_DRHD: Drhd =3D (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -204,8 +204,8 @@ DumpAcpiDmar ( DEBUG ((DEBUG_INFO, "\n")); break; } - DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); DmarLen -=3D DmarStructHeader->Length; + DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); } } =20 @@ -220,7 +220,7 @@ CheckAcpiDmar ( =20 DmarLen =3D Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); - while (DmarLen > 0) { + while (DmarLen >=3D sizeof (*DmarStructHeader)) { switch (DmarStructHeader->Type) { case EFI_ACPI_DMAR_TYPE_DRHD: Drhd =3D (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -232,8 +232,8 @@ CheckAcpiDmar ( default: break; } - DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); DmarLen -=3D DmarStructHeader->Length; + DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); } return EFI_SUCCESS; } \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib= /DxeCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/Tes= tPointCheckLib/DxeCheckDmaProtection.c index 10b44fe8b9b8..aba0985956f2 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckDmaProtection.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeChe= ckDmaProtection.c @@ -38,7 +38,7 @@ CheckDrhd ( // DmarLen =3D Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); - while (DmarLen > 0) { + while (DmarLen >=3D sizeof (*DmarStructHeader)) { switch (DmarStructHeader->Type) { case EFI_ACPI_DMAR_TYPE_DRHD: Drhd =3D (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -56,8 +56,8 @@ CheckDrhd ( default: break; } - DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); DmarLen -=3D DmarStructHeader->Length; + DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); } =20 return EFI_SUCCESS; diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib= /PeiCheckDmaProtection.c b/Platform/Intel/MinPlatformPkg/Test/Library/Tes= tPointCheckLib/PeiCheckDmaProtection.c index cb764b3633ef..5a18235eddf4 100644 --- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiChe= ckDmaProtection.c +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/PeiChe= ckDmaProtection.c @@ -36,7 +36,7 @@ CheckDrhd ( // DmarLen =3D Dmar->Header.Length - sizeof(EFI_ACPI_DMAR_HEADER); DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)(Dmar + 1); - while (DmarLen > 0) { + while (DmarLen >=3D sizeof (*DmarStructHeader)) { switch (DmarStructHeader->Type) { case EFI_ACPI_DMAR_TYPE_DRHD: Drhd =3D (EFI_ACPI_DMAR_DRHD_HEADER *)DmarStructHeader; @@ -61,8 +61,8 @@ CheckDrhd ( default: break; } - DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); DmarLen -=3D DmarStructHeader->Length; + DmarStructHeader =3D (EFI_ACPI_DMAR_STRUCTURE_HEADER *)((UINT8 *)Dma= rStructHeader + DmarStructHeader->Length); } =20 return EFI_SUCCESS; --=20 2.28.0.windows.1