]>
Commit | Line | Data |
---|---|---|
cd98f305 LG |
1 | /** @file\r |
2 | Provides generic security measurement functions for DXE module.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
cd98f305 LG |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include <PiDxe.h>\r | |
2b75e8cd | 10 | #include <Protocol/LoadFile.h>\r |
cd98f305 LG |
11 | #include <Library/DebugLib.h>\r |
12 | #include <Library/DxeServicesLib.h>\r | |
13 | #include <Library/MemoryAllocationLib.h>\r | |
14 | #include <Library/SecurityManagementLib.h>\r | |
2b75e8cd LG |
15 | #include <Library/DevicePathLib.h>\r |
16 | #include <Library/UefiBootServicesTableLib.h>\r | |
cd98f305 LG |
17 | \r |
18 | #define SECURITY_HANDLER_TABLE_SIZE 0x10\r | |
19 | \r | |
bc2dfdbc LG |
20 | //\r |
21 | // Secruity Operation on Image and none Image.\r | |
22 | //\r | |
23 | #define EFI_AUTH_IMAGE_OPERATION_MASK (EFI_AUTH_OPERATION_VERIFY_IMAGE \\r | |
24 | | EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD \\r | |
25 | | EFI_AUTH_OPERATION_MEASURE_IMAGE)\r | |
26 | #define EFI_AUTH_NONE_IMAGE_OPERATION_MASK (EFI_AUTH_OPERATION_CONNECT_POLICY \\r | |
27 | | EFI_AUTH_OPERATION_AUTHENTICATION_STATE)\r | |
cd98f305 LG |
28 | \r |
29 | typedef struct {\r | |
30 | UINT32 SecurityOperation;\r | |
31 | SECURITY_FILE_AUTHENTICATION_STATE_HANDLER SecurityHandler;\r | |
32 | } SECURITY_INFO;\r | |
33 | \r | |
bc2dfdbc LG |
34 | typedef struct {\r |
35 | UINT32 Security2Operation;\r | |
36 | SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler;\r | |
37 | } SECURITY2_INFO;\r | |
38 | \r | |
cd98f305 LG |
39 | UINT32 mCurrentAuthOperation = 0;\r |
40 | UINT32 mNumberOfSecurityHandler = 0;\r | |
41 | UINT32 mMaxNumberOfSecurityHandler = 0;\r | |
42 | SECURITY_INFO *mSecurityTable = NULL;\r | |
43 | \r | |
bc2dfdbc LG |
44 | UINT32 mCurrentAuthOperation2 = 0;\r |
45 | UINT32 mNumberOfSecurity2Handler = 0;\r | |
46 | UINT32 mMaxNumberOfSecurity2Handler = 0;\r | |
47 | SECURITY2_INFO *mSecurity2Table = NULL;\r | |
48 | \r | |
cd98f305 LG |
49 | /**\r |
50 | Reallocates more global memory to store the registered Handler list.\r | |
51 | \r | |
52 | @retval RETURN_SUCCESS Reallocate memory successfully.\r | |
53 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.\r | |
54 | **/\r | |
55 | RETURN_STATUS\r | |
56 | EFIAPI\r | |
57 | ReallocateSecurityHandlerTable (\r | |
f826516d | 58 | VOID\r |
cd98f305 LG |
59 | )\r |
60 | {\r | |
61 | //\r | |
62 | // Reallocate memory for security info structure.\r | |
63 | //\r | |
64 | mSecurityTable = ReallocatePool (\r | |
d1102dba LG |
65 | mMaxNumberOfSecurityHandler * sizeof (SECURITY_INFO),\r |
66 | (mMaxNumberOfSecurityHandler + SECURITY_HANDLER_TABLE_SIZE) * sizeof (SECURITY_INFO),\r | |
cd98f305 LG |
67 | mSecurityTable\r |
68 | );\r | |
69 | \r | |
70 | //\r | |
71 | // No enough resource is allocated.\r | |
72 | //\r | |
73 | if (mSecurityTable == NULL) {\r | |
74 | return RETURN_OUT_OF_RESOURCES;\r | |
75 | }\r | |
76 | \r | |
77 | //\r | |
78 | // Increase max handler number\r | |
79 | //\r | |
80 | mMaxNumberOfSecurityHandler = mMaxNumberOfSecurityHandler + SECURITY_HANDLER_TABLE_SIZE;\r | |
81 | return RETURN_SUCCESS;\r | |
82 | }\r | |
83 | \r | |
84 | /**\r | |
d1102dba | 85 | Check whether an operation is valid according to the requirement of current operation,\r |
cd98f305 LG |
86 | which must make sure that the measure image operation is the last one.\r |
87 | \r | |
88 | @param CurrentAuthOperation Current operation.\r | |
89 | @param CheckAuthOperation Operation to be checked.\r | |
90 | \r | |
91 | @retval TRUE Operation is valid for current operation.\r | |
92 | @retval FALSE Operation is invalid for current operation.\r | |
93 | **/\r | |
94 | BOOLEAN\r | |
95 | CheckAuthenticationOperation (\r | |
96 | IN UINT32 CurrentAuthOperation,\r | |
97 | IN UINT32 CheckAuthOperation\r | |
98 | )\r | |
d1102dba | 99 | {\r |
cd98f305 LG |
100 | //\r |
101 | // Make sure new auth operation can be recognized.\r | |
102 | //\r | |
c9e88815 | 103 | ASSERT ((CheckAuthOperation & ~(EFI_AUTH_IMAGE_OPERATION_MASK | EFI_AUTH_OPERATION_AUTHENTICATION_STATE | EFI_AUTH_OPERATION_IMAGE_REQUIRED)) == 0);\r |
d1102dba | 104 | \r |
cd98f305 | 105 | //\r |
d1102dba | 106 | // When current operation includes measure image operation,\r |
cd98f305 LG |
107 | // only another measure image operation or none operation will be allowed.\r |
108 | //\r | |
109 | if ((CurrentAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) {\r | |
110 | if (((CheckAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) ||\r | |
bc2dfdbc | 111 | ((CheckAuthOperation & EFI_AUTH_IMAGE_OPERATION_MASK) == EFI_AUTH_OPERATION_NONE)) {\r |
cd98f305 LG |
112 | return TRUE;\r |
113 | } else {\r | |
114 | return FALSE;\r | |
115 | }\r | |
116 | }\r | |
d1102dba | 117 | \r |
cd98f305 | 118 | //\r |
d1102dba | 119 | // When current operation doesn't include measure image operation,\r |
cd98f305 LG |
120 | // any new operation will be allowed.\r |
121 | //\r | |
122 | return TRUE;\r | |
123 | }\r | |
124 | \r | |
125 | /**\r | |
126 | Register security measurement handler with its operation type. The different\r | |
127 | handler with the same operation can all be registered.\r | |
128 | \r | |
129 | If SecurityHandler is NULL, then ASSERT().\r | |
130 | If no enough resources available to register new handler, then ASSERT().\r | |
131 | If AuthenticationOperation is not recongnized, then ASSERT().\r | |
132 | If the previous register handler can't be executed before the later register handler, then ASSERT().\r | |
133 | \r | |
134 | @param[in] SecurityHandler Security measurement service handler to be registered.\r | |
135 | @param[in] AuthenticationOperation Operation type is specified for the registered handler.\r | |
136 | \r | |
137 | @retval EFI_SUCCESS The handlers were registered successfully.\r | |
138 | **/\r | |
139 | EFI_STATUS\r | |
140 | EFIAPI\r | |
141 | RegisterSecurityHandler (\r | |
142 | IN SECURITY_FILE_AUTHENTICATION_STATE_HANDLER SecurityHandler,\r | |
143 | IN UINT32 AuthenticationOperation\r | |
144 | )\r | |
145 | {\r | |
146 | EFI_STATUS Status;\r | |
147 | \r | |
148 | ASSERT (SecurityHandler != NULL);\r | |
149 | \r | |
150 | //\r | |
151 | // Make sure AuthenticationOperation is valid in the register order.\r | |
152 | //\r | |
153 | ASSERT (CheckAuthenticationOperation (mCurrentAuthOperation, AuthenticationOperation));\r | |
154 | mCurrentAuthOperation = mCurrentAuthOperation | AuthenticationOperation;\r | |
155 | \r | |
156 | //\r | |
157 | // Check whether the handler lists is enough to store new handler.\r | |
158 | //\r | |
159 | if (mNumberOfSecurityHandler == mMaxNumberOfSecurityHandler) {\r | |
160 | //\r | |
161 | // Allocate more resources for new handler.\r | |
162 | //\r | |
163 | Status = ReallocateSecurityHandlerTable();\r | |
164 | ASSERT_EFI_ERROR (Status);\r | |
165 | }\r | |
166 | \r | |
167 | //\r | |
168 | // Register new handler into the handler list.\r | |
169 | //\r | |
170 | mSecurityTable[mNumberOfSecurityHandler].SecurityOperation = AuthenticationOperation;\r | |
171 | mSecurityTable[mNumberOfSecurityHandler].SecurityHandler = SecurityHandler;\r | |
172 | mNumberOfSecurityHandler ++;\r | |
173 | \r | |
174 | return EFI_SUCCESS;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | Execute registered handlers until one returns an error and that error is returned.\r | |
179 | If none of the handlers return an error, then EFI_SUCCESS is returned.\r | |
180 | \r | |
d1102dba | 181 | Before exectue handler, get the image buffer by file device path if a handler\r |
cd98f305 LG |
182 | requires the image file. And return the image buffer to each handler when exectue handler.\r |
183 | \r | |
184 | The handlers are executed in same order to their registered order.\r | |
185 | \r | |
d1102dba | 186 | @param[in] AuthenticationStatus\r |
cd98f305 LG |
187 | This is the authentication type returned from the Section\r |
188 | Extraction protocol. See the Section Extraction Protocol\r | |
189 | Specification for details on this type.\r | |
190 | @param[in] FilePath This is a pointer to the device path of the file that is\r | |
191 | being dispatched. This will optionally be used for logging.\r | |
192 | \r | |
193 | @retval EFI_SUCCESS The file specified by File did authenticate when more\r | |
d1102dba LG |
194 | than one security handler services were registered,\r |
195 | or the file did not authenticate when no security\r | |
196 | handler service was registered. And the platform policy\r | |
cd98f305 LG |
197 | dictates that the DXE Core may use File.\r |
198 | @retval EFI_INVALID_PARAMETER File is NULL.\r | |
199 | @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and\r | |
200 | the platform policy dictates that File should be placed\r | |
201 | in the untrusted state. A file may be promoted from\r | |
202 | the untrusted to the trusted state at a future time\r | |
203 | with a call to the Trust() DXE Service.\r | |
204 | @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and\r | |
205 | the platform policy dictates that File should not be\r | |
206 | used for any purpose.\r | |
207 | **/\r | |
208 | EFI_STATUS\r | |
209 | EFIAPI\r | |
210 | ExecuteSecurityHandlers (\r | |
211 | IN UINT32 AuthenticationStatus,\r | |
212 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
213 | )\r | |
214 | {\r | |
215 | UINT32 Index;\r | |
216 | EFI_STATUS Status;\r | |
217 | UINT32 HandlerAuthenticationStatus;\r | |
218 | VOID *FileBuffer;\r | |
219 | UINTN FileSize;\r | |
2b75e8cd LG |
220 | EFI_HANDLE Handle;\r |
221 | EFI_DEVICE_PATH_PROTOCOL *Node;\r | |
222 | EFI_DEVICE_PATH_PROTOCOL *FilePathToVerfiy;\r | |
d1102dba | 223 | \r |
cd98f305 LG |
224 | if (FilePath == NULL) {\r |
225 | return EFI_INVALID_PARAMETER;\r | |
226 | }\r | |
227 | \r | |
228 | //\r | |
229 | // Directly return successfully when no handler is registered.\r | |
230 | //\r | |
231 | if (mNumberOfSecurityHandler == 0) {\r | |
232 | return EFI_SUCCESS;\r | |
233 | }\r | |
d1102dba | 234 | \r |
cd98f305 LG |
235 | Status = EFI_SUCCESS;\r |
236 | FileBuffer = NULL;\r | |
237 | FileSize = 0;\r | |
238 | HandlerAuthenticationStatus = AuthenticationStatus;\r | |
2b75e8cd | 239 | FilePathToVerfiy = (EFI_DEVICE_PATH_PROTOCOL *) FilePath;\r |
cd98f305 LG |
240 | //\r |
241 | // Run security handler in same order to their registered list\r | |
242 | //\r | |
243 | for (Index = 0; Index < mNumberOfSecurityHandler; Index ++) {\r | |
244 | if ((mSecurityTable[Index].SecurityOperation & EFI_AUTH_OPERATION_IMAGE_REQUIRED) == EFI_AUTH_OPERATION_IMAGE_REQUIRED) {\r | |
245 | //\r | |
246 | // Try get file buffer when the handler requires image buffer.\r | |
247 | //\r | |
248 | if (FileBuffer == NULL) {\r | |
2b75e8cd LG |
249 | Node = FilePathToVerfiy;\r |
250 | Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);\r | |
2983a79d LG |
251 | //\r |
252 | // Try to get image by FALSE boot policy for the exact boot file path.\r | |
253 | //\r | |
cd98f305 | 254 | FileBuffer = GetFileBufferByFilePath (FALSE, FilePath, &FileSize, &AuthenticationStatus);\r |
2983a79d LG |
255 | if (FileBuffer == NULL) {\r |
256 | //\r | |
257 | // Try to get image by TRUE boot policy for the inexact boot file path.\r | |
258 | //\r | |
259 | FileBuffer = GetFileBufferByFilePath (TRUE, FilePath, &FileSize, &AuthenticationStatus);\r | |
260 | }\r | |
2b75e8cd LG |
261 | if ((FileBuffer != NULL) && (!EFI_ERROR (Status))) {\r |
262 | //\r | |
263 | // LoadFile () may cause the device path of the Handle be updated.\r | |
264 | //\r | |
265 | FilePathToVerfiy = AppendDevicePath (DevicePathFromHandle (Handle), Node);\r | |
266 | }\r | |
cd98f305 LG |
267 | }\r |
268 | }\r | |
269 | Status = mSecurityTable[Index].SecurityHandler (\r | |
270 | HandlerAuthenticationStatus,\r | |
2b75e8cd | 271 | FilePathToVerfiy,\r |
cd98f305 LG |
272 | FileBuffer,\r |
273 | FileSize\r | |
274 | );\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | break;\r | |
277 | }\r | |
278 | }\r | |
279 | \r | |
280 | if (FileBuffer != NULL) {\r | |
281 | FreePool (FileBuffer);\r | |
282 | }\r | |
2b75e8cd LG |
283 | if (FilePathToVerfiy != FilePath) {\r |
284 | FreePool (FilePathToVerfiy);\r | |
285 | }\r | |
cd98f305 LG |
286 | \r |
287 | return Status;\r | |
288 | }\r | |
bc2dfdbc LG |
289 | \r |
290 | /**\r | |
291 | Reallocates more global memory to store the registered Securit2Handler list.\r | |
292 | \r | |
293 | @retval RETURN_SUCCESS Reallocate memory successfully.\r | |
294 | @retval RETURN_OUT_OF_RESOURCES No enough memory to allocated.\r | |
295 | **/\r | |
296 | RETURN_STATUS\r | |
297 | EFIAPI\r | |
298 | ReallocateSecurity2HandlerTable (\r | |
f826516d | 299 | VOID\r |
bc2dfdbc LG |
300 | )\r |
301 | {\r | |
302 | //\r | |
303 | // Reallocate memory for security info structure.\r | |
304 | //\r | |
305 | mSecurity2Table = ReallocatePool (\r | |
d1102dba LG |
306 | mMaxNumberOfSecurity2Handler * sizeof (SECURITY2_INFO),\r |
307 | (mMaxNumberOfSecurity2Handler + SECURITY_HANDLER_TABLE_SIZE) * sizeof (SECURITY2_INFO),\r | |
bc2dfdbc LG |
308 | mSecurity2Table\r |
309 | );\r | |
310 | \r | |
311 | //\r | |
312 | // No enough resource is allocated.\r | |
313 | //\r | |
314 | if (mSecurity2Table == NULL) {\r | |
315 | return RETURN_OUT_OF_RESOURCES;\r | |
316 | }\r | |
317 | \r | |
318 | //\r | |
319 | // Increase max handler number\r | |
320 | //\r | |
321 | mMaxNumberOfSecurity2Handler = mMaxNumberOfSecurity2Handler + SECURITY_HANDLER_TABLE_SIZE;\r | |
322 | return RETURN_SUCCESS;\r | |
323 | }\r | |
324 | \r | |
325 | /**\r | |
d1102dba | 326 | Check whether an operation is valid according to the requirement of current operation,\r |
bc2dfdbc | 327 | which must make sure that the measure image operation is the last one.\r |
d1102dba | 328 | \r |
bc2dfdbc LG |
329 | If AuthenticationOperation is not recongnized, return FALSE.\r |
330 | If AuthenticationOperation is EFI_AUTH_OPERATION_NONE, return FALSE.\r | |
331 | If AuthenticationOperation includes security operation and authentication operation, return FALSE.\r | |
332 | If the previous register handler can't be executed before the later register handler, return FALSE.\r | |
d1102dba | 333 | \r |
bc2dfdbc LG |
334 | @param CurrentAuthOperation Current operation.\r |
335 | @param CheckAuthOperation Operation to be checked.\r | |
d1102dba | 336 | \r |
bc2dfdbc LG |
337 | @retval TRUE Operation is valid for current operation.\r |
338 | @retval FALSE Operation is invalid for current operation.\r | |
339 | **/\r | |
340 | BOOLEAN\r | |
341 | CheckAuthentication2Operation (\r | |
342 | IN UINT32 CurrentAuthOperation,\r | |
343 | IN UINT32 CheckAuthOperation\r | |
344 | )\r | |
d1102dba | 345 | {\r |
bc2dfdbc LG |
346 | //\r |
347 | // Make sure new auth operation can be recognized.\r | |
348 | //\r | |
349 | if (CheckAuthOperation == EFI_AUTH_OPERATION_NONE) {\r | |
350 | return FALSE;\r | |
351 | }\r | |
d1102dba LG |
352 | if ((CheckAuthOperation & ~(EFI_AUTH_IMAGE_OPERATION_MASK |\r |
353 | EFI_AUTH_NONE_IMAGE_OPERATION_MASK |\r | |
bc2dfdbc LG |
354 | EFI_AUTH_OPERATION_IMAGE_REQUIRED)) != 0) {\r |
355 | return FALSE;\r | |
356 | }\r | |
357 | \r | |
358 | //\r | |
d1102dba | 359 | // When current operation includes measure image operation,\r |
bc2dfdbc LG |
360 | // only another measure image or none image operation will be allowed.\r |
361 | //\r | |
362 | if ((CurrentAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) {\r | |
363 | if (((CheckAuthOperation & EFI_AUTH_OPERATION_MEASURE_IMAGE) == EFI_AUTH_OPERATION_MEASURE_IMAGE) ||\r | |
364 | ((CheckAuthOperation & EFI_AUTH_IMAGE_OPERATION_MASK) == 0)) {\r | |
365 | return TRUE;\r | |
366 | } else {\r | |
367 | return FALSE;\r | |
368 | }\r | |
369 | }\r | |
d1102dba | 370 | \r |
bc2dfdbc LG |
371 | //\r |
372 | // Any other operation will be allowed.\r | |
373 | //\r | |
374 | return TRUE;\r | |
375 | }\r | |
376 | \r | |
377 | /**\r | |
378 | Register security measurement handler with its operation type. Different\r | |
379 | handlers with the same operation can all be registered.\r | |
380 | \r | |
381 | If Security2Handler is NULL, then ASSERT().\r | |
382 | If no enough resources available to register new handler, then ASSERT().\r | |
383 | If AuthenticationOperation is not recongnized, then ASSERT().\r | |
384 | If AuthenticationOperation is EFI_AUTH_OPERATION_NONE, then ASSERT().\r | |
385 | If the previous register handler can't be executed before the later register handler, then ASSERT().\r | |
386 | \r | |
387 | @param[in] Security2Handler The security measurement service handler to be registered.\r | |
388 | @param[in] AuthenticationOperation The operation type is specified for the registered handler.\r | |
389 | \r | |
390 | @retval EFI_SUCCESS The handlers were registered successfully.\r | |
391 | **/\r | |
392 | EFI_STATUS\r | |
393 | EFIAPI\r | |
394 | RegisterSecurity2Handler (\r | |
395 | IN SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler,\r | |
396 | IN UINT32 AuthenticationOperation\r | |
397 | )\r | |
398 | {\r | |
399 | EFI_STATUS Status;\r | |
400 | \r | |
401 | ASSERT (Security2Handler != NULL);\r | |
402 | \r | |
403 | //\r | |
404 | // Make sure AuthenticationOperation is valid in the register order.\r | |
405 | //\r | |
406 | ASSERT (CheckAuthentication2Operation (mCurrentAuthOperation2, AuthenticationOperation));\r | |
407 | mCurrentAuthOperation2 = mCurrentAuthOperation2 | AuthenticationOperation;\r | |
408 | \r | |
409 | //\r | |
410 | // Check whether the handler lists is enough to store new handler.\r | |
411 | //\r | |
412 | if (mNumberOfSecurity2Handler == mMaxNumberOfSecurity2Handler) {\r | |
413 | //\r | |
414 | // Allocate more resources for new handler.\r | |
415 | //\r | |
416 | Status = ReallocateSecurity2HandlerTable();\r | |
417 | ASSERT_EFI_ERROR (Status);\r | |
418 | }\r | |
419 | \r | |
420 | //\r | |
421 | // Register new handler into the handler list.\r | |
422 | //\r | |
423 | mSecurity2Table[mNumberOfSecurity2Handler].Security2Operation = AuthenticationOperation;\r | |
424 | mSecurity2Table[mNumberOfSecurity2Handler].Security2Handler = Security2Handler;\r | |
425 | mNumberOfSecurity2Handler ++;\r | |
426 | \r | |
427 | return EFI_SUCCESS;\r | |
428 | }\r | |
429 | \r | |
430 | /**\r | |
d1102dba LG |
431 | Execute registered handlers based on input AuthenticationOperation until\r |
432 | one returns an error and that error is returned.\r | |
433 | \r | |
bc2dfdbc LG |
434 | If none of the handlers return an error, then EFI_SUCCESS is returned.\r |
435 | The handlers those satisfy AuthenticationOperation will only be executed.\r | |
436 | The handlers are executed in same order to their registered order.\r | |
437 | \r | |
d1102dba | 438 | @param[in] AuthenticationOperation\r |
bc2dfdbc | 439 | The operation type specifies which handlers will be executed.\r |
d1102dba | 440 | @param[in] AuthenticationStatus\r |
bc2dfdbc LG |
441 | The authentication status for the input file.\r |
442 | @param[in] File This is a pointer to the device path of the file that is\r | |
443 | being dispatched. This will optionally be used for logging.\r | |
444 | @param[in] FileBuffer A pointer to the buffer with the UEFI file image\r | |
445 | @param[in] FileSize The size of File buffer.\r | |
446 | @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service.\r | |
447 | \r | |
448 | @retval EFI_SUCCESS The file specified by DevicePath and non-NULL\r | |
449 | FileBuffer did authenticate, and the platform policy dictates\r | |
450 | that the DXE Foundation may use the file.\r | |
451 | @retval EFI_SUCCESS The device path specified by NULL device path DevicePath\r | |
452 | and non-NULL FileBuffer did authenticate, and the platform\r | |
453 | policy dictates that the DXE Foundation may execute the image in\r | |
454 | FileBuffer.\r | |
455 | @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start\r | |
456 | UEFI device drivers on the device path specified by DevicePath.\r | |
457 | @retval EFI_SECURITY_VIOLATION The file specified by File or FileBuffer did not\r | |
d1102dba | 458 | authenticate, and the platform policy dictates that\r |
bc2dfdbc LG |
459 | the file should be placed in the untrusted state.\r |
460 | @retval EFI_SECURITY_VIOLATION FileBuffer FileBuffer is NULL and the user has no\r | |
461 | permission to start UEFI device drivers on the device path specified\r | |
462 | by DevicePath.\r | |
463 | @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load\r | |
464 | drivers from the device path specified by DevicePath. The\r | |
465 | image has been added into the list of the deferred images.\r | |
466 | @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and\r | |
467 | the platform policy dictates that the DXE\r | |
468 | Foundation may not use File.\r | |
d1102dba | 469 | @retval EFI_INVALID_PARAMETER File and FileBuffer are both NULL.\r |
bc2dfdbc LG |
470 | **/\r |
471 | EFI_STATUS\r | |
472 | EFIAPI\r | |
473 | ExecuteSecurity2Handlers (\r | |
474 | IN UINT32 AuthenticationOperation,\r | |
475 | IN UINT32 AuthenticationStatus,\r | |
476 | IN CONST EFI_DEVICE_PATH_PROTOCOL *File,\r | |
477 | IN VOID *FileBuffer,\r | |
478 | IN UINTN FileSize,\r | |
479 | IN BOOLEAN BootPolicy\r | |
480 | )\r | |
481 | {\r | |
482 | UINT32 Index;\r | |
483 | EFI_STATUS Status;\r | |
484 | \r | |
485 | //\r | |
486 | // Invalid case if File and FileBuffer are both NULL.\r | |
487 | //\r | |
488 | if (File == NULL && FileBuffer == NULL) {\r | |
489 | return EFI_INVALID_PARAMETER;\r | |
490 | }\r | |
491 | \r | |
492 | //\r | |
493 | // Directly return successfully when no handler is registered.\r | |
494 | //\r | |
495 | if (mNumberOfSecurity2Handler == 0) {\r | |
496 | return EFI_SUCCESS;\r | |
497 | }\r | |
498 | \r | |
499 | //\r | |
500 | // Run security handler in same order to their registered list\r | |
501 | //\r | |
502 | for (Index = 0; Index < mNumberOfSecurity2Handler; Index ++) {\r | |
503 | //\r | |
504 | // If FileBuffer is not NULL, the input is Image, which will be handled by EFI_AUTH_IMAGE_OPERATION_MASK operation.\r | |
505 | // If FileBuffer is NULL, the input is not Image, which will be handled by EFI_AUTH_NONE_IMAGE_OPERATION_MASK operation.\r | |
506 | // Other cases are ignored.\r | |
507 | //\r | |
508 | if ((FileBuffer != NULL && (mSecurity2Table[Index].Security2Operation & EFI_AUTH_IMAGE_OPERATION_MASK) != 0) ||\r | |
509 | (FileBuffer == NULL && (mSecurity2Table[Index].Security2Operation & EFI_AUTH_NONE_IMAGE_OPERATION_MASK) != 0)) {\r | |
510 | //\r | |
511 | // Execute registered handlers based on input AuthenticationOperation\r | |
512 | //\r | |
513 | if ((mSecurity2Table[Index].Security2Operation & AuthenticationOperation) != 0) {\r | |
514 | Status = mSecurity2Table[Index].Security2Handler (\r | |
515 | AuthenticationStatus,\r | |
516 | File,\r | |
517 | FileBuffer,\r | |
518 | FileSize,\r | |
519 | BootPolicy\r | |
520 | );\r | |
521 | if (EFI_ERROR (Status)) {\r | |
522 | return Status;\r | |
523 | }\r | |
524 | }\r | |
525 | }\r | |
526 | }\r | |
527 | \r | |
528 | return EFI_SUCCESS;\r | |
529 | }\r |