X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SecurityPkg%2FTcg%2FOpal%2FOpalPasswordSmm%2FOpalAhciMode.c;h=33f77bd8a248248baa75c61b45fca88a7fdc1f38;hp=0dc3490a362d2135e17091031cec7a24bfe1abba;hb=009264f5cf0fa0009ff96f307eaac88860a998a8;hpb=83681c74f07978adbb621a467fe391ae901e2515 diff --git a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalAhciMode.c b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalAhciMode.c index 0dc3490a36..33f77bd8a2 100644 --- a/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalAhciMode.c +++ b/SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalAhciMode.c @@ -1022,6 +1022,34 @@ GetAhciBarSize ( return Size; } +/** + This function check if the memory region is in GCD MMIO region. + + @param Addr The memory region start address to be checked. + @param Size The memory region length to be checked. + + @retval TRUE This memory region is in GCD MMIO region. + @retval FALSE This memory region is not in GCD MMIO region. +**/ +BOOLEAN +EFIAPI +OpalIsValidMmioSpace ( + IN EFI_PHYSICAL_ADDRESS Addr, + IN UINTN Size + ) +{ + UINTN Index; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Desc; + + for (Index = 0; Index < mNumberOfDescriptors; Index ++) { + Desc = &mGcdMemSpace[Index]; + if ((Desc->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) && (Addr >= Desc->BaseAddress) && ((Addr + Size) <= (Desc->BaseAddress + Desc->Length))) { + return TRUE; + } + } + + return FALSE; +} /** Get AHCI mode base address registers' Value. @@ -1055,7 +1083,7 @@ GetAhciBaseAddress ( // // Check if the AHCI Bar region is in SMRAM to avoid malicious attack by modifying MMIO Bar to point to SMRAM. // - if (!SmmIsBufferOutsideSmmValid ((EFI_PHYSICAL_ADDRESS)mAhciBar, Size)) { + if (!OpalIsValidMmioSpace ((EFI_PHYSICAL_ADDRESS)mAhciBar, Size)) { return EFI_UNSUPPORTED; }