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:42 -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:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,389,1571727600"; d="scan'208";a="252455113" Received: from fieedk001.ccr.corp.intel.com ([10.239.33.119]) by fmsmga002.fm.intel.com with ESMTP; 02 Jan 2020 19:04:40 -0800 From: "Gao, Zhichao" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefan Berger Subject: [PATCH 06/13] OvmfPkg/Tcg2PhysicalPresenceLib: Use pcd for user response wait time Date: Fri, 3 Jan 2020 11:04:20 +0800 Message-Id: <20200103030428.28176-7-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-Type: text/plain; charset=UTF-8 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 Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Marc-André Lureau Cc: Stefan Berger Signed-off-by: Zhichao Gao --- .../DxeTcg2PhysicalPresenceLib.c | 63 ++++++++++++++----- .../DxeTcg2PhysicalPresenceLib.inf | 6 +- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c index 00d76ba2c2..13f78cbfac 100644 --- a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c +++ b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c @@ -9,7 +9,7 @@ Copyright (C) 2018, Red Hat, Inc. Copyright (c) 2018, IBM Corporation. All rights reserved.
-Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -32,6 +32,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include +#include #include @@ -365,28 +367,57 @@ Tcg2ReadUserKey ( { EFI_STATUS Status; EFI_INPUT_KEY Key; - UINT16 InputKey; + UINT16 ConfirmKey; + UINTN Interval; + INT64 Timeout; - InputKey = 0; + // + // 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; + } + + // + // 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 (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 (!EFI_ERROR (Status)) { + if (Key.ScanCode == ConfirmKey) { + // + // User Confirmation + // + return TRUE; + } + + 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/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf index 85ce0e2b29..701de1836c 100644 --- a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf +++ b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf @@ -20,7 +20,7 @@ # This external input must be validated carefully to avoid security issue. # # Copyright (C) 2018, Red Hat, Inc. -# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2013 - 2020, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -62,10 +62,14 @@ UefiBootServicesTableLib UefiLib UefiRuntimeServicesTableLib + TimerLib [Protocols] gEfiTcg2ProtocolGuid ## SOMETIMES_CONSUMES +[Pcd] + gEfiSecurityPkgTokenSpaceGuid.PcdPhysicalPresenceUserConfirmTimeout + [Guids] ## SOMETIMES_CONSUMES ## HII gEfiTcg2PhysicalPresenceGuid -- 2.21.0.windows.1