2008-03-19 10:01:03 +01:00
|
|
|
/** @file
|
2008-07-16 11:40:06 +02:00
|
|
|
EFI PEI Core Security services
|
|
|
|
|
2014-08-18 07:43:06 +02:00
|
|
|
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-04 09:51:48 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-10-31 05:35:02 +01:00
|
|
|
#include "PeiMain.h"
|
2007-07-04 09:51:48 +02:00
|
|
|
|
|
|
|
|
2008-10-30 07:05:06 +01:00
|
|
|
EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
|
2007-09-24 13:38:43 +02:00
|
|
|
&gEfiPeiSecurity2PpiGuid,
|
2007-07-04 09:51:48 +02:00
|
|
|
SecurityPpiNotifyCallback
|
|
|
|
};
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2007-07-04 09:51:48 +02:00
|
|
|
Initialize the security services.
|
|
|
|
|
2008-08-08 03:37:44 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
2008-07-23 11:15:14 +02:00
|
|
|
@param OldCoreData Pointer to the old core data.
|
2008-07-16 11:40:06 +02:00
|
|
|
NULL if being run in non-permament memory mode.
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
InitializeSecurityServices (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN PEI_CORE_INSTANCE *OldCoreData
|
|
|
|
)
|
2007-07-04 09:51:48 +02:00
|
|
|
{
|
|
|
|
if (OldCoreData == NULL) {
|
|
|
|
PeiServicesNotifyPpi (&mNotifyList);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
|
|
|
|
Provide a callback for when the security PPI is installed.
|
2008-08-18 10:38:00 +02:00
|
|
|
This routine will cache installed security PPI into PeiCore's private data.
|
|
|
|
|
2008-08-08 03:37:44 +02:00
|
|
|
@param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
|
|
|
|
@param NotifyDescriptor The descriptor for the notification event.
|
|
|
|
@param Ppi Pointer to the PPI in question.
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
@return Always success
|
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SecurityPpiNotifyCallback (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PEI_CORE_INSTANCE *PrivateData;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get PEI Core private data
|
|
|
|
//
|
|
|
|
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If there isn't a security PPI installed, use the one from notification
|
|
|
|
//
|
|
|
|
if (PrivateData->PrivateSecurityPpi == NULL) {
|
2007-09-24 13:38:43 +02:00
|
|
|
PrivateData->PrivateSecurityPpi = (EFI_PEI_SECURITY2_PPI *)Ppi;
|
2007-07-04 09:51:48 +02:00
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
2007-07-04 09:51:48 +02:00
|
|
|
Provide a callout to the security verification service.
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
@param PrivateData PeiCore's private data structure
|
|
|
|
@param VolumeHandle Handle of FV
|
|
|
|
@param FileHandle Handle of PEIM's ffs
|
2013-10-11 05:54:13 +02:00
|
|
|
@param AuthenticationStatus Authentication status
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
@retval EFI_SUCCESS Image is OK
|
|
|
|
@retval EFI_SECURITY_VIOLATION Image is illegal
|
2008-08-18 10:38:00 +02:00
|
|
|
@retval EFI_NOT_FOUND If security PPI is not installed.
|
2008-07-16 11:40:06 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
VerifyPeim (
|
|
|
|
IN PEI_CORE_INSTANCE *PrivateData,
|
|
|
|
IN EFI_PEI_FV_HANDLE VolumeHandle,
|
2013-10-11 05:54:13 +02:00
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
IN UINT32 AuthenticationStatus
|
2008-07-16 11:40:06 +02:00
|
|
|
)
|
2007-07-04 09:51:48 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2007-09-24 13:38:43 +02:00
|
|
|
BOOLEAN DeferExection;
|
2007-07-04 09:51:48 +02:00
|
|
|
|
2014-08-18 07:43:06 +02:00
|
|
|
Status = EFI_NOT_FOUND;
|
2007-07-04 09:51:48 +02:00
|
|
|
if (PrivateData->PrivateSecurityPpi == NULL) {
|
2014-08-18 07:43:06 +02:00
|
|
|
//
|
|
|
|
// Check AuthenticationStatus first.
|
|
|
|
//
|
|
|
|
if ((AuthenticationStatus & EFI_AUTH_STATUS_IMAGE_SIGNED) != 0) {
|
|
|
|
if ((AuthenticationStatus & (EFI_AUTH_STATUS_TEST_FAILED | EFI_AUTH_STATUS_NOT_TESTED)) != 0) {
|
|
|
|
Status = EFI_SECURITY_VIOLATION;
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 09:51:48 +02:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Check to see if the image is OK
|
|
|
|
//
|
|
|
|
Status = PrivateData->PrivateSecurityPpi->AuthenticationState (
|
2010-02-11 03:33:16 +01:00
|
|
|
(CONST EFI_PEI_SERVICES **) &PrivateData->Ps,
|
2007-07-04 09:51:48 +02:00
|
|
|
PrivateData->PrivateSecurityPpi,
|
|
|
|
AuthenticationStatus,
|
2007-09-24 13:38:43 +02:00
|
|
|
VolumeHandle,
|
|
|
|
FileHandle,
|
|
|
|
&DeferExection
|
2007-07-04 09:51:48 +02:00
|
|
|
);
|
2007-09-24 13:38:43 +02:00
|
|
|
if (DeferExection) {
|
2007-07-04 09:51:48 +02:00
|
|
|
Status = EFI_SECURITY_VIOLATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-16 11:40:06 +02:00
|
|
|
/**
|
|
|
|
Verify a Firmware volume.
|
|
|
|
|
2008-08-18 10:38:00 +02:00
|
|
|
@param CurrentFvAddress Pointer to the current Firmware Volume under consideration
|
2008-07-16 11:40:06 +02:00
|
|
|
|
2008-08-18 10:38:00 +02:00
|
|
|
@retval EFI_SUCCESS Firmware Volume is legal
|
2008-07-16 11:40:06 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-04 09:51:48 +02:00
|
|
|
EFI_STATUS
|
|
|
|
VerifyFv (
|
|
|
|
IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Right now just pass the test. Future can authenticate and/or check the
|
|
|
|
// FV-header or other metric for goodness of binary.
|
|
|
|
//
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|