Revision: 13927
          http://edk2.svn.sourceforge.net/edk2/?rev=13927&view=rev
Author:   vanjeff
Date:     2012-11-05 03:07:53 +0000 (Mon, 05 Nov 2012)
Log Message:
-----------
Sync patches r13908 and r13926 from main trunk.
Add Physical Presence request UI detection logic. Refine UIConfirm ReadKey 
logic.

Revision Links:
--------------
    http://edk2.svn.sourceforge.net/edk2/?rev=13908&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=13926&view=rev

Modified Paths:
--------------
    branches/UDK2010.SR1/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h
    
branches/UDK2010.SR1/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c

Modified: 
branches/UDK2010.SR1/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h
===================================================================
--- branches/UDK2010.SR1/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h   
2012-11-05 02:52:13 UTC (rev 13926)
+++ branches/UDK2010.SR1/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h   
2012-11-05 03:07:53 UTC (rev 13927)
@@ -2,7 +2,7 @@
   Ihis library is intended to be used by BDS modules.
   This library will lock TPM after executing TPM request.
 
-Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials 
 are licensed and made available under the terms and conditions of the BSD 
License 
 which accompanies this distribution.  The full text of the license may be 
found at 
@@ -35,4 +35,20 @@
   VOID
   );
 
+/**
+  Check if the pending TPM request needs user input to confirm.
+
+  The TPM request may come from OS. This API will check if TPM request exists 
and need user
+  input to confirmation.
+  
+  @retval    TRUE        TPM needs input to confirm user physical presence.
+  @retval    FALSE       TPM doesn't need input to confirm user physical 
presence.
+
+**/
+BOOLEAN
+EFIAPI
+TcgPhysicalPresenceLibNeedUserConfirm(
+  VOID
+  );
+
 #endif

Modified: 
branches/UDK2010.SR1/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
===================================================================
--- 
branches/UDK2010.SR1/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
      2012-11-05 02:52:13 UTC (rev 13926)
+++ 
branches/UDK2010.SR1/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
      2012-11-05 03:07:53 UTC (rev 13927)
@@ -440,7 +440,7 @@
                           If false, F10 is used as confirm key.
 
   @retval     TRUE        User confirmed the changes by input.
-  @retval     FALSE       User discarded the changes.
+  @retval     FALSE       User discarded the changes or device error.
 
 **/
 BOOLEAN
@@ -451,22 +451,29 @@
   EFI_STATUS                        Status;
   EFI_INPUT_KEY                     Key;
   UINT16                            InputKey;
-      
+  UINTN                             Index;
+
   InputKey = 0; 
   do {
-    Status = gBS->CheckEvent (gST->ConIn->WaitForKey);
-    if (!EFI_ERROR (Status)) {
-      Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
-      if (Key.ScanCode == SCAN_ESC) {
-        InputKey = Key.ScanCode;
-      }
-      if ((Key.ScanCode == SCAN_F10) && !CautionKey) {
-        InputKey = Key.ScanCode;
-      }
-      if ((Key.ScanCode == SCAN_F12) && CautionKey) {
-        InputKey = Key.ScanCode;
-      }
-    }      
+    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
+    if (Status == EFI_NOT_READY) {
+      gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
+      continue;
+    }
+
+    if (Status == EFI_DEVICE_ERROR) {
+      return FALSE;
+    }
+
+    if (Key.ScanCode == SCAN_ESC) {
+      InputKey = Key.ScanCode;
+    }
+    if ((Key.ScanCode == SCAN_F10) && !CautionKey) {
+      InputKey = Key.ScanCode;
+    }
+    if ((Key.ScanCode == SCAN_F12) && CautionKey) {
+      InputKey = Key.ScanCode;
+    }
   } while (InputKey == 0);
 
   if (InputKey != SCAN_ESC) {
@@ -886,32 +893,34 @@
 }
 
 /**
-  Check and execute the requested physical presence command.
+  Check if there is a valid physical presence command request. Also updates 
parameter value 
+  to whether the requested physical presence command already confirmed by user
+ 
+   @param[in]  TcgPpData                 EFI TCG Physical Presence request 
data. 
+   @param[out] RequestConfirmed            If the physical presence operation 
command required user confirm from UI.
+                                             True, it indicates the command 
doesn't require user confirm, or already confirmed 
+                                                   in last boot cycle by user.
+                                             False, it indicates the command 
need user confirm from UI.
 
-  Caution: This function may receive untrusted input.
-  TcgPpData variable is external input, so this function will validate
-  its data structure to be valid value.
+   @retval  TRUE        Physical Presence operation command is valid.
+   @retval  FALSE       Physical Presence operation command is invalid.
 
-  @param[in] TcgProtocol          EFI TCG Protocol instance. 
-  @param[in] TcgPpData            Point to the physical presence NV variable.
-
 **/
-VOID
-ExecutePendingTpmRequest (
-  IN      EFI_TCG_PROTOCOL          *TcgProtocol,
-  IN      EFI_PHYSICAL_PRESENCE     *TcgPpData
+BOOLEAN
+HaveValidTpmRequest  (
+  IN      EFI_PHYSICAL_PRESENCE     *TcgPpData,
+  OUT     BOOLEAN                   *RequestConfirmed
   )
 {
-  EFI_STATUS                        Status;
-  UINTN                             DataSize;
   UINT8                             Flags;
-  BOOLEAN                           RequestConfirmed;
+  
+  Flags = TcgPpData->Flags;
+  *RequestConfirmed = FALSE;
 
-  Flags            = TcgPpData->Flags;
-  RequestConfirmed = FALSE;  
   switch (TcgPpData->PPRequest) {
     case PHYSICAL_PRESENCE_NO_ACTION:
-      return;
+      *RequestConfirmed = TRUE;
+      return TRUE;
     case PHYSICAL_PRESENCE_ENABLE:
     case PHYSICAL_PRESENCE_DISABLE:
     case PHYSICAL_PRESENCE_ACTIVATE:
@@ -924,66 +933,108 @@
     case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:
     case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:
       if ((Flags & FLAG_NO_PPI_PROVISION) != 0) {
-        RequestConfirmed = TRUE;
+        *RequestConfirmed = TRUE;
       }
       break;
 
     case PHYSICAL_PRESENCE_CLEAR:
     case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:
       if ((Flags & FLAG_NO_PPI_CLEAR) != 0) {
-        RequestConfirmed = TRUE;
+        *RequestConfirmed = TRUE;
       }
       break;
 
     case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:
       if ((Flags & FLAG_NO_PPI_MAINTENANCE) != 0) {
-        RequestConfirmed = TRUE;
+        *RequestConfirmed = TRUE;
       }
       break;
 
     case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:
     case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
       if ((Flags & FLAG_NO_PPI_CLEAR) != 0 && (Flags & FLAG_NO_PPI_PROVISION) 
!= 0) {
-        RequestConfirmed = TRUE;
+        *RequestConfirmed = TRUE;
       }
-      break;  
+      break;
 
     case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:
     case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:
     case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:
-      RequestConfirmed = TRUE;
+      *RequestConfirmed = TRUE;
       break;
-      
+
     case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:
     case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:
     case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:
       break;
-      
+
     default:
       //
-      // Invalid operation request.
+      // Wrong Physical Presence command
       //
-      TcgPpData->PPResponse = TPM_PP_BIOS_FAILURE;
-      TcgPpData->LastPPRequest = TcgPpData->PPRequest;
-      TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
-      DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
-      Status = gRT->SetVariable (
-                      PHYSICAL_PRESENCE_VARIABLE,
-                      &gEfiPhysicalPresenceGuid,
-                      EFI_VARIABLE_NON_VOLATILE | 
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-                      DataSize,
-                      TcgPpData
-                      );
-      return;
+      return FALSE;
   }
 
   if ((Flags & FLAG_RESET_TRACK) != 0) {
     //
     // It had been confirmed in last boot, it doesn't need confirm again.
     //
-    RequestConfirmed = TRUE;
+    *RequestConfirmed = TRUE;
   }
 
+  //
+  // Physical Presence command is correct
+  //
+  return TRUE;
+}
+
+
+/**
+  Check and execute the requested physical presence command.
+
+  Caution: This function may receive untrusted input.
+  TcgPpData variable is external input, so this function will validate
+  its data structure to be valid value.
+
+  @param[in] TcgProtocol          EFI TCG Protocol instance. 
+  @param[in] TcgPpData            Point to the physical presence NV variable.
+
+**/
+VOID
+ExecutePendingTpmRequest (
+  IN      EFI_TCG_PROTOCOL          *TcgProtocol,
+  IN      EFI_PHYSICAL_PRESENCE     *TcgPpData
+  )
+{
+  EFI_STATUS                        Status;
+  UINTN                             DataSize;
+  BOOLEAN                           RequestConfirmed;
+
+  if (TcgPpData->PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
+    //
+    // No operation request
+    //
+    return;
+  }
+
+  if (!HaveValidTpmRequest(TcgPpData, &RequestConfirmed)) {
+    //
+    // Invalid operation request.
+    //
+    TcgPpData->PPResponse = TPM_PP_BIOS_FAILURE;
+    TcgPpData->LastPPRequest = TcgPpData->PPRequest;
+    TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
+    DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
+    Status = gRT->SetVariable (
+                    PHYSICAL_PRESENCE_VARIABLE,
+                    &gEfiPhysicalPresenceGuid,
+                    EFI_VARIABLE_NON_VOLATILE | 
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+                    DataSize,
+                    TcgPpData
+                    );
+    return;
+  }
+
   if (!RequestConfirmed) {
     //
     // Print confirm text and wait for approval. 
@@ -1149,3 +1200,88 @@
   TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | 
TPM_PHYSICAL_PRESENCE_LOCK);
 }
 
+/**
+  Check if the pending TPM request needs user input to confirm.
+
+  The TPM request may come from OS. This API will check if TPM request exists 
and need user
+  input to confirmation.
+  
+  @retval    TRUE        TPM needs input to confirm user physical presence.
+  @retval    FALSE       TPM doesn't need input to confirm user physical 
presence.
+
+**/
+BOOLEAN
+EFIAPI
+TcgPhysicalPresenceLibNeedUserConfirm(
+  VOID
+  )
+{
+  EFI_STATUS              Status;
+  EFI_PHYSICAL_PRESENCE   TcgPpData;
+  UINTN                   DataSize;
+  BOOLEAN                 RequestConfirmed;
+  BOOLEAN                 LifetimeLock;
+  BOOLEAN                 CmdEnable;
+  EFI_TCG_PROTOCOL        *TcgProtocol;
+
+  Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID 
**)&TcgProtocol);
+  if (EFI_ERROR (Status)) {
+    return FALSE;
+  }
+
+  //
+  // Check Tpm requests
+  //
+  DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
+  Status = gRT->GetVariable (
+                  PHYSICAL_PRESENCE_VARIABLE,
+                  &gEfiPhysicalPresenceGuid,
+                  NULL,
+                  &DataSize,
+                  &TcgPpData
+                  );
+  if (EFI_ERROR (Status)) {
+    return FALSE;
+  }
+
+  if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
+    //
+    // No operation request
+    //
+    return FALSE;
+  }
+
+  if (!HaveValidTpmRequest(&TcgPpData, &RequestConfirmed)) {
+    //
+    // Invalid operation request.
+    //
+    return FALSE;
+  }
+
+  //
+  // Check Tpm Capability
+  //
+  Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);
+  if (EFI_ERROR (Status)) {
+    return FALSE;
+  }
+
+  if (!CmdEnable) {
+    if (LifetimeLock) {
+      //
+      // physicalPresenceCMDEnable is locked, can't execute physical presence 
command.
+      //
+      return FALSE;
+    }
+  }
+
+  if (!RequestConfirmed) {
+    //
+    // Need UI to confirm
+    //
+    return TRUE;
+  }
+
+  return FALSE;
+}
+

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to