-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from amrathesh/psci-mem-protect
R310_BBSR: Platform Reset Attack Mitigation thru PSCI
- Loading branch information
Showing
11 changed files
with
579 additions
and
9 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
bbsr/sct-tests/PlatformResetAttackMitigationPsciTest/BlackBoxTest/Guid.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** @file | ||
Copyright (c) 2024, Arm Ltd, All rights reserved.<BR> | ||
This program and the accompanying materials | ||
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. | ||
**/ | ||
/*++ | ||
Module Name: | ||
guid.c | ||
Abstract: | ||
GUIDs auto-generated for EFI test assertion. | ||
--*/ | ||
|
||
#include "Efi.h" | ||
#include "Guid.h" | ||
|
||
|
||
const EFI_GUID gPlatformResetAttackMitigationPsciBbTestAssertionGuid001 = | ||
EFI_TEST_PLATRESETATTACKMITIGATIONPSCIBBTEST_ASSERTION_001_GUID; |
34 changes: 34 additions & 0 deletions
34
bbsr/sct-tests/PlatformResetAttackMitigationPsciTest/BlackBoxTest/Guid.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @file | ||
Copyright (c) 2024, Arm Ltd, All rights reserved.<BR> | ||
This program and the accompanying materials | ||
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. | ||
**/ | ||
|
||
/*++ | ||
Module Name: | ||
guid.h | ||
Abstract: | ||
GUIDs auto-generated for EFI test assertion. | ||
--*/ | ||
|
||
extern EFI_GUID gEfiGlobalVariableGuid; | ||
|
||
#define PLAT_RESET_ATTACK_MITIGATION_TEST_GUID \ | ||
{0xf4fc5de8, 0x7ba2, 0x422c, {0xa5, 0x5b, 0x4f, 0x76, 0x0e, 0xd6, 0xa8, 0x5d}} | ||
|
||
#define EFI_TEST_PLATRESETATTACKMITIGATIONPSCIBBTEST_ASSERTION_001_GUID \ | ||
{0x24d2d671, 0xea3d, 0x4c67, {0xba, 0xa2, 0x73, 0x6b, 0xeb, 0x09, 0x66, 0xf9}} | ||
extern const EFI_GUID gPlatformResetAttackMitigationPsciBbTestAssertionGuid001; |
55 changes: 55 additions & 0 deletions
55
...ormResetAttackMitigationPsciTest/BlackBoxTest/PlatformResetAttackMitigationPsciBBTest.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## @file | ||
# | ||
# Copyright (c) 2024, Arm Ltd,. All rights reserved.<BR> | ||
# | ||
# This program and the accompanying materials | ||
# 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. | ||
# | ||
## | ||
#/*++ | ||
# | ||
# Module Name: | ||
# | ||
# PlatformResetAttackMitigationPsciBBTest.inf | ||
# | ||
# Abstract: | ||
# | ||
# Component description file for Platform Reset Attack Mitigation Via PSCI Black-Box Test. | ||
# | ||
#--*/ | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010005 | ||
BASE_NAME = PlatformResetAttackMitigationPsciTest | ||
FILE_GUID = 5c2c18d0-62be-40fe-8ba6-692bf06c97ad | ||
MODULE_TYPE = UEFI_DRIVER | ||
VERSION_STRING = 1.0 | ||
ENTRY_POINT = InitializePlatformResetAttackMitigationPsciBBTest | ||
|
||
[Sources.common] | ||
PlatformResetAttackMitigationPsciBBTestMain.h | ||
PlatformResetAttackMitigationPsciBBTestMain.c | ||
PlatformResetAttackMitigationPsciBBTestFunction.c | ||
Guid.h | ||
Guid.c | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
SctPkg/SctPkg.dec | ||
SctPkg/UEFI/UEFI.dec | ||
ArmPkg/ArmPkg.dec | ||
|
||
[LibraryClasses] | ||
UefiDriverEntryPoint | ||
SctLib | ||
EfiTestLib | ||
ArmSmcLib | ||
|
||
[Protocols] | ||
gEfiTestRecoveryLibraryGuid | ||
gEfiTestLoggingLibraryGuid |
175 changes: 175 additions & 0 deletions
175
...etAttackMitigationPsciTest/BlackBoxTest/PlatformResetAttackMitigationPsciBBTestFunction.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/** @file | ||
Copyright (c) 2024, Arm Ltd, All rights reserved.<BR> | ||
This program and the accompanying materials | ||
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. | ||
**/ | ||
/*++ | ||
Module Name: | ||
PlatformResetAttackMitigationPsciBBTestFunction.c | ||
Abstract: | ||
Source file for Platform Reset Attack Mitigation PSCI Black-Box Test. | ||
--*/ | ||
|
||
#include "SctLib.h" | ||
#include "PlatformResetAttackMitigationPsciBBTestMain.h" | ||
#include <Library/ArmSmcLib.h> | ||
|
||
ARM_SMC_ARGS SmcArgs; | ||
|
||
// | ||
// Prototypes | ||
// | ||
|
||
EFI_STATUS | ||
PlatformResetAttackMitigationPsciTest ( | ||
IN EFI_BB_TEST_PROTOCOL *This, | ||
IN VOID *ClientInterface, | ||
IN EFI_TEST_LEVEL TestLevel, | ||
IN EFI_HANDLE SupportHandle | ||
); | ||
|
||
// | ||
// Prototypes (internal) | ||
// | ||
|
||
EFI_STATUS | ||
PlatformResetAttackMitigationPsciTestSub1 ( | ||
IN EFI_RUNTIME_SERVICES *RT, | ||
IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, | ||
IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib | ||
); | ||
|
||
/* BBSR R310_BBSR - Entry point for Platform Reset Attack Mitigation via PSCI Function Test. | ||
* @param This A pointer to the EFI_BB_TEST_PROTOCOL instance. | ||
* @param ClientInterface A pointer to the interface to be tested. | ||
* @param TestLevel Test "thoroughness" control. | ||
* @param SupportHandle A handle containing support protocols. | ||
* @return EFI_SUCCESS Successfully. | ||
* @return Other value Something failed. | ||
*/ | ||
EFI_STATUS | ||
PlatformResetAttackMitigationPsciTest ( | ||
IN EFI_BB_TEST_PROTOCOL *This, | ||
IN VOID *ClientInterface, | ||
IN EFI_TEST_LEVEL TestLevel, | ||
IN EFI_HANDLE SupportHandle | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
EFI_RUNTIME_SERVICES *RT; | ||
EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; | ||
EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib; | ||
EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib; | ||
|
||
// | ||
// Get test support library interfaces | ||
// | ||
Status = GetTestSupportLibrary ( | ||
SupportHandle, | ||
&StandardLib, | ||
&RecoveryLib, | ||
&LoggingLib | ||
); | ||
if (EFI_ERROR(Status)) { | ||
return Status; | ||
} | ||
|
||
if (FALSE == CheckBBTestCanRunAndRecordAssertion( | ||
StandardLib, | ||
L"Platform Reset Attack Mitigation via PSCI test not supported in EFI", | ||
__FILE__, | ||
(UINTN)__LINE__ | ||
)) { | ||
return EFI_SUCCESS; | ||
} | ||
|
||
RT = (EFI_RUNTIME_SERVICES *)ClientInterface; | ||
|
||
Status = PlatformResetAttackMitigationPsciTestSub1 (RT, StandardLib, LoggingLib); | ||
|
||
return EFI_SUCCESS; | ||
} | ||
|
||
// | ||
// Platform Reset Attack Mitigation Psci Test | ||
// | ||
EFI_STATUS | ||
PlatformResetAttackMitigationPsciTestSub1 ( | ||
IN EFI_RUNTIME_SERVICES *RT, | ||
IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, | ||
IN EFI_TEST_LOGGING_LIBRARY_PROTOCOL *LoggingLib | ||
) | ||
{ | ||
EFI_STATUS Status; | ||
UINT32 Index; | ||
UINT32 Attribute; | ||
UINTN DataSize; | ||
VOID *Data; | ||
EFI_TEST_ASSERTION Result = EFI_TEST_ASSERTION_PASSED; | ||
|
||
// | ||
// Trace ... | ||
// | ||
if (LoggingLib != NULL) { | ||
LoggingLib->EnterFunction ( | ||
LoggingLib, | ||
L"PlatformResetAttackMitigationPsciTestSub1", | ||
L"BBSR R310" | ||
); | ||
} | ||
|
||
// PSCI MEM_PROTECT check | ||
SmcArgs.Arg0 = ARM_SMC_ID_PSCI_PSCI_FEATURES; | ||
SmcArgs.Arg1 = ARM_SMC_ID_PSCI_MEM_PROTECT; | ||
|
||
ArmCallSmc(&SmcArgs); | ||
|
||
StandardLib->RecordMessage ( | ||
StandardLib, | ||
EFI_VERBOSE_LEVEL_DEFAULT, | ||
L"\r\nPSCI feature return value = %x", | ||
SmcArgs.Arg0 | ||
); | ||
|
||
// If MEM_PROTECT function is implemented, PSCI_FEATURES returns a value of 0. | ||
if (SmcArgs.Arg0 == 0) | ||
Result = EFI_TEST_ASSERTION_PASSED; | ||
else | ||
Result = EFI_TEST_ASSERTION_FAILED; | ||
|
||
StandardLib->RecordAssertion ( | ||
StandardLib, | ||
Result, | ||
gPlatformResetAttackMitigationPsciBbTestAssertionGuid001, | ||
L"Platfrom Reset Attack prevention support via PSCI", | ||
L"%a:%d:", | ||
__FILE__, | ||
(UINTN)__LINE__ | ||
); | ||
|
||
// | ||
// Trace ... | ||
// | ||
if (LoggingLib != NULL) { | ||
LoggingLib->ExitFunction ( | ||
LoggingLib, | ||
L"PlatformResetAttackMitigationPsciTestSub1", | ||
L"BBSR R310" | ||
); | ||
} | ||
|
||
// | ||
// Done | ||
// | ||
return EFI_SUCCESS; | ||
} | ||
|
Oops, something went wrong.