Implement BlGetRandomValue() and BlInitializeEntropy() routines for future KASLR support
This commit is contained in:
parent
f9714a79e4
commit
632bb30b64
@ -68,8 +68,10 @@ typedef EFI_STATUS (*PBL_GET_CONFIGURATION_TABLE)(IN PEFI_GUID TableGuid, OUT PV
|
|||||||
typedef VOID (*PBL_GET_MAPPINGS_COUNT)(IN PXTBL_PAGE_MAPPING PageMap, OUT PULONG NumberOfMappings);
|
typedef VOID (*PBL_GET_MAPPINGS_COUNT)(IN PXTBL_PAGE_MAPPING PageMap, OUT PULONG NumberOfMappings);
|
||||||
typedef EFI_STATUS (*PBL_GET_MEMORY_MAP)(OUT PEFI_MEMORY_MAP MemoryMap);
|
typedef EFI_STATUS (*PBL_GET_MEMORY_MAP)(OUT PEFI_MEMORY_MAP MemoryMap);
|
||||||
typedef PLIST_ENTRY (*PBL_GET_MODULES_LIST)();
|
typedef PLIST_ENTRY (*PBL_GET_MODULES_LIST)();
|
||||||
|
typedef ULONGLONG (*PBL_GET_RANDOM_VALUE)(IN OUT PULONGLONG RNGBuffer);
|
||||||
typedef INT_PTR (*PBL_GET_SECURE_BOOT_STATUS)();
|
typedef INT_PTR (*PBL_GET_SECURE_BOOT_STATUS)();
|
||||||
typedef PVOID (*PBL_GET_VIRTUAL_ADDRESS)(IN PXTBL_PAGE_MAPPING PageMap, IN PVOID PhysicalAddress);
|
typedef PVOID (*PBL_GET_VIRTUAL_ADDRESS)(IN PXTBL_PAGE_MAPPING PageMap, IN PVOID PhysicalAddress);
|
||||||
|
typedef EFI_STATUS (*PBL_INITIALIZE_ENTROPY)(PULONGLONG RNGBuffer);
|
||||||
typedef VOID (*PBL_INITIALIZE_PAGE_MAP)(OUT PXTBL_PAGE_MAPPING PageMap, IN SHORT PageMapLevel, IN PAGE_SIZE PageSize);
|
typedef VOID (*PBL_INITIALIZE_PAGE_MAP)(OUT PXTBL_PAGE_MAPPING PageMap, IN SHORT PageMapLevel, IN PAGE_SIZE PageSize);
|
||||||
typedef EFI_STATUS (*PBL_INSTALL_XT_PROTOCOL)(IN PVOID Interface, IN PEFI_GUID Guid);
|
typedef EFI_STATUS (*PBL_INSTALL_XT_PROTOCOL)(IN PVOID Interface, IN PEFI_GUID Guid);
|
||||||
typedef EFI_STATUS (*PBL_INVOKE_BOOT_PROTOCOL)(IN PLIST_ENTRY OptionsList);
|
typedef EFI_STATUS (*PBL_INVOKE_BOOT_PROTOCOL)(IN PLIST_ENTRY OptionsList);
|
||||||
@ -375,7 +377,9 @@ typedef struct _XTBL_LOADER_PROTOCOL
|
|||||||
{
|
{
|
||||||
PBL_EXIT_BOOT_SERVICES ExitBootServices;
|
PBL_EXIT_BOOT_SERVICES ExitBootServices;
|
||||||
PBL_GET_CONFIGURATION_TABLE GetConfigurationTable;
|
PBL_GET_CONFIGURATION_TABLE GetConfigurationTable;
|
||||||
|
PBL_GET_RANDOM_VALUE GetRandomValue;
|
||||||
PBL_GET_SECURE_BOOT_STATUS GetSecureBootStatus;
|
PBL_GET_SECURE_BOOT_STATUS GetSecureBootStatus;
|
||||||
|
PBL_INITIALIZE_ENTROPY InitializeEntropy;
|
||||||
PBL_LOAD_EFI_IMAGE LoadEfiImage;
|
PBL_LOAD_EFI_IMAGE LoadEfiImage;
|
||||||
PBL_POWER_SYSTEM RebootSystem;
|
PBL_POWER_SYSTEM RebootSystem;
|
||||||
PBL_POWER_SYSTEM ShutdownSystem;
|
PBL_POWER_SYSTEM ShutdownSystem;
|
||||||
|
@ -103,6 +103,31 @@ BlGetConfigurationTable(IN PEFI_GUID TableGuid,
|
|||||||
return STATUS_EFI_NOT_FOUND;
|
return STATUS_EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random value based on the initialized RNG buffer.
|
||||||
|
*
|
||||||
|
* @param RNGBuffer
|
||||||
|
* Supplies a pointer to the RNG buffer.
|
||||||
|
*
|
||||||
|
* @return This routine returns a random value.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*
|
||||||
|
* @see https://en.wikipedia.org/wiki/Xorshift
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
ULONGLONG
|
||||||
|
BlGetRandomValue(IN OUT PULONGLONG RNGBuffer)
|
||||||
|
{
|
||||||
|
/* Recalculate RNG buffer with XORSHIFT */
|
||||||
|
*RNGBuffer ^= *RNGBuffer >> 12;
|
||||||
|
*RNGBuffer ^= *RNGBuffer << 25;
|
||||||
|
*RNGBuffer ^= *RNGBuffer >> 27;
|
||||||
|
|
||||||
|
/* Return random value */
|
||||||
|
return *RNGBuffer * 0x2545F4914F6CDD1D;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether SecureBoot is enabled or not.
|
* Checks whether SecureBoot is enabled or not.
|
||||||
*
|
*
|
||||||
@ -136,6 +161,50 @@ BlGetSecureBootStatus()
|
|||||||
return SecureBootStatus;
|
return SecureBootStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the RNG buffer with random bytes from the default EFI RNG algorithm.
|
||||||
|
*
|
||||||
|
* @param RNGBuffer
|
||||||
|
* Supplies a pointer to the RNG buffer.
|
||||||
|
*
|
||||||
|
* @return This routine returns a status code.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
EFI_STATUS
|
||||||
|
BlInitializeEntropy(PULONGLONG RNGBuffer)
|
||||||
|
{
|
||||||
|
EFI_GUID RngGuid = EFI_RNG_PROTOCOL_GUID;
|
||||||
|
PEFI_RNG_PROTOCOL Rng;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
ULONGLONG Seed;
|
||||||
|
|
||||||
|
/* Initialize variables */
|
||||||
|
Rng = NULL;
|
||||||
|
Seed = 0;
|
||||||
|
|
||||||
|
/* Locate RNG protocol */
|
||||||
|
Status = EfiSystemTable->BootServices->LocateProtocol(&RngGuid, NULL, (PVOID *)&Rng);
|
||||||
|
if(Status != STATUS_EFI_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Failed to locate RNG protocol, return status code */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get RNG value using the default algorithm */
|
||||||
|
Status = Rng->GetRNG(Rng, NULL, 8, (PUCHAR)&Seed);
|
||||||
|
if(Status != STATUS_EFI_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Failed to get RNG value, return status code */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize RNG state and return success */
|
||||||
|
*RNGBuffer = Seed ? Seed : 1;
|
||||||
|
return STATUS_EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an EFI image into memory.
|
* Loads an EFI image into memory.
|
||||||
*
|
*
|
||||||
|
@ -150,6 +150,10 @@ XTCDECL
|
|||||||
PLIST_ENTRY
|
PLIST_ENTRY
|
||||||
BlGetModulesList();
|
BlGetModulesList();
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
ULONGLONG
|
||||||
|
BlGetRandomValue(IN OUT PULONGLONG RNGBuffer);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
INT_PTR
|
INT_PTR
|
||||||
BlGetSecureBootStatus();
|
BlGetSecureBootStatus();
|
||||||
@ -180,6 +184,10 @@ XTCDECL
|
|||||||
VOID
|
VOID
|
||||||
BlInitializeConsole();
|
BlInitializeConsole();
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
EFI_STATUS
|
||||||
|
BlInitializeEntropy(PULONGLONG RNGBuffer);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
VOID
|
VOID
|
||||||
BlInitializePageMap(OUT PXTBL_PAGE_MAPPING PageMap,
|
BlInitializePageMap(OUT PXTBL_PAGE_MAPPING PageMap,
|
||||||
|
@ -654,7 +654,9 @@ BlpInstallXtLoaderProtocol()
|
|||||||
BlpLdrProtocol.Tui.UpdateProgressBar = BlUpdateProgressBar;
|
BlpLdrProtocol.Tui.UpdateProgressBar = BlUpdateProgressBar;
|
||||||
BlpLdrProtocol.Util.ExitBootServices = BlExitBootServices;
|
BlpLdrProtocol.Util.ExitBootServices = BlExitBootServices;
|
||||||
BlpLdrProtocol.Util.GetConfigurationTable = BlGetConfigurationTable;
|
BlpLdrProtocol.Util.GetConfigurationTable = BlGetConfigurationTable;
|
||||||
|
BlpLdrProtocol.Util.GetRandomValue = BlGetRandomValue;
|
||||||
BlpLdrProtocol.Util.GetSecureBootStatus = BlGetSecureBootStatus;
|
BlpLdrProtocol.Util.GetSecureBootStatus = BlGetSecureBootStatus;
|
||||||
|
BlpLdrProtocol.Util.InitializeEntropy = BlInitializeEntropy;
|
||||||
BlpLdrProtocol.Util.LoadEfiImage = BlLoadEfiImage;
|
BlpLdrProtocol.Util.LoadEfiImage = BlLoadEfiImage;
|
||||||
BlpLdrProtocol.Util.RebootSystem = BlRebootSystem;
|
BlpLdrProtocol.Util.RebootSystem = BlRebootSystem;
|
||||||
BlpLdrProtocol.Util.ShutdownSystem = BlShutdownSystem;
|
BlpLdrProtocol.Util.ShutdownSystem = BlShutdownSystem;
|
||||||
|
Loading…
Reference in New Issue
Block a user