From 491f6026293bef88ea31b3d1848300708253f68b Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Mon, 22 Aug 2016 14:11:23 +0800 Subject: [PATCH] MdeModulePkg NvmExpressDxe: Add check on the attributes of NVME controller According to UEFI spec, an EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL with neither EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL nor EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL set in the Attributes field is an illegal configuration. This commit adds this check in the PassThru API to follow the spec. Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Feng Tian --- .../Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c index 6b29260858..c7ead2114f 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c @@ -375,6 +375,7 @@ NvmExpressPassThru ( UINT64 *Prp; VOID *PrpListHost; UINTN PrpListNo; + UINT32 Attributes; UINT32 IoAlign; UINT32 Data; NVME_PASS_THRU_ASYNC_REQ *AsyncRequest; @@ -395,10 +396,21 @@ NvmExpressPassThru ( return EFI_INVALID_PARAMETER; } + // + // 'Attributes' with neither EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL nor + // EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL set is an illegal + // configuration. + // + Attributes = This->Mode->Attributes; + if ((Attributes & (EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL | + EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL)) == 0) { + return EFI_INVALID_PARAMETER; + } + // // Buffer alignment check for TransferBuffer & MetadataBuffer. // - IoAlign = This->Mode->IoAlign; + IoAlign = This->Mode->IoAlign; if (IoAlign > 0 && (((UINTN) Packet->TransferBuffer & (IoAlign - 1)) != 0)) { return EFI_INVALID_PARAMETER; } -- 2.39.2