]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add a check for metadata size in NvmExpress Driver
authorMa, Hua <Hua.Ma@intel.com>
Thu, 3 Mar 2022 05:06:04 +0000 (13:06 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 7 Mar 2022 01:55:41 +0000 (01:55 +0000)
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3856

Currently this NvmeExpress Driver do not support metadata handling.
According to the NVME specs, metadata may be transferred to the host after
the logical block data. It can overrun the input buffer which may only
be the size of logical block data.

Add a check to return not support for the namespaces formatted with
metadata.

v2 changes:
 - Change debug log level from INFO to ERROR
 - Change to if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0)

v1: https://edk2.groups.io/g/devel/message/87242

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Hua Ma <hua.ma@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c

index 5a1eda8e8ded0bf749e84687b636d10a03e22835..dea14f1a446cc6aee8953dca83e29b65a4c52678 100644 (file)
@@ -137,8 +137,23 @@ EnumerateNvmeDevNamespace (
     Device->Media.WriteCaching     = FALSE;\r
     Device->Media.IoAlign          = Private->PassThruMode.IoAlign;\r
 \r
     Device->Media.WriteCaching     = FALSE;\r
     Device->Media.IoAlign          = Private->PassThruMode.IoAlign;\r
 \r
-    Flbas                   = NamespaceData->Flbas;\r
-    LbaFmtIdx               = Flbas & 0xF;\r
+    Flbas     = NamespaceData->Flbas;\r
+    LbaFmtIdx = Flbas & 0xF;\r
+\r
+    //\r
+    // Currently this NVME driver only suport Metadata Size == 0\r
+    //\r
+    if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {\r
+      DEBUG ((\r
+        DEBUG_ERROR,\r
+        "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",\r
+        NamespaceId,\r
+        NamespaceData->LbaFormat[LbaFmtIdx].Ms\r
+        ));\r
+      Status = EFI_UNSUPPORTED;\r
+      goto Exit;\r
+    }\r
+\r
     Lbads                   = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;\r
     Device->Media.BlockSize = (UINT32)1 << Lbads;\r
 \r
     Lbads                   = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;\r
     Device->Media.BlockSize = (UINT32)1 << Lbads;\r
 \r
index f73053fc3feb53f760da2bacb7b786842658684a..2d6a79028fcd7552689fa2fa0662bb55238d1bb7 100644 (file)
@@ -104,7 +104,22 @@ EnumerateNvmeDevNamespace (
   //\r
   Flbas     = NamespaceData->Flbas;\r
   LbaFmtIdx = Flbas & 0xF;\r
   //\r
   Flbas     = NamespaceData->Flbas;\r
   LbaFmtIdx = Flbas & 0xF;\r
-  Lbads     = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;\r
+\r
+  //\r
+  // Currently this NVME driver only suport Metadata Size == 0\r
+  //\r
+  if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",\r
+      NamespaceId,\r
+      NamespaceData->LbaFormat[LbaFmtIdx].Ms\r
+      ));\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Exit;\r
+  }\r
+\r
+  Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;\r
 \r
   NamespaceInfo->Media.InterfaceType  = MSG_NVME_NAMESPACE_DP;\r
   NamespaceInfo->Media.RemovableMedia = FALSE;\r
 \r
   NamespaceInfo->Media.InterfaceType  = MSG_NVME_NAMESPACE_DP;\r
   NamespaceInfo->Media.RemovableMedia = FALSE;\r