[SRU][BIONIC][PATCH 11/16] UBUNTU: SAUCE: integrity: Load mokx certs from the EFI MOK config table
Dimitri John Ledkov
dimitri.ledkov at canonical.com
Tue Nov 30 11:04:11 UTC 2021
Refactor load_moklist_certs() to load either MokListRT into db, or
MokListXRT into dbx. Call load_moklist_certs() twice - first to load
mokx certs into dbx, then mok certs into db.
This thus now attempts to load mokx certs via the EFI MOKvar config
table first, and if that fails, via the EFI variable. Previously mokx
certs were only loaded via the EFI variable. Which fails when
MokListXRT is large. Instead of large MokListXRT variable, only
MokListXRT{1,2,3} are available which are not loaded. This is the case
with Ubuntu's 15.4 based shim. This patch is required to address
CVE-2020-26541 when certificates are revoked via MokListXRT.
Fixes: ebd9c2ae369a ("integrity: Load mokx variables into the blacklist keyring")
BugLink: https://bugs.launchpad.net/bugs/1928679
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov at canonical.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski at canonical.com>
Signed-off-by: Seth Forshee <seth.forshee at canonical.com>
(cherry picked from commit a9e3aae16235d6af12509a64f1337da4485ccbae)
(xnox: cherry-pick is from impish:linux SAUCE)
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov at canonical.com>
---
certs/load_uefi.c | 54 +++++++++++++++++++++++++++++++++--------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/certs/load_uefi.c b/certs/load_uefi.c
index 6f51c48be9..a99e7563d0 100644
--- a/certs/load_uefi.c
+++ b/certs/load_uefi.c
@@ -144,55 +144,70 @@ static __init efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_ty
}
/*
- * load_moklist_certs() - Load MokList certs
+ * load_moklist_certs() - Load Mok(X)List certs
+ * @load_db: Load MokListRT into db when true; MokListXRT into dbx when false
*
- * Load the certs contained in the UEFI MokListRT database into the
- * platform trusted keyring.
+ * Load the certs contained in the UEFI MokList(X)RT database into the
+ * platform trusted/denied keyring.
*
* This routine checks the EFI MOK config table first. If and only if
- * that fails, this routine uses the MokListRT ordinary UEFI variable.
+ * that fails, this routine uses the MokList(X)RT ordinary UEFI variable.
*
* Return: Status
*/
-static int __init load_moklist_certs(void)
+static int __init load_moklist_certs(const bool load_db)
{
struct efi_mokvar_table_entry *mokvar_entry;
efi_guid_t mok_var = EFI_SHIM_LOCK_GUID;
void *mok;
unsigned long moksize;
int rc;
+ const char *mokvar_name = "MokListRT";
+ /* Should be const, but get_cert_list() doesn't have it as const yet */
+ efi_char16_t *efivar_name = L"MokListRT";
+ const char *parse_mokvar_name = "UEFI:MokListRT (MOKvar table)";
+ const char *parse_efivar_name = "UEFI:MokListRT";
+ efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *) = get_handler_for_db;
+
+ if (!load_db) {
+ mokvar_name = "MokListXRT";
+ efivar_name = L"MokListXRT";
+ parse_mokvar_name = "UEFI:MokListXRT (MOKvar table)";
+ parse_efivar_name = "UEFI:MokListXRT";
+ get_handler_for_guid = get_handler_for_dbx;
+ }
/* First try to load certs from the EFI MOKvar config table.
* It's not an error if the MOKvar config table doesn't exist
* or the MokListRT entry is not found in it.
*/
- mokvar_entry = efi_mokvar_entry_find("MokListRT");
+ mokvar_entry = efi_mokvar_entry_find(mokvar_name);
if (mokvar_entry) {
- rc = parse_efi_signature_list("UEFI:MokListRT (MOKvar table)",
+ rc = parse_efi_signature_list(parse_mokvar_name,
mokvar_entry->data,
mokvar_entry->data_size,
- get_handler_for_db);
+ get_handler_for_guid);
/* All done if that worked. */
if (!rc)
return rc;
- pr_err("Couldn't parse MokListRT signatures from EFI MOKvar config table: %d\n",
- rc);
+ pr_err("Couldn't parse %s signatures from EFI MOKvar config table: %d\n",
+ mokvar_name, rc);
}
/* 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);
+ mok = get_cert_list(efivar_name, &mok_var, &moksize);
if (mok) {
- rc = parse_efi_signature_list("UEFI:MokListRT",
- mok, moksize, get_handler_for_db);
+ rc = parse_efi_signature_list(parse_efivar_name,
+ mok, moksize, get_handler_for_guid);
kfree(mok);
if (rc)
- pr_err("Couldn't parse MokListRT signatures: %d\n", rc);
+ pr_err("Couldn't parse %s signatures: %d\n", mokvar_name, rc);
return rc;
} else
- pr_info("Couldn't get UEFI MokListRT\n");
+ pr_info("Couldn't get UEFI %s\n", mokvar_name);
return 0;
}
@@ -242,8 +257,15 @@ static int __init load_uefi_certs(void)
kfree(dbx);
}
+ /* Load the MokListXRT certs */
+ rc = load_moklist_certs(false);
+ if (rc)
+ pr_err("Couldn't parse mokx signatures: %d\n", rc);
+
/* Load the MokListRT certs */
- rc = load_moklist_certs();
+ rc = load_moklist_certs(true);
+ if (rc)
+ pr_err("Couldn't parse mok signatures: %d\n", rc);
return rc;
}
--
2.32.0
More information about the kernel-team
mailing list