]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/Security/Security.c
fd5cbc508c0604969b37adfb9229747526453951
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Security / Security.c
1 /** @file
2 EFI PEI Core Security services
3
4 Copyright (c) 2006 - 2010, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "PeiMain.h"
16
17
18 EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
19 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
20 &gEfiPeiSecurity2PpiGuid,
21 SecurityPpiNotifyCallback
22 };
23
24 /**
25 Initialize the security services.
26
27 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
28 @param OldCoreData Pointer to the old core data.
29 NULL if being run in non-permament memory mode.
30
31 **/
32 VOID
33 InitializeSecurityServices (
34 IN EFI_PEI_SERVICES **PeiServices,
35 IN PEI_CORE_INSTANCE *OldCoreData
36 )
37 {
38 if (OldCoreData == NULL) {
39 PeiServicesNotifyPpi (&mNotifyList);
40 }
41 return;
42 }
43
44 /**
45
46 Provide a callback for when the security PPI is installed.
47 This routine will cache installed security PPI into PeiCore's private data.
48
49 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
50 @param NotifyDescriptor The descriptor for the notification event.
51 @param Ppi Pointer to the PPI in question.
52
53 @return Always success
54
55 **/
56 EFI_STATUS
57 EFIAPI
58 SecurityPpiNotifyCallback (
59 IN EFI_PEI_SERVICES **PeiServices,
60 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
61 IN VOID *Ppi
62 )
63 {
64 PEI_CORE_INSTANCE *PrivateData;
65
66 //
67 // Get PEI Core private data
68 //
69 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
70
71 //
72 // If there isn't a security PPI installed, use the one from notification
73 //
74 if (PrivateData->PrivateSecurityPpi == NULL) {
75 PrivateData->PrivateSecurityPpi = (EFI_PEI_SECURITY2_PPI *)Ppi;
76 }
77 return EFI_SUCCESS;
78 }
79
80 /**
81
82 Provide a callout to the security verification service.
83
84
85 @param PrivateData PeiCore's private data structure
86 @param VolumeHandle Handle of FV
87 @param FileHandle Handle of PEIM's ffs
88
89 @retval EFI_SUCCESS Image is OK
90 @retval EFI_SECURITY_VIOLATION Image is illegal
91 @retval EFI_NOT_FOUND If security PPI is not installed.
92 **/
93 EFI_STATUS
94 VerifyPeim (
95 IN PEI_CORE_INSTANCE *PrivateData,
96 IN EFI_PEI_FV_HANDLE VolumeHandle,
97 IN EFI_PEI_FILE_HANDLE FileHandle
98 )
99 {
100 EFI_STATUS Status;
101 UINT32 AuthenticationStatus;
102 BOOLEAN DeferExection;
103
104 //
105 // Set a default authentication state
106 //
107 AuthenticationStatus = 0;
108
109 if (PrivateData->PrivateSecurityPpi == NULL) {
110 Status = EFI_NOT_FOUND;
111 } else {
112 //
113 // Check to see if the image is OK
114 //
115 Status = PrivateData->PrivateSecurityPpi->AuthenticationState (
116 (CONST EFI_PEI_SERVICES **) &PrivateData->Ps,
117 PrivateData->PrivateSecurityPpi,
118 AuthenticationStatus,
119 VolumeHandle,
120 FileHandle,
121 &DeferExection
122 );
123 if (DeferExection) {
124 Status = EFI_SECURITY_VIOLATION;
125 }
126 }
127 return Status;
128 }
129
130
131 /**
132 Verify a Firmware volume.
133
134 @param CurrentFvAddress Pointer to the current Firmware Volume under consideration
135
136 @retval EFI_SUCCESS Firmware Volume is legal
137
138 **/
139 EFI_STATUS
140 VerifyFv (
141 IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress
142 )
143 {
144 //
145 // Right now just pass the test. Future can authenticate and/or check the
146 // FV-header or other metric for goodness of binary.
147 //
148 return EFI_SUCCESS;
149 }