From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.7658.1646283982746486166 for ; Wed, 02 Mar 2022 21:06:23 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=mU3y/FSp; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: hua.ma@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1646283982; x=1677819982; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=3b3VfU8/z2Vk2G9nR3F+h772vuN8S3WUesu+fl3j9bQ=; b=mU3y/FSpYwWvHM2gJN01ywQVS1U2p1uyFIYdjtW1M6qyNnfw9GEZ3tUu RhqPOZmC+43tlJi0i7Ox758fGPTBWXmEJqjtGZMxNmgtVM20LjvB7NMiT CC7C61m6uWk1LRVdCC/S/ol32HnlCpMJD5cWCTqD7Ta3YIWRZjAMnIUY0 R3YGK4GisTKBpVSknDatEnUIcpw9GqksE+QlOGzUc0TPBPYoIIeKbficB OI+5ISFW7nuH7AMqZpP33UuylGlZMt4C3X5OhFyRrRYp1gO43icDcewsx 6RJM0k5B3AZkdUXbyDxEZJFjc+89oQ39Pj9JmRixV56G2WgZnCHp2oKLt w==; X-IronPort-AV: E=McAfee;i="6200,9189,10274"; a="253510256" X-IronPort-AV: E=Sophos;i="5.90,151,1643702400"; d="scan'208";a="253510256" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 21:06:21 -0800 X-IronPort-AV: E=Sophos;i="5.90,151,1643702400"; d="scan'208";a="535675136" Received: from huama-mobl.ccr.corp.intel.com ([10.239.37.125]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2022 21:06:19 -0800 From: "Ma, Hua" To: devel@edk2.groups.io Cc: jian.j.wang@intel.com, gaoliming@byosoft.com.cn, hao.a.wu@intel.com, ray.ni@intel.com, Hua Ma Subject: [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver Date: Thu, 3 Mar 2022 13:06:04 +0800 Message-Id: <71f2bca338cef51bf250616c684f2b8bab8694f5.1646276422.git.hua.ma@intel.com> X-Mailer: git-send-email 2.32.0.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Hua Ma --- MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c | 15 +++++++++++++++ .../Bus/Pci/NvmExpressPei/NvmExpressPei.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c index 5a1eda8e8d..388583e4d5 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c @@ -139,6 +139,21 @@ EnumerateNvmeDevNamespace ( Flbas = NamespaceData->Flbas; LbaFmtIdx = Flbas & 0xF; + + // + // Currently this NVME driver only suport Metadata Size == 0 + // + if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) { + DEBUG (( + DEBUG_ERROR, + "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n", + NamespaceId, + NamespaceData->LbaFormat[LbaFmtIdx].Ms + )); + Status = EFI_UNSUPPORTED; + goto Exit; + } + Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads; Device->Media.BlockSize = (UINT32)1 << Lbads; diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c index f73053fc3f..e8a29f23c7 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c @@ -104,6 +104,21 @@ EnumerateNvmeDevNamespace ( // Flbas = NamespaceData->Flbas; LbaFmtIdx = Flbas & 0xF; + + // + // Currently this NVME driver only suport Metadata Size == 0 + // + if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) { + DEBUG (( + DEBUG_ERROR, + "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n", + NamespaceId, + NamespaceData->LbaFormat[LbaFmtIdx].Ms + )); + Status = EFI_UNSUPPORTED; + goto Exit; + } + Lbads = NamespaceData->LbaFormat[LbaFmtIdx].Lbads; NamespaceInfo->Media.InterfaceType = MSG_NVME_NAMESPACE_DP; -- 2.32.0.windows.2