diff --git a/include/mock-variables.h b/include/mock-variables.h index 3f282a68d..9f276e63c 100644 --- a/include/mock-variables.h +++ b/include/mock-variables.h @@ -122,6 +122,7 @@ typedef enum { DELETE, APPEND, REPLACE, + GET, } mock_variable_op_t; static inline const char * @@ -133,6 +134,7 @@ format_var_op(mock_variable_op_t op) "DELETE", "APPEND", "REPLACE", + "GET", NULL }; diff --git a/mok.c b/mok.c index 801379ee4..7755eea9b 100644 --- a/mok.c +++ b/mok.c @@ -828,30 +828,32 @@ EFI_STATUS import_one_mok_state(struct mok_state_variable *v, dprint(L"importing mok state for \"%s\"\n", v->name); - efi_status = get_variable_attr(v->name, - &v->data, &v->data_size, - *v->guid, &attrs); - if (efi_status == EFI_NOT_FOUND) { - v->data = NULL; - v->data_size = 0; - } else if (EFI_ERROR(efi_status)) { - perror(L"Could not verify %s: %r\n", v->name, - efi_status); - delete = TRUE; - } else { - if (!(attrs & v->yes_attr)) { - perror(L"Variable %s is missing attributes:\n", - v->name); - perror(L" 0x%08x should have 0x%08x set.\n", - attrs, v->yes_attr); - delete = TRUE; - } - if (attrs & v->no_attr) { - perror(L"Variable %s has incorrect attribute:\n", - v->name); - perror(L" 0x%08x should not have 0x%08x set.\n", - attrs, v->no_attr); + if (!v->data && !v->data_size) { + efi_status = get_variable_attr(v->name, + &v->data, &v->data_size, + *v->guid, &attrs); + if (efi_status == EFI_NOT_FOUND) { + v->data = NULL; + v->data_size = 0; + } else if (EFI_ERROR(efi_status)) { + perror(L"Could not verify %s: %r\n", v->name, + efi_status); delete = TRUE; + } else { + if (!(attrs & v->yes_attr)) { + perror(L"Variable %s is missing attributes:\n", + v->name); + perror(L" 0x%08x should have 0x%08x set.\n", + attrs, v->yes_attr); + delete = TRUE; + } + if (attrs & v->no_attr) { + perror(L"Variable %s has incorrect attribute:\n", + v->name); + perror(L" 0x%08x should not have 0x%08x set.\n", + attrs, v->no_attr); + delete = TRUE; + } } } if (delete == TRUE) { diff --git a/test-mok-mirror.c b/test-mok-mirror.c index d7829843b..3479ddf82 100644 --- a/test-mok-mirror.c +++ b/test-mok-mirror.c @@ -78,6 +78,20 @@ getvar_post(CHAR16 *name, EFI_GUID *guid, printf("attrs:NULL\n"); printf("failed:%s\n", efi_strerror(*status)); } + + if (!test_vars) + return; + + for (UINTN i = 0; test_vars[i].name != NULL; i++) { + struct test_var *tv = &test_vars[i]; + + if (CompareGuid(&tv->guid, guid) != 0 || + StrCmp(tv->name, name) != 0) + continue; + tv->ops[tv->n_ops] = GET; + tv->results[tv->n_ops] = *status; + tv->n_ops += 1; + } } static int @@ -201,6 +215,7 @@ test_mok_mirror_0(void) struct mock_variable *var; bool deleted; bool created; + int gets = 0; var = list_entry(pos, struct mock_variable, list); if (CompareGuid(&tv->guid, &var->guid) != 0 || @@ -238,8 +253,14 @@ test_mok_mirror_0(void) assert_goto(false, err, "No replace action should have been tested\n"); break; + case GET: + if (tv->results[j] == EFI_SUCCESS) + gets += 1; + break; } } + assert_goto(gets == 0 || gets == 1, err, + "Variable should not be read %d times.\n", gets); } if (tv->must_be_present) { assert_goto(found == true, err,