2 Handle TPM 2.0 physical presence requests from OS.
4 This library will handle TPM 2.0 physical presence request from OS.
6 Caution: This module requires additional review when modified.
7 This driver will have external input - variable.
8 This external input must be validated carefully to avoid security issue.
10 Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
11 will receive untrusted input and do validation.
13 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
14 This program and the accompanying materials
15 are licensed and made available under the terms and conditions of the BSD License
16 which accompanies this distribution. The full text of the license may be found at
17 http://opensource.org/licenses/bsd-license.php
19 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
20 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include <Guid/Tcg2PhysicalPresenceData.h>
28 #include <Protocol/SmmVariable.h>
30 #include <Library/DebugLib.h>
31 #include <Library/Tcg2PpVendorLib.h>
32 #include <Library/SmmServicesTableLib.h>
34 EFI_SMM_VARIABLE_PROTOCOL
*mTcg2PpSmmVariable
;
37 The handler for TPM physical presence function:
38 Return TPM Operation Response to OS Environment.
40 This API should be invoked in OS runtime phase to interface with ACPI method.
42 @param[out] MostRecentRequest Most recent operation request.
43 @param[out] Response Response to the most recent operation request.
45 @return Return Code for Return TPM Operation Response to OS Environment.
49 Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
50 OUT UINT32
*MostRecentRequest
,
56 EFI_TCG2_PHYSICAL_PRESENCE PpData
;
58 DEBUG ((EFI_D_INFO
, "[TPM2] ReturnOperationResponseToOsFunction\n"));
61 // Get the Physical Presence variable
63 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE
);
64 Status
= mTcg2PpSmmVariable
->SmmGetVariable (
65 TCG2_PHYSICAL_PRESENCE_VARIABLE
,
66 &gEfiTcg2PhysicalPresenceGuid
,
71 if (EFI_ERROR (Status
)) {
72 *MostRecentRequest
= 0;
74 DEBUG ((EFI_D_ERROR
, "[TPM2] Get PP variable failure! Status = %r\n", Status
));
75 return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE
;
78 *MostRecentRequest
= PpData
.LastPPRequest
;
79 *Response
= PpData
.PPResponse
;
81 return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
;
85 The handler for TPM physical presence function:
86 Submit TPM Operation Request to Pre-OS Environment and
87 Submit TPM Operation Request to Pre-OS Environment 2.
89 This API should be invoked in OS runtime phase to interface with ACPI method.
91 Caution: This function may receive untrusted input.
93 @param[in] OperationRequest TPM physical presence operation request.
94 @param[in] RequestParameter TPM physical presence operation request parameter.
96 @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
97 Submit TPM Operation Request to Pre-OS Environment 2.
101 Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (
102 IN UINT32 OperationRequest
,
103 IN UINT32 RequestParameter
108 EFI_TCG2_PHYSICAL_PRESENCE PpData
;
109 EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags
;
111 DEBUG ((EFI_D_INFO
, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", OperationRequest
, RequestParameter
));
114 // Get the Physical Presence variable
116 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE
);
117 Status
= mTcg2PpSmmVariable
->SmmGetVariable (
118 TCG2_PHYSICAL_PRESENCE_VARIABLE
,
119 &gEfiTcg2PhysicalPresenceGuid
,
124 if (EFI_ERROR (Status
)) {
125 DEBUG ((EFI_D_ERROR
, "[TPM2] Get PP variable failure! Status = %r\n", Status
));
126 return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
;
129 if ((OperationRequest
> TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX
) &&
130 (OperationRequest
< TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) ) {
132 // This command requires UI to prompt user for Auth data.
134 return TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
;
137 if ((PpData
.PPRequest
!= OperationRequest
) ||
138 (PpData
.PPRequestParameter
!= RequestParameter
)) {
139 PpData
.PPRequest
= (UINT8
)OperationRequest
;
140 PpData
.PPRequestParameter
= RequestParameter
;
141 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE
);
142 Status
= mTcg2PpSmmVariable
->SmmSetVariable (
143 TCG2_PHYSICAL_PRESENCE_VARIABLE
,
144 &gEfiTcg2PhysicalPresenceGuid
,
145 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
151 if (EFI_ERROR (Status
)) {
152 DEBUG ((EFI_D_ERROR
, "[TPM2] Set PP variable failure! Status = %r\n", Status
));
153 return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
;
156 if (OperationRequest
>= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
157 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS
);
158 Status
= mTcg2PpSmmVariable
->SmmGetVariable (
159 TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
160 &gEfiTcg2PhysicalPresenceGuid
,
165 if (EFI_ERROR (Status
)) {
166 Flags
.PPFlags
= TCG2_BIOS_TPM_MANAGEMENT_FLAG_DEFAULT
;
168 return Tcg2PpVendorLibSubmitRequestToPreOSFunction (OperationRequest
, Flags
.PPFlags
, RequestParameter
);
171 return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
;
175 The handler for TPM physical presence function:
176 Get User Confirmation Status for Operation.
178 This API should be invoked in OS runtime phase to interface with ACPI method.
180 Caution: This function may receive untrusted input.
182 @param[in] OperationRequest TPM physical presence operation request.
184 @return Return Code for Get User Confirmation Status for Operation.
188 Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
189 IN UINT32 OperationRequest
194 EFI_TCG2_PHYSICAL_PRESENCE PpData
;
195 EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags
;
196 BOOLEAN RequestConfirmed
;
198 DEBUG ((EFI_D_INFO
, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest
));
201 // Get the Physical Presence variable
203 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE
);
204 Status
= mTcg2PpSmmVariable
->SmmGetVariable (
205 TCG2_PHYSICAL_PRESENCE_VARIABLE
,
206 &gEfiTcg2PhysicalPresenceGuid
,
211 if (EFI_ERROR (Status
)) {
212 DEBUG ((EFI_D_ERROR
, "[TPM2] Get PP variable failure! Status = %r\n", Status
));
213 return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION
;
216 // Get the Physical Presence flags
218 DataSize
= sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS
);
219 Status
= mTcg2PpSmmVariable
->SmmGetVariable (
220 TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE
,
221 &gEfiTcg2PhysicalPresenceGuid
,
226 if (EFI_ERROR (Status
)) {
227 DEBUG ((EFI_D_ERROR
, "[TPM2] Get PP flags failure! Status = %r\n", Status
));
228 return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION
;
231 RequestConfirmed
= FALSE
;
233 switch (OperationRequest
) {
234 case TCG2_PHYSICAL_PRESENCE_CLEAR
:
235 case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR
:
236 case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2
:
237 case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3
:
238 if ((Flags
.PPFlags
& TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CLEAR
) == 0) {
239 RequestConfirmed
= TRUE
;
243 case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE
:
244 RequestConfirmed
= TRUE
;
247 case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_FALSE
:
250 case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
:
251 if ((Flags
.PPFlags
& TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCRS
) == 0) {
252 RequestConfirmed
= TRUE
;
256 case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS
:
257 if ((Flags
.PPFlags
& TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS
) == 0) {
258 RequestConfirmed
= TRUE
;
262 case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS
:
263 RequestConfirmed
= TRUE
;
267 if (OperationRequest
<= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX
) {
268 RequestConfirmed
= TRUE
;
270 if (OperationRequest
< TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
271 return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED
;
277 if (OperationRequest
>= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION
) {
278 return Tcg2PpVendorLibGetUserConfirmationStatusFunction (OperationRequest
, Flags
.PPFlags
);
281 if (RequestConfirmed
) {
282 return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUIRED
;
284 return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED
;
289 The constructor function register UNI strings into imageHandle.
291 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
293 @param ImageHandle The firmware allocated handle for the EFI image.
294 @param SystemTable A pointer to the EFI System Table.
296 @retval EFI_SUCCESS The constructor successfully added string package.
297 @retval Other value The constructor can't add string package.
301 Tcg2PhysicalPresenceLibConstructor (
302 IN EFI_HANDLE ImageHandle
,
303 IN EFI_SYSTEM_TABLE
*SystemTable
309 // Locate SmmVariableProtocol.
311 Status
= gSmst
->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&mTcg2PpSmmVariable
);
312 ASSERT_EFI_ERROR (Status
);