Skip to content

Commit 3be54d5

Browse files
martinezjaviermimizohar
authored andcommitted
efi: Only print errors about failing to get certs if EFI vars are found
If CONFIG_LOAD_UEFI_KEYS is enabled, the kernel attempts to load the certs from the db, dbx and MokListRT EFI variables into the appropriate keyrings. But it just assumes that the variables will be present and prints an error if the certs can't be loaded, even when is possible that the variables may not exist. For example the MokListRT variable will only be present if shim is used. So only print an error message about failing to get the certs list from an EFI variable if this is found. Otherwise these printed errors just pollute the kernel log ring buffer with confusing messages like the following: [ 5.427251] Couldn't get size: 0x800000000000000e [ 5.427261] MODSIGN: Couldn't get UEFI db list [ 5.428012] Couldn't get size: 0x800000000000000e [ 5.428023] Couldn't get UEFI MokListRT Reported-by: Hans de Goede <[email protected]> Signed-off-by: Javier Martinez Canillas <[email protected]> Tested-by: Hans de Goede <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Signed-off-by: Mimi Zohar <[email protected]>
1 parent ff5ac61 commit 3be54d5

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

security/integrity/platform_certs/load_uefi.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,29 @@ static __init bool uefi_check_ignore_db(void)
3535
* Get a certificate list blob from the named EFI variable.
3636
*/
3737
static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
38-
unsigned long *size)
38+
unsigned long *size, efi_status_t *status)
3939
{
40-
efi_status_t status;
4140
unsigned long lsize = 4;
4241
unsigned long tmpdb[4];
4342
void *db;
4443

45-
status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb);
46-
if (status != EFI_BUFFER_TOO_SMALL) {
47-
pr_err("Couldn't get size: 0x%lx\n", status);
44+
*status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb);
45+
if (*status == EFI_NOT_FOUND)
46+
return NULL;
47+
48+
if (*status != EFI_BUFFER_TOO_SMALL) {
49+
pr_err("Couldn't get size: 0x%lx\n", *status);
4850
return NULL;
4951
}
5052

5153
db = kmalloc(lsize, GFP_KERNEL);
5254
if (!db)
5355
return NULL;
5456

55-
status = efi.get_variable(name, guid, NULL, &lsize, db);
56-
if (status != EFI_SUCCESS) {
57+
*status = efi.get_variable(name, guid, NULL, &lsize, db);
58+
if (*status != EFI_SUCCESS) {
5759
kfree(db);
58-
pr_err("Error reading db var: 0x%lx\n", status);
60+
pr_err("Error reading db var: 0x%lx\n", *status);
5961
return NULL;
6062
}
6163

@@ -74,6 +76,7 @@ static int __init load_uefi_certs(void)
7476
efi_guid_t mok_var = EFI_SHIM_LOCK_GUID;
7577
void *db = NULL, *dbx = NULL, *mok = NULL;
7678
unsigned long dbsize = 0, dbxsize = 0, moksize = 0;
79+
efi_status_t status;
7780
int rc = 0;
7881

7982
if (!efi.get_variable)
@@ -83,9 +86,12 @@ static int __init load_uefi_certs(void)
8386
* an error if we can't get them.
8487
*/
8588
if (!uefi_check_ignore_db()) {
86-
db = get_cert_list(L"db", &secure_var, &dbsize);
89+
db = get_cert_list(L"db", &secure_var, &dbsize, &status);
8790
if (!db) {
88-
pr_err("MODSIGN: Couldn't get UEFI db list\n");
91+
if (status == EFI_NOT_FOUND)
92+
pr_debug("MODSIGN: db variable wasn't found\n");
93+
else
94+
pr_err("MODSIGN: Couldn't get UEFI db list\n");
8995
} else {
9096
rc = parse_efi_signature_list("UEFI:db",
9197
db, dbsize, get_handler_for_db);
@@ -96,9 +102,12 @@ static int __init load_uefi_certs(void)
96102
}
97103
}
98104

99-
mok = get_cert_list(L"MokListRT", &mok_var, &moksize);
105+
mok = get_cert_list(L"MokListRT", &mok_var, &moksize, &status);
100106
if (!mok) {
101-
pr_info("Couldn't get UEFI MokListRT\n");
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");
102111
} else {
103112
rc = parse_efi_signature_list("UEFI:MokListRT",
104113
mok, moksize, get_handler_for_db);
@@ -107,9 +116,12 @@ static int __init load_uefi_certs(void)
107116
kfree(mok);
108117
}
109118

110-
dbx = get_cert_list(L"dbx", &secure_var, &dbxsize);
119+
dbx = get_cert_list(L"dbx", &secure_var, &dbxsize, &status);
111120
if (!dbx) {
112-
pr_info("Couldn't get UEFI dbx list\n");
121+
if (status == EFI_NOT_FOUND)
122+
pr_debug("dbx variable wasn't found\n");
123+
else
124+
pr_info("Couldn't get UEFI dbx list\n");
113125
} else {
114126
rc = parse_efi_signature_list("UEFI:dbx",
115127
dbx, dbxsize,

0 commit comments

Comments
 (0)