Skip to content

Commit 38a1f03

Browse files
LennySzubowiczardbiesheuvel
authored andcommitted
integrity: Move import of MokListRT certs to a separate routine
Move the loading of certs from the UEFI MokListRT into a separate routine to facilitate additional MokList functionality. There is no visible functional change as a result of this patch. Although the UEFI dbx certs are now loaded before the MokList certs, they are loaded onto different key rings. So the order of the keys on their respective key rings is the same. Signed-off-by: Lenny Szubowicz <lszubowi@redhat.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Link: https://lore.kernel.org/r/20200905013107.10457-3-lszubowi@redhat.com Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 58c9090 commit 38a1f03

1 file changed

Lines changed: 44 additions & 19 deletions

File tree

security/integrity/platform_certs/load_uefi.c

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,60 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
6666
}
6767

6868
/*
69+
* load_moklist_certs() - Load MokList certs
70+
*
71+
* Load the certs contained in the UEFI MokListRT database into the
72+
* platform trusted keyring.
73+
*
74+
* Return: Status
75+
*/
76+
static int __init load_moklist_certs(void)
77+
{
78+
efi_guid_t mok_var = EFI_SHIM_LOCK_GUID;
79+
void *mok;
80+
unsigned long moksize;
81+
efi_status_t status;
82+
int rc;
83+
84+
/* Get MokListRT. It might not exist, so it isn't an error
85+
* if we can't get it.
86+
*/
87+
mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status);
88+
if (mok) {
89+
rc = parse_efi_signature_list("UEFI:MokListRT",
90+
mok, moksize, get_handler_for_db);
91+
kfree(mok);
92+
if (rc)
93+
pr_err("Couldn't parse MokListRT signatures: %d\n", rc);
94+
return rc;
95+
}
96+
if (status == EFI_NOT_FOUND)
97+
pr_debug("MokListRT variable wasn't found\n");
98+
else
99+
pr_info("Couldn't get UEFI MokListRT\n");
100+
return 0;
101+
}
102+
103+
/*
104+
* load_uefi_certs() - Load certs from UEFI sources
105+
*
69106
* Load the certs contained in the UEFI databases into the platform trusted
70107
* keyring and the UEFI blacklisted X.509 cert SHA256 hashes into the blacklist
71108
* keyring.
72109
*/
73110
static int __init load_uefi_certs(void)
74111
{
75112
efi_guid_t secure_var = EFI_IMAGE_SECURITY_DATABASE_GUID;
76-
efi_guid_t mok_var = EFI_SHIM_LOCK_GUID;
77-
void *db = NULL, *dbx = NULL, *mok = NULL;
78-
unsigned long dbsize = 0, dbxsize = 0, moksize = 0;
113+
void *db = NULL, *dbx = NULL;
114+
unsigned long dbsize = 0, dbxsize = 0;
79115
efi_status_t status;
80116
int rc = 0;
81117

82118
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
83119
return false;
84120

85-
/* Get db, MokListRT, and dbx. They might not exist, so it isn't
86-
* an error if we can't get them.
121+
/* Get db and dbx. They might not exist, so it isn't an error
122+
* if we can't get them.
87123
*/
88124
if (!uefi_check_ignore_db()) {
89125
db = get_cert_list(L"db", &secure_var, &dbsize, &status);
@@ -102,20 +138,6 @@ static int __init load_uefi_certs(void)
102138
}
103139
}
104140

105-
mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status);
106-
if (!mok) {
107-
if (status == EFI_NOT_FOUND)
108-
pr_debug("MokListRT variable wasn't found\n");
109-
else
110-
pr_info("Couldn't get UEFI MokListRT\n");
111-
} else {
112-
rc = parse_efi_signature_list("UEFI:MokListRT",
113-
mok, moksize, get_handler_for_db);
114-
if (rc)
115-
pr_err("Couldn't parse MokListRT signatures: %d\n", rc);
116-
kfree(mok);
117-
}
118-
119141
dbx = get_cert_list(L"dbx", &secure_var, &dbxsize, &status);
120142
if (!dbx) {
121143
if (status == EFI_NOT_FOUND)
@@ -131,6 +153,9 @@ static int __init load_uefi_certs(void)
131153
kfree(dbx);
132154
}
133155

156+
/* Load the MokListRT certs */
157+
rc = load_moklist_certs();
158+
134159
return rc;
135160
}
136161
late_initcall(load_uefi_certs);

0 commit comments

Comments
 (0)