Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions arch/x86/configs/common.fragment
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,28 @@ CONFIG_NETFILTER_XT_NAT=y
CONFIG_NETFILTER_XT_TARGET_MASQUERADE=y
CONFIG_NETFILTER_XT_TARGET_REDIRECT=y
CONFIG_NETFILTER_XT_TARGET_NETMAP=y

# Secure Boot (two-stage GRUB, db + GPG): dm-verity root hash signatures
# checked against the platform keyring (UEFI db), lockdown forced to
# integrity, and kexec limited to signed images. PLATFORM_KEYRING is set
# explicitly because its default follows the SECONDARY_KEYRING choice.
# SIGNED_PE_FILE_VERIFICATION is what KEXEC_BZIMAGE_VERIFY_SIG depends on;
# without a verifier, KEXEC_SIG_FORCE rejects every kexec.
CONFIG_DM_VERITY=y
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y
CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING=y
CONFIG_INTEGRITY_SIGNATURE=y
CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y
CONFIG_INTEGRITY_PLATFORM_KEYRING=y
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY=y
CONFIG_SIGNED_PE_FILE_VERIFICATION=y
CONFIG_KEXEC_SIG=y
CONFIG_KEXEC_SIG_FORCE=y
CONFIG_KEXEC_BZIMAGE_VERIFY_SIG=y

# efi-pstore built in, not a module: a panic in the initrd (dm-verity root
# hash rejected) happens before any module loads and must still be recorded.
CONFIG_PSTORE=y
CONFIG_EFI_VARS_PSTORE=y
5 changes: 5 additions & 0 deletions arch/x86/configs/rt.fragment
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ CONFIG_RCU_NOCB_CPU=y
CONFIG_RCU_NOCB_CPU_CB_BOOST=y
# CONFIG_RCU_NOCB_CPU_DEFAULT_ALL is not set
CONFIG_VIRT_CPU_ACCOUNTING=y
# EFI_DISABLE_RUNTIME defaults to y under PREEMPT_RT. Secure Boot needs EFI
# runtime services: the kernel reads db into the .platform keyring that
# dm-verity root hash and kexec signatures are checked against, and
# efi-pstore stores panic records in EFI variables.
# CONFIG_EFI_DISABLE_RUNTIME is not set
45 changes: 36 additions & 9 deletions security/integrity/platform_certs/load_uefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ static const struct dmi_system_id uefi_skip_cert[] = {
{ }
};

/*
* shim creates MokListRT, MokListXRT and MokIgnoreDB as volatile variables on
* every boot. A non-volatile variable with one of these names was written by
* an OS, not by shim, and must not decide which keys the kernel trusts.
*/
static __init bool shim_volatile(const char *name, u32 attr)
{
if (!(attr & EFI_VARIABLE_NON_VOLATILE))
return true;
pr_warn("Ignoring non-volatile %s, which shim did not create\n", name);
return false;
}

/*
* Look to see if a UEFI variable called MokIgnoreDB exists and return true if
* it does.
Expand All @@ -54,16 +67,19 @@ static __init bool uefi_check_ignore_db(void)
unsigned int db = 0;
unsigned long size = sizeof(db);
efi_guid_t guid = EFI_SHIM_LOCK_GUID;
u32 attr = 0;

status = efi.get_variable(L"MokIgnoreDB", &guid, NULL, &size, &db);
return status == EFI_SUCCESS;
status = efi.get_variable(L"MokIgnoreDB", &guid, &attr, &size, &db);
return status == EFI_SUCCESS && shim_volatile("MokIgnoreDB", attr);
}

/*
* Get a certificate list blob from the named EFI variable.
* Get a certificate list blob from the named EFI variable, and its attributes
* in *attr if attr is not NULL.
*/
static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
unsigned long *size, efi_status_t *status)
unsigned long *size, efi_status_t *status,
u32 *attr)
{
unsigned long lsize = 4;
unsigned long tmpdb[4];
Expand All @@ -82,7 +98,7 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
if (!db)
return NULL;

*status = efi.get_variable(name, guid, NULL, &lsize, db);
*status = efi.get_variable(name, guid, attr, &lsize, db);
if (*status != EFI_SUCCESS) {
kfree(db);
pr_err("Error reading db var: 0x%lx\n", *status);
Expand Down Expand Up @@ -111,6 +127,7 @@ static int __init load_moklist_certs(void)
void *mok;
unsigned long moksize;
efi_status_t status;
u32 attr = 0;
int rc;

/* First try to load certs from the EFI MOKvar config table.
Expand All @@ -134,7 +151,11 @@ static int __init load_moklist_certs(void)
/* Get MokListRT. It might not exist, so it isn't an error
* if we can't get it.
*/
mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status);
mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status, &attr);
if (mok && !shim_volatile("MokListRT", attr)) {
kfree(mok);
return 0;
}
if (mok) {
rc = parse_efi_signature_list("UEFI:MokListRT",
mok, moksize, get_handler_for_mok);
Expand Down Expand Up @@ -164,6 +185,7 @@ static int __init load_uefi_certs(void)
void *db = NULL, *dbx = NULL, *mokx = NULL;
unsigned long dbsize = 0, dbxsize = 0, mokxsize = 0;
efi_status_t status;
u32 attr = 0;
int rc = 0;
const struct dmi_system_id *dmi_id;

Expand All @@ -180,7 +202,7 @@ static int __init load_uefi_certs(void)
* if we can't get them.
*/
if (!uefi_check_ignore_db()) {
db = get_cert_list(L"db", &secure_var, &dbsize, &status);
db = get_cert_list(L"db", &secure_var, &dbsize, &status, NULL);
if (!db) {
if (status == EFI_NOT_FOUND)
pr_debug("MODSIGN: db variable wasn't found\n");
Expand All @@ -196,7 +218,7 @@ static int __init load_uefi_certs(void)
}
}

dbx = get_cert_list(L"dbx", &secure_var, &dbxsize, &status);
dbx = get_cert_list(L"dbx", &secure_var, &dbxsize, &status, NULL);
if (!dbx) {
if (status == EFI_NOT_FOUND)
pr_debug("dbx variable wasn't found\n");
Expand All @@ -215,7 +237,12 @@ static int __init load_uefi_certs(void)
if (!arch_get_secureboot())
return 0;

mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, &status);
mokx = get_cert_list(L"MokListXRT", &mok_var, &mokxsize, &status, &attr);
if (mokx && !shim_volatile("MokListXRT", attr)) {
kfree(mokx);
mokx = NULL;
status = EFI_NOT_FOUND;
}
if (!mokx) {
if (status == EFI_NOT_FOUND)
pr_debug("mokx variable wasn't found\n");
Expand Down