]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SecurityPkg/TcgMor: move TPer Reset operation to this module
authorTian Feng <feng.tian@intel.com>
Fri, 26 Jun 2015 08:42:46 +0000 (08:42 +0000)
committererictian <erictian@Edk2>
Fri, 26 Jun 2015 08:42:46 +0000 (08:42 +0000)
The TPer Reset operation is a common logic. So it's added into
SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf module and
would be triggered at EndOfDxe.

By this way, all encrypted drives which produce EFI_STORAGE_SECURITY_
RPOTOCOL interface would be force reset when MOR is set.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Tian Feng <feng.tian@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17718 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.c
SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.h
SecurityPkg/Tcg/MemoryOverwriteControl/TcgMor.inf

index a4acc14e9a883f669d322237283a287984e2af84..e691a084d0edd5f952c3b056a3717317fc9e0197 100644 (file)
@@ -2,9 +2,10 @@
   TCG MOR (Memory Overwrite Request) Control Driver.\r
 \r
   This driver initilize MemoryOverwriteRequestControl variable. It \r
-  will clear MOR_CLEAR_MEMORY_BIT bit if it is set.\r
+  will clear MOR_CLEAR_MEMORY_BIT bit if it is set. It will also do TPer Reset for\r
+  those encrypted drives through EFI_STORAGE_SECURITY_COMMAND_PROTOCOL at EndOfDxe.\r
 \r
-Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -63,6 +64,242 @@ OnReadyToBoot (
   }\r
 }\r
 \r
+/**\r
+  Send TPer Reset command to reset eDrive to lock all protected bands.\r
+  Typically, there are 2 mechanism for resetting eDrive. They are:\r
+  1. TPer Reset through IEEE 1667 protocol.\r
+  2. TPer Reset through native TCG protocol.\r
+  This routine will detect what protocol the attached eDrive comform to, TCG or\r
+  IEEE 1667 protocol. Then send out TPer Reset command separately.\r
+\r
+  @param[in] Ssp      The pointer to EFI_STORAGE_SECURITY_COMMAND_PROTOCOL instance.\r
+  @param[in] MediaId  ID of the medium to receive data from or send data to.\r
+\r
+**/\r
+VOID\r
+InitiateTPerReset (\r
+  IN  EFI_STORAGE_SECURITY_COMMAND_PROTOCOL    *Ssp,\r
+  IN  UINT32                                   MediaId\r
+  )\r
+{\r
+\r
+  EFI_STATUS                                   Status;\r
+  UINT8                                        *Buffer;\r
+  UINTN                                        XferSize;\r
+  UINTN                                        Len;\r
+  UINTN                                        Index;\r
+  BOOLEAN                                      TcgFlag;\r
+  BOOLEAN                                      IeeeFlag;\r
+  SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA  *Data;\r
+\r
+  Buffer        = NULL;\r
+  TcgFlag       = FALSE;\r
+  IeeeFlag      = FALSE;\r
+\r
+  //\r
+  // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.\r
+  // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,\r
+  // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.\r
+  //\r
+  Len           = ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA));\r
+  Buffer        = AllocateZeroPool(Len);\r
+\r
+  if (Buffer == NULL) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE\r
+  // command, the device basic information data shall be returned.\r
+  //\r
+  Status = Ssp->ReceiveData (\r
+                  Ssp,\r
+                  MediaId,\r
+                  100000000,                    // Timeout 10-sec\r
+                  0,                            // SecurityProtocol\r
+                  0,                            // SecurityProtocolSpecifcData\r
+                  Len,                          // PayloadBufferSize,\r
+                  Buffer,                       // PayloadBuffer\r
+                  &XferSize\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // In returned data, the ListLength field indicates the total length, in bytes,\r
+  // of the supported security protocol list.\r
+  //\r
+  Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r
+  Len  = ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA) +\r
+                    (Data->SupportedSecurityListLength[0] << 8) +\r
+                    (Data->SupportedSecurityListLength[1])\r
+                    );\r
+\r
+  //\r
+  // Free original buffer and allocate new buffer.\r
+  //\r
+  FreePool(Buffer);\r
+  Buffer = AllocateZeroPool(Len);\r
+  if (Buffer == NULL) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Read full supported security protocol list from device.\r
+  //\r
+  Status = Ssp->ReceiveData (\r
+                  Ssp,\r
+                  MediaId,\r
+                  100000000,                    // Timeout 10-sec\r
+                  0,                            // SecurityProtocol\r
+                  0,                            // SecurityProtocolSpecifcData\r
+                  Len,                          // PayloadBufferSize,\r
+                  Buffer,                       // PayloadBuffer\r
+                  &XferSize\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Exit;\r
+  }\r
+\r
+  Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r
+  Len  = (Data->SupportedSecurityListLength[0] << 8) + Data->SupportedSecurityListLength[1];\r
+\r
+  //\r
+  // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol\r
+  // is supported.\r
+  //\r
+  for (Index = 0; Index < Len; Index++) {\r
+    if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_TCG) {\r
+      //\r
+      // Found a  TCG device.\r
+      //\r
+      TcgFlag = TRUE;\r
+      DEBUG ((EFI_D_INFO, "This device is a TCG protocol device\n"));\r
+      break;\r
+    }\r
+\r
+    if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_IEEE1667) {\r
+      //\r
+      // Found a IEEE 1667 device.\r
+      //\r
+      IeeeFlag = TRUE;\r
+      DEBUG ((EFI_D_INFO, "This device is a IEEE 1667 protocol device\n"));\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (!TcgFlag && !IeeeFlag) {\r
+    DEBUG ((EFI_D_INFO, "Neither a TCG nor IEEE 1667 protocol device is found\n"));\r
+    goto Exit;\r
+  }\r
+\r
+  if (TcgFlag) {\r
+    //\r
+    // As long as TCG protocol is supported, send out a TPer Reset\r
+    // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.\r
+    //\r
+    Status = Ssp->SendData (\r
+                    Ssp,\r
+                    MediaId,\r
+                    100000000,                    // Timeout 10-sec\r
+                    SECURITY_PROTOCOL_TCG,        // SecurityProtocol\r
+                    0x0400,                       // SecurityProtocolSpecifcData\r
+                    512,                          // PayloadBufferSize,\r
+                    Buffer                        // PayloadBuffer\r
+                    );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_INFO, "Send TPer Reset Command Successfully !\n"));\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, "Send TPer Reset Command Fail !\n"));\r
+    }\r
+  }\r
+\r
+  if (IeeeFlag) {\r
+    //\r
+    // TBD : Perform a TPer Reset via IEEE 1667 Protocol\r
+    //\r
+    DEBUG ((EFI_D_INFO, "IEEE 1667 Protocol didn't support yet!\n"));\r
+  }\r
+\r
+Exit:\r
+\r
+  if (Buffer != NULL) {\r
+    FreePool(Buffer);\r
+  }\r
+}\r
+\r
+/**\r
+  Notification function of END_OF_DXE.\r
+\r
+  This is a notification function registered on END_OF_DXE event.\r
+  It is to get VarCheckPcdBin.\r
+\r
+  @param[in] Event      Event whose notification function is being invoked.\r
+  @param[in] Context    Pointer to the notification function's context.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+TPerResetAtEndOfDxe (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  EFI_STORAGE_SECURITY_COMMAND_PROTOCOL   *Ssp;\r
+  EFI_BLOCK_IO_PROTOCOL                   *BlockIo;\r
+  EFI_STATUS                              Status;\r
+  UINTN                                   HandleCount;\r
+  EFI_HANDLE                              *HandleBuffer;\r
+  UINTN                                   Index;\r
+\r
+  //\r
+  // Locate all SSP protocol instances.\r
+  //\r
+  HandleCount  = 0;\r
+  HandleBuffer = NULL;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiStorageSecurityCommandProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
+\r
+  if (EFI_ERROR (Status) || (HandleCount == 0) || (HandleBuffer == NULL)) {\r
+    return;\r
+  }\r
+\r
+  for (Index = 0; Index < HandleCount; Index ++) {\r
+    //\r
+    // Get the SSP interface.\r
+    //\r
+    Status = gBS->HandleProtocol(\r
+                    HandleBuffer[Index],\r
+                    &gEfiStorageSecurityCommandProtocolGuid,\r
+                    (VOID **) &Ssp\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    Status = gBS->HandleProtocol(\r
+                    HandleBuffer[Index],\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    (VOID **) &BlockIo\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    InitiateTPerReset (Ssp, BlockIo->Media->MediaId);\r
+  }\r
+}\r
 \r
 /**\r
   Entry Point for TCG MOR Control driver.\r
@@ -120,8 +357,27 @@ MorDriverEntryPoint (
                NULL,\r
                &Event\r
                );\r
-  }    \r
-  \r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    //\r
+    // Register EFI_END_OF_DXE_EVENT_GROUP_GUID event.\r
+    //\r
+    DEBUG ((EFI_D_INFO, "TcgMor: Create EndofDxe Event for Mor TPer Reset!\n"));\r
+    Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    TPerResetAtEndOfDxe,\r
+                    NULL,\r
+                    &gEfiEndOfDxeEventGroupGuid,\r
+                    &Event\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
index 24ecdf6a0669a70090de958906590184cd11156b..a4aae48a5f2a920ff2a826fa7845a027a91a3793 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The header file for TcgMor.\r
 \r
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials \r
 are licensed and made available under the terms and conditions of the BSD License \r
 which accompanies this distribution.  The full text of the license may be found at \r
@@ -20,9 +20,29 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/MemoryOverwriteControl.h>\r
 \r
 #include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Protocol/StorageSecurityCommand.h>\r
+#include <Protocol/BlockIo.h>\r
+\r
+//\r
+// Supported Security Protocols List Description.\r
+// Refer to ATA8-ACS Spec 7.57.6.2 Table 69 or SPC4 7.7.1.3 Table 511.\r
+//\r
+typedef struct  {\r
+  UINT8                            Reserved1[6];\r
+  UINT8                            SupportedSecurityListLength[2];\r
+  UINT8                            SupportedSecurityProtocol[1];\r
+} SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA;\r
+\r
+#define SECURITY_PROTOCOL_TCG      0x02\r
+#define SECURITY_PROTOCOL_IEEE1667 0xEE\r
+\r
+#define ROUNDUP512(x) (((x) % 512 == 0) ? (x) : ((x) / 512 + 1) * 512)\r
 \r
 #endif\r
 \r
index 45cb31121a757fa9a6a2c24b37a7997e70a02eae..d5a7da83434237bdff9805c53448165d0cf20c56 100644 (file)
@@ -1,9 +1,11 @@
 ## @file\r
 #  Initilizes MemoryOverwriteRequestControl variable\r
 #\r
-#  This module will clear MOR_CLEAR_MEMORY_BIT bit if it is set.\r
+#  This module will clear MOR_CLEAR_MEMORY_BIT bit if it is set. It will also do\r
+#  TPer Reset for those encrypted drives through EFI_STORAGE_SECURITY_COMMAND_PROTOCOL\r
+#  at EndOfDxe.\r
 #\r
-# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution. The full text of the license may be found at\r
 \r
 [LibraryClasses]\r
   UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
   UefiRuntimeServicesTableLib\r
   ReportStatusCodeLib\r
   DebugLib\r
   UefiLib\r
+  MemoryAllocationLib\r
 \r
 [Guids]\r
   ## SOMETIMES_CONSUMES      ## Variable:L"MemoryOverwriteRequestControl"\r
   ## PRODUCES                ## Variable:L"MemoryOverwriteRequestControl"\r
   gEfiMemoryOverwriteControlDataGuid\r
+  gEfiEndOfDxeEventGroupGuid                  ## SOMETIMES_CONSUMES    ## Event\r
+\r
+[Protocols]\r
+  gEfiStorageSecurityCommandProtocolGuid      ## SOMETIMES_CONSUMES\r
+  gEfiBlockIoProtocolGuid                     ## SOMETIMES_CONSUMES\r
 \r
 [Depex]\r
   gEfiVariableArchProtocolGuid AND\r