提交 f545a348 编写于 作者: G Goldfish64

OpenCoreKernel: Block cache types via ForceKernelCache option

上级 5ea680a0
......@@ -87,10 +87,43 @@
#define PLIST_EXPANSION_SIZE 512
//
// Make integral kernel version.
// Make integral kernel version (major, minor, revision).
//
#define KERNEL_VERSION(A, B, C) ((A) * 10000 + (B) * 100 + (C))
//
// Minimum kernel versions for each release.
//
#define KERNEL_VERSION_TIGER_MIN KERNEL_VERSION (8, 0, 0)
#define KERNEL_VERSION_LEOPARD_MIN KERNEL_VERSION (9, 0, 0)
#define KERNEL_VERSION_SNOW_LEOPARD_MIN KERNEL_VERSION (10, 0, 0)
#define KERNEL_VERSION_LION_MIN KERNEL_VERSION (11, 0, 0)
#define KERNEL_VERSION_MOUNTAIN_LION_MIN KERNEL_VERSION (12, 0, 0)
#define KERNEL_VERSION_MAVERICKS_MIN KERNEL_VERSION (13, 0, 0)
#define KERNEL_VERSION_YOSEMITE_MIN KERNEL_VERSION (14, 0, 0)
#define KERNEL_VERSION_EL_CAPITAN_MIN KERNEL_VERSION (15, 0, 0)
#define KERNEL_VERSION_SIERRA_MIN KERNEL_VERSION (16, 0, 0)
#define KERNEL_VERSION_HIGH_SIERRA_MIN KERNEL_VERSION (17, 0, 0)
#define KERNEL_VERSION_MOJAVE_MIN KERNEL_VERSION (18, 0, 0)
#define KERNEL_VERSION_CATALINA_MIN KERNEL_VERSION (19, 0, 0)
#define KERNEL_VERSION_BIG_SUR_MIN KERNEL_VERSION (20, 0, 0)
//
// Maximum kernel versions for each release.
//
#define KERNEL_VERSION_TIGER_MAX (KERNEL_VERSION_LEOPARD_MIN - 1)
#define KERNEL_VERSION_LEOPARD_MAX (KERNEL_VERSION_SNOW_LEOPARD_MIN - 1)
#define KERNEL_VERSION_SNOW_LEOPARD_MAX (KERNEL_VERSION_LION_MIN - 1)
#define KERNEL_VERSION_LION_MAX (KERNEL_VERSION_MOUNTAIN_LION_MIN - 1)
#define KERNEL_VERSION_MOUNTAIN_LION_MAX (KERNEL_VERSION_MAVERICKS_MIN - 1)
#define KERNEL_VERSION_MAVERICKS_MAX (KERNEL_VERSION_YOSEMITE_MIN - 1)
#define KERNEL_VERSION_YOSEMITE_MAX (KERNEL_VERSION_EL_CAPITAN_MIN - 1)
#define KERNEL_VERSION_EL_CAPITAN_MAX (KERNEL_VERSION_SIERRA_MIN - 1)
#define KERNEL_VERSION_SIERRA_MAX (KERNEL_VERSION_HIGH_SIERRA_MIN - 1)
#define KERNEL_VERSION_HIGH_SIERRA_MAX (KERNEL_VERSION_MOJAVE_MIN - 1)
#define KERNEL_VERSION_MOJAVE_MAX (KERNEL_VERSION_CATALINA_MIN - 1)
#define KERNEL_VERSION_CATALINA_MAX (KERNEL_VERSION_BIG_SUR_MIN - 1)
//
// Prelinked context used for kernel modification.
//
......
......@@ -247,6 +247,7 @@
_(BOOLEAN , DisableRtcChecksum , , FALSE , ()) \
_(BOOLEAN , DummyPowerManagement , , FALSE , ()) \
_(BOOLEAN , ExternalDiskIcons , , FALSE , ()) \
_(OC_STRING , ForceKernelCache , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
_(BOOLEAN , IncreasePciBarSize , , FALSE , ()) \
_(BOOLEAN , LapicKernelPanic , , FALSE , ()) \
_(BOOLEAN , PanicNoKextDump , , FALSE , ()) \
......@@ -483,7 +484,7 @@ typedef enum {
_(UINT64 , MinVersion , , 0 , ()) \
_(UINT32 , MinDate , , 0 , ()) \
_(BOOLEAN , EnableJumpstart , , FALSE , ()) \
_(BOOLEAN , GlobalConnect , , FALSE , ()) \
_(BOOLEAN , GlobalConnect , , FALSE , ()) \
_(BOOLEAN , HideVerbose , , FALSE , ()) \
_(BOOLEAN , JumpstartHotPlug , , FALSE , ())
OC_DECLARE (OC_UEFI_APFS)
......
......@@ -297,6 +297,7 @@ mKernelQuirksSchema[] = {
OC_SCHEMA_BOOLEAN_IN ("DisableRtcChecksum", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableRtcChecksum),
OC_SCHEMA_BOOLEAN_IN ("DummyPowerManagement", OC_GLOBAL_CONFIG, Kernel.Quirks.DummyPowerManagement),
OC_SCHEMA_BOOLEAN_IN ("ExternalDiskIcons", OC_GLOBAL_CONFIG, Kernel.Quirks.ExternalDiskIcons),
OC_SCHEMA_STRING_IN ("ForceKernelCache", OC_GLOBAL_CONFIG, Kernel.Quirks.ForceKernelCache),
OC_SCHEMA_BOOLEAN_IN ("IncreasePciBarSize", OC_GLOBAL_CONFIG, Kernel.Quirks.IncreasePciBarSize),
OC_SCHEMA_BOOLEAN_IN ("LapicKernelPanic", OC_GLOBAL_CONFIG, Kernel.Quirks.LapicKernelPanic),
OC_SCHEMA_BOOLEAN_IN ("PanicNoKextDump", OC_GLOBAL_CONFIG, Kernel.Quirks.PanicNoKextDump),
......
......@@ -819,6 +819,8 @@ OcKernelFileOpen (
)
{
EFI_STATUS Status;
CONST CHAR8 *ForceCacheType;
KERNEL_CACHE_TYPE MaxCacheTypeAllowed;
BOOLEAN Result;
UINT8 *Kernel;
UINT32 KernelSize;
......@@ -833,6 +835,18 @@ OcKernelFileOpen (
UINT32 LinkedExpansion;
UINT32 ReservedFullSize;
//
// Prevent access to cache files depending on maximum cache type allowed.
//
ForceCacheType = OC_BLOB_GET (&mOcConfiguration->Kernel.Quirks.ForceKernelCache);
if (AsciiStrCmp (ForceCacheType, "Cacheless") == 0) {
MaxCacheTypeAllowed = CacheTypeCacheless;
} else if (AsciiStrCmp (ForceCacheType, "Mkext") == 0) {
MaxCacheTypeAllowed = CacheTypeMkext;
} else {
MaxCacheTypeAllowed = CacheTypePrelinked;
}
//
// Hook injected OcXXXXXXXX.kext reads from /S/L/E.
//
......@@ -925,6 +939,21 @@ OcKernelFileOpen (
mOcDarwinVersion = OcKernelReadDarwinVersion (Kernel, KernelSize);
OcKernelApplyPatches (mOcConfiguration, mOcDarwinVersion, 0, NULL, Kernel, KernelSize);
//
// Disable prelinked if forcing mkext or cacheless, but only on appropriate versions.
//
if ((OcStriStr (FileName, L"kernelcache") != NULL || OcStriStr (FileName, L"prelinkedkernel") != NULL)
&& ((MaxCacheTypeAllowed == CacheTypeMkext && mOcDarwinVersion <= KERNEL_VERSION_SNOW_LEOPARD_MAX)
|| (MaxCacheTypeAllowed == CacheTypeCacheless && mOcDarwinVersion <= KERNEL_VERSION_MAVERICKS_MAX))) {
DEBUG ((DEBUG_INFO, "OC: Blocking prelinked due to ForceKernelCache=%s: %a\n", FileName, ForceCacheType));
FreePool (Kernel);
(*NewHandle)->Close(*NewHandle);
*NewHandle = NULL;
return EFI_NOT_FOUND;
}
PrelinkedStatus = OcKernelProcessPrelinked (
mOcConfiguration,
mOcDarwinVersion,
......@@ -974,6 +1003,17 @@ OcKernelFileOpen (
if (OpenMode == EFI_FILE_MODE_READ
&& OcStriStr (FileName, L"Extensions.mkext") != NULL) {
//
// Disable mkext booting if forcing cacheless.
//
if (MaxCacheTypeAllowed == CacheTypeCacheless) {
DEBUG ((DEBUG_INFO, "OC: Blocking mkext due to ForceKernelCache=%s: %a\n", FileName, ForceCacheType));
(*NewHandle)->Close(*NewHandle);
*NewHandle = NULL;
return EFI_NOT_FOUND;
}
OcKernelLoadKextsAndReserve (
mOcStorage,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册