2 This driver produces Security2 and Security architectural protocol based on SecurityManagementLib.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Protocol/Security.h>
12 #include <Protocol/Security2.h>
13 #include <Library/DebugLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/UefiDriverEntryPoint.h>
16 #include <Library/SecurityManagementLib.h>
17 #include "Defer3rdPartyImageLoad.h"
20 // Handle for the Security Architectural Protocol instance produced by this driver
22 EFI_HANDLE mSecurityArchProtocolHandle
= NULL
;
25 The EFI_SECURITY_ARCH_PROTOCOL (SAP) is used to abstract platform-specific
26 policy from the DXE core response to an attempt to use a file that returns a
27 given status for the authentication check from the section extraction protocol.
29 The possible responses in a given SAP implementation may include locking
30 flash upon failure to authenticate, attestation logging for all signed drivers,
31 and other exception operations. The File parameter allows for possible logging
32 within the SAP of the driver.
34 If File is NULL, then EFI_INVALID_PARAMETER is returned.
36 If the file specified by File with an authentication status specified by
37 AuthenticationStatus is safe for the DXE Core to use, then EFI_SUCCESS is returned.
39 If the file specified by File with an authentication status specified by
40 AuthenticationStatus is not safe for the DXE Core to use under any circumstances,
41 then EFI_ACCESS_DENIED is returned.
43 If the file specified by File with an authentication status specified by
44 AuthenticationStatus is not safe for the DXE Core to use right now, but it
45 might be possible to use it at a future time, then EFI_SECURITY_VIOLATION is
48 @param This The EFI_SECURITY_ARCH_PROTOCOL instance.
49 @param AuthenticationStatus
50 This is the authentication type returned from the Section
51 Extraction protocol. See the Section Extraction Protocol
52 Specification for details on this type.
53 @param File This is a pointer to the device path of the file that is
54 being dispatched. This will optionally be used for logging.
56 @retval EFI_SUCCESS Do nothing and return success.
57 @retval EFI_INVALID_PARAMETER File is NULL.
61 SecurityStubAuthenticateState (
62 IN CONST EFI_SECURITY_ARCH_PROTOCOL
*This
,
63 IN UINT32 AuthenticationStatus
,
64 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File
69 Status
= ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_AUTHENTICATION_STATE
,
76 if (Status
== EFI_SUCCESS
) {
77 Status
= ExecuteSecurityHandlers (AuthenticationStatus
, File
);
84 The DXE Foundation uses this service to measure and/or verify a UEFI image.
86 This service abstracts the invocation of Trusted Computing Group (TCG) measured boot, UEFI
87 Secure boot, and UEFI User Identity infrastructure. For the former two, the DXE Foundation
88 invokes the FileAuthentication() with a DevicePath and corresponding image in
89 FileBuffer memory. The TCG measurement code will record the FileBuffer contents into the
90 appropriate PCR. The image verification logic will confirm the integrity and provenance of the
91 image in FileBuffer of length FileSize . The origin of the image will be DevicePath in
93 If the FileBuffer is NULL, the interface will determine if the DevicePath can be connected
94 in order to support the User Identification policy.
96 @param This The EFI_SECURITY2_ARCH_PROTOCOL instance.
97 @param File A pointer to the device path of the file that is
98 being dispatched. This will optionally be used for logging.
99 @param FileBuffer A pointer to the buffer with the UEFI file image.
100 @param FileSize The size of the file.
101 @param BootPolicy A boot policy that was used to call LoadImage() UEFI service. If
102 FileAuthentication() is invoked not from the LoadImage(),
103 BootPolicy must be set to FALSE.
105 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL
106 FileBuffer did authenticate, and the platform policy dictates
107 that the DXE Foundation may use the file.
108 @retval EFI_SUCCESS The device path specified by NULL device path DevicePath
109 and non-NULL FileBuffer did authenticate, and the platform
110 policy dictates that the DXE Foundation may execute the image in
112 @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start
113 UEFI device drivers on the device path specified by DevicePath.
114 @retval EFI_SECURITY_VIOLATION The file specified by DevicePath and FileBuffer did not
115 authenticate, and the platform policy dictates that the file should be
116 placed in the untrusted state. The image has been added to the file
118 @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not
119 authenticate, and the platform policy dictates that the DXE
120 Foundation many not use File.
121 @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no
122 permission to start UEFI device drivers on the device path specified
124 @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load
125 drivers from the device path specified by DevicePath. The
126 image has been added into the list of the deferred images.
130 Security2StubAuthenticate (
131 IN CONST EFI_SECURITY2_ARCH_PROTOCOL
*This
,
132 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File OPTIONAL
,
135 IN BOOLEAN BootPolicy
140 if (FileBuffer
!= NULL
) {
141 Status
= Defer3rdPartyImageLoad (File
, BootPolicy
);
142 if (EFI_ERROR (Status
)) {
147 return ExecuteSecurity2Handlers (EFI_AUTH_OPERATION_VERIFY_IMAGE
|
148 EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD
|
149 EFI_AUTH_OPERATION_MEASURE_IMAGE
|
150 EFI_AUTH_OPERATION_CONNECT_POLICY
,
160 // Security2 and Security Architectural Protocol instance produced by this driver
162 EFI_SECURITY_ARCH_PROTOCOL mSecurityStub
= {
163 SecurityStubAuthenticateState
166 EFI_SECURITY2_ARCH_PROTOCOL mSecurity2Stub
= {
167 Security2StubAuthenticate
171 Installs Security2 and Security Architectural Protocol.
173 @param ImageHandle The image handle of this driver.
174 @param SystemTable A pointer to the EFI System Table.
176 @retval EFI_SUCCESS Install the sample Security Architectural Protocol successfully.
181 SecurityStubInitialize (
182 IN EFI_HANDLE ImageHandle
,
183 IN EFI_SYSTEM_TABLE
*SystemTable
189 // Make sure the Security Architectural Protocol is not already installed in the system
191 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiSecurity2ArchProtocolGuid
);
192 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiSecurityArchProtocolGuid
);
195 // Install the Security Architectural Protocol onto a new handle
197 Status
= gBS
->InstallMultipleProtocolInterfaces (
198 &mSecurityArchProtocolHandle
,
199 &gEfiSecurity2ArchProtocolGuid
,
201 &gEfiSecurityArchProtocolGuid
,
205 ASSERT_EFI_ERROR (Status
);
207 Defer3rdPartyImageLoadInitialize ();