OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
CustomSlide.c File Reference
#include "BootCompatInternal.h"
#include <Guid/AppleVariable.h>
#include <Guid/OcVariable.h>
#include <IndustryStandard/AppleHibernate.h>
#include <IndustryStandard/AppleCsrConfig.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcCryptoLib.h>
#include <Library/OcDeviceTreeLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcRngLib.h>
#include <Library/OcStringLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>

Go to the source code of this file.

Functions

STATIC VOID GetSlideRangeForValue (IN UINTN EstimatedKernelArea, IN BOOLEAN HasSandyOrIvy, IN UINT8 Slide, OUT UINTN *StartAddr, OUT UINTN *EndAddr)
 
STATIC UINT8 GenerateSlideValue (IN SLIDE_SUPPORT_STATE *SlideSupport)
 
STATIC BOOLEAN ShouldUseCustomSlideOffsetDecision (IN OUT SLIDE_SUPPORT_STATE *SlideSupport, IN UINT8 FallbackSlide, IN UINT64 MaxAvailableSize)
 
STATIC BOOLEAN ShouldUseCustomSlideOffset (IN OUT SLIDE_SUPPORT_STATE *SlideSupport, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL, IN OC_MEMORY_FILTER FilterMap OPTIONAL, IN VOID *FilterMapContext OPTIONAL, IN BOOLEAN HasSandyOrIvy)
 
STATIC EFI_STATUS GetVariableCsrActiveConfig (IN OUT SLIDE_SUPPORT_STATE *SlideSupport, IN EFI_GET_VARIABLE GetVariable, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data)
 
STATIC EFI_STATUS GetVariableBootArgs (IN OUT SLIDE_SUPPORT_STATE *SlideSupport, IN EFI_GET_VARIABLE GetVariable, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data)
 
STATIC VOID HideSlideFromOs (IN OUT SLIDE_SUPPORT_STATE *SlideSupport, IN OUT OC_BOOT_ARGUMENTS *BootArgs)
 
VOID AppleSlideUnlockForSafeMode (IN OUT UINT8 *ImageBase, IN UINTN ImageSize)
 
EFI_STATUS AppleSlideGetVariable (IN OUT BOOT_COMPAT_CONTEXT *BootCompat, IN EFI_GET_VARIABLE GetVariable, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL, IN OC_MEMORY_FILTER FilterMap OPTIONAL, IN VOID *FilterMapContext OPTIONAL, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data)
 
VOID AppleSlideRestore (IN OUT BOOT_COMPAT_CONTEXT *BootCompat, IN OUT OC_BOOT_ARGUMENTS *BootArgs)
 
UINTN AppleSlideGetRelocationSize (IN OUT BOOT_COMPAT_CONTEXT *BootCompat)
 

Detailed Description

Copyright (C) 2018, Downlod-Fritz. All rights reserved. Copyright (C) 2018, vit9696. All rights reserved.

All rights reserved.

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.

Definition in file CustomSlide.c.

Function Documentation

◆ AppleSlideGetRelocationSize()

UINTN AppleSlideGetRelocationSize ( IN OUT BOOT_COMPAT_CONTEXT * BootCompat)

Get calculated relocation block size for booting with slide=0 (e.g. Safe Mode) or without KASLR (older macOS) when it is otherwise impossible.

Parameters
[in,out]BootCompatBoot compatibility context.
Returns
Size of the relocation block (maximum).
Return values
0otherwise.

Definition at line 879 of file CustomSlide.c.

◆ AppleSlideGetVariable()

EFI_STATUS AppleSlideGetVariable ( IN OUT BOOT_COMPAT_CONTEXT * BootCompat,
IN EFI_GET_VARIABLE GetVariable,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
IN OC_MEMORY_FILTER FilterMap OPTIONAL,
IN VOID *FilterMapContext OPTIONAL,
IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN * DataSize,
OUT VOID * Data )

Primary custom KASLR support handler. This gets called on every UEFI RuntimeServices GetVariable call and thus is useful to perform KASLR slide injection through boot-args.

Parameters
[in,out]BootCompatBoot compatibility context.
[in]GetVariableOriginal UEFI GetVariable service.
[in]GetMemoryMapUnmodified GetMemoryMap pointer, optional.
[in]FilterMapGetMemoryMap result filter, optional.
[in]FilterMapContextFilterMap context, optional.
[in]VariableNameGetVariable variable name argument.
[in]VendorGuidGetVariable vendor GUID argument.
[out]AttributesGetVariable attributes argument.
[in,out]DataSizeGetVariable data size argument.
[out]DataGetVariable data argument.
Return values
GetVariablestatus code.

Definition at line 773 of file CustomSlide.c.

◆ AppleSlideRestore()

VOID AppleSlideRestore ( IN OUT BOOT_COMPAT_CONTEXT * BootCompat,
IN OUT OC_BOOT_ARGUMENTS * BootArgs )

Ensures that the original csr-active-config is passed to the kernel, and removes customised slide value for security reasons.

Parameters
[in,out]BootCompatBoot compatibility context.
[in,out]BootArgsApple kernel boot arguments.

Definition at line 849 of file CustomSlide.c.

◆ AppleSlideUnlockForSafeMode()

VOID AppleSlideUnlockForSafeMode ( IN OUT UINT8 * ImageBase,
IN UINTN ImageSize )

Patch boot.efi to support random and passed slide values in safe mode.

Parameters
[in,out]ImageBaseApple booter image base.
[in]ImageSizeApple booter image size.

Definition at line 609 of file CustomSlide.c.

◆ GenerateSlideValue()

STATIC UINT8 GenerateSlideValue ( IN SLIDE_SUPPORT_STATE * SlideSupport)

Generate more or less random slide value.

Parameters
[in]SlideSupportSlide support state.

Definition at line 78 of file CustomSlide.c.

◆ GetSlideRangeForValue()

STATIC VOID GetSlideRangeForValue ( IN UINTN EstimatedKernelArea,
IN BOOLEAN HasSandyOrIvy,
IN UINT8 Slide,
OUT UINTN * StartAddr,
OUT UINTN * EndAddr )

Obtain estimated kernel area start and end addresses for specified slide number.

Parameters
[in]EstimatedKernelAreaEstimated kernel area size.
[in]HasSandyOrIvyCPU type.
[in]SlideSlide number.
[out]StartAddrStarting address.
[out]EndAddrEnding address (not inclusive).

Definition at line 51 of file CustomSlide.c.

◆ GetVariableBootArgs()

STATIC EFI_STATUS GetVariableBootArgs ( IN OUT SLIDE_SUPPORT_STATE * SlideSupport,
IN EFI_GET_VARIABLE GetVariable,
IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN * DataSize,
OUT VOID * Data )

UEFI GetVariable override specific to boot-args. See caller for more details.

Parameters
[in,out]SlideSupportSlide support state.
[in]GetVariableOriginal UEFI GetVariable service.
[in]VariableNameGetVariable variable name argument.
[in]VendorGuidGetVariable vendor GUID argument.
[out]AttributesGetVariable attributes argument.
[in,out]DataSizeGetVariable data size argument.
[out]DataGetVariable data argument.
Return values
GetVariablestatus code.

Definition at line 482 of file CustomSlide.c.

◆ GetVariableCsrActiveConfig()

STATIC EFI_STATUS GetVariableCsrActiveConfig ( IN OUT SLIDE_SUPPORT_STATE * SlideSupport,
IN EFI_GET_VARIABLE GetVariable,
IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN * DataSize,
OUT VOID * Data )

UEFI GetVariable override specific to csr-active-config. See caller for more details.

Parameters
[in,out]SlideSupportSlide support state.
[in]GetVariableOriginal UEFI GetVariable service.
[in]VariableNameGetVariable variable name argument.
[in]VendorGuidGetVariable vendor GUID argument.
[out]AttributesGetVariable attributes argument.
[in,out]DataSizeGetVariable data size argument.
[out]DataGetVariable data argument.
Return values
GetVariablestatus code.

Definition at line 416 of file CustomSlide.c.

◆ HideSlideFromOs()

STATIC VOID HideSlideFromOs ( IN OUT SLIDE_SUPPORT_STATE * SlideSupport,
IN OUT OC_BOOT_ARGUMENTS * BootArgs )

Erases customised slide value from everywhere accessible for security purposes.

Parameters
[in,out]SlideSupportSlide support state.
[in,out]BootArgsApple kernel boot arguments.

Definition at line 572 of file CustomSlide.c.

◆ ShouldUseCustomSlideOffset()

STATIC BOOLEAN ShouldUseCustomSlideOffset ( IN OUT SLIDE_SUPPORT_STATE * SlideSupport,
IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL,
IN OC_MEMORY_FILTER FilterMap OPTIONAL,
IN VOID *FilterMapContext OPTIONAL,
IN BOOLEAN HasSandyOrIvy )

Return cached decision or perform memory map analysis to decide whether to use custom slide for reliable kernel booting or not.

Parameters
[in,out]SlideSupportSlide support state.
[in]GetMemoryMapFunction to get current memory map for analysis. optional.
[in]FilterMapFunction to filter returned memory map, optional.
[in]FilterMapContextFilter map context, optional.
Return values
TRUEin case custom slide is to be used.

Definition at line 227 of file CustomSlide.c.

◆ ShouldUseCustomSlideOffsetDecision()

STATIC BOOLEAN ShouldUseCustomSlideOffsetDecision ( IN OUT SLIDE_SUPPORT_STATE * SlideSupport,
IN UINT8 FallbackSlide,
IN UINT64 MaxAvailableSize )

Decide on whether to use custom slide based on memory map analysis. This additionally logs the decision through standard services.

Parameters
[in,out]SlideSupportSlide support state.
[in]FallbackSlideFallback slide number with largest area.
[in]MaxAvailableSizeMaximum available contiguous area.
Return values
TRUEin case custom slide is to be used.

Definition at line 110 of file CustomSlide.c.