From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com []) by mx.groups.io with SMTP id smtpd.web09.3729.1578020675360032184 for ; Thu, 02 Jan 2020 19:04:44 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhichao.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 19:04:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,389,1571727600"; d="scan'208";a="252455138" Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga002.fm.intel.com with ESMTP; 02 Jan 2020 19:04:43 -0800 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang Subject: [PATCH 08/13] SecurityPkg/TcgPyhsicalPresenceLib: Use Pcd for user resp wait time Date: Fri, 3 Jan 2020 11:04:22 +0800 Message-Id: <20200103030428.28176-9-zhichao.gao@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200103030428.28176-1-zhichao.gao@intel.com> References: <20200103030428.28176-1-zhichao.gao@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2443 Use the pcd PcdPhysicalPresenceUserConfirmTimeout to control the wait time of user response. Cc: Jiewen Yao Cc: Jian J Wang Cc: Chao Zhang Signed-off-by: Zhichao Gao --- .../DxeTcgPhysicalPresenceLib.c | 76 ++++++++++++------- .../DxeTcgPhysicalPresenceLib.inf | 6 +- 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c index 174172d5d7..14423991f0 100644 --- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c +++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c @@ -8,7 +8,7 @@ ExecutePendingTpmRequest() will receive untrusted input and do validation. -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -29,6 +29,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include +#include #define CONFIRM_BUFFER_SIZE 4096 @@ -444,35 +446,57 @@ ReadUserKey ( { EFI_STATUS Status; EFI_INPUT_KEY Key; - UINT16 InputKey; - UINTN Index; + UINT16 ConfirmKey; + UINTN Interval; + INT64 Timeout; - InputKey = 0; - do { - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - if (Status == EFI_NOT_READY) { - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index); - continue; - } + // + // delay 100 milli-second + // + Interval = 100; + ConfirmKey = (CautionKey) ? SCAN_F12 : SCAN_F10; + Timeout = (INT64)PcdGet32 (PcdPhysicalPresenceUserConfirmTimeout); + if (Timeout > 0) { + Timeout = (INT64)MultU64x32 ((UINT64)Timeout, 1000); + } else { + // + // Wait forever + // + Timeout = MAX_INT64; + } - if (Status == EFI_DEVICE_ERROR) { - return FALSE; - } + // + // Wait for user response within the time-out + // + do { + MicroSecondDelay (Interval * 1000); + + Status = gBS->CheckEvent (gST->ConIn->WaitForKey); + if (!EFI_ERROR (Status)) { + Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + if (!EFI_ERROR (Status)) { + if (Key.ScanCode == ConfirmKey) { + // + // User Confirmation + // + return TRUE; + } - 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; + if (Key.ScanCode == SCAN_ESC) { + // + // User Rejection + // + return FALSE; + } + } else if (Status == EFI_DEVICE_ERROR) { + // + // If error, assume User Rejection + // + return FALSE; + } } - } while (InputKey == 0); - - if (InputKey != SCAN_ESC) { - return TRUE; - } + Timeout -= Interval; + } while (Timeout > 0); return FALSE; } diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf index cfe14f20ca..13b7246290 100644 --- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf +++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf @@ -9,7 +9,7 @@ # This driver will have external input - variable. # This external input must be validated carefully to avoid security issue. # -# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -50,11 +50,15 @@ PrintLib HiiLib TcgPpVendorLib + TimerLib [Protocols] gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES +[Pcd] + gEfiSecurityPkgTokenSpaceGuid.PcdPhysicalPresenceUserConfirmTimeout + [Guids] ## SOMETIMES_CONSUMES ## HII ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence" -- 2.21.0.windows.1