]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: correctly handle no tpm device error
authorMasahisa Kojima <masahisa.kojima@linaro.org>
Tue, 7 Dec 2021 05:15:33 +0000 (14:15 +0900)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 9 Dec 2021 19:43:25 +0000 (11:43 -0800)
When the TCG2 protocol is installed in efi_tcg2_register(),
TPM2 device must be present.
tcg2_measure_pe_image() expects that TCP2 protocol is installed
and TPM device is available. If TCG2 Protocol is installed but
TPM device is not found, tcg2_measure_pe_image() returns
EFI_SECURITY_VIOLATION and efi_load_image() ends with failure.

The same error handling is applied to
efi_tcg2_measure_efi_app_invocation().

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
lib/efi_loader/efi_boottime.c
lib/efi_loader/efi_image_loader.c
lib/efi_loader/efi_tcg2.c

index 8492b732f38400bbc8a92c3c4a06c295393c545d..20b69699fe9414f465634d494cfca02539da035f 100644 (file)
@@ -3016,9 +3016,12 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
        if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
                if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) {
                        ret = efi_tcg2_measure_efi_app_invocation(image_obj);
-                       if (ret != EFI_SUCCESS) {
-                               log_warning("tcg2 measurement fails(0x%lx)\n",
-                                           ret);
+                       if (ret == EFI_SECURITY_VIOLATION) {
+                               /*
+                                * TCG2 Protocol is installed but no TPM device found,
+                                * this is not expected.
+                                */
+                               return EFI_EXIT(EFI_SECURITY_VIOLATION);
                        }
                }
        }
index eb95580538ccbfb5dcb479c548f1263a918cca55..773bd0677c09a99efeae2f2c89b428482b21e820 100644 (file)
@@ -934,9 +934,16 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
 
 #if CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL)
        /* Measure an PE/COFF image */
-       if (tcg2_measure_pe_image(efi, efi_size, handle,
-                                 loaded_image_info))
-               log_err("PE image measurement failed\n");
+       ret = tcg2_measure_pe_image(efi, efi_size, handle, loaded_image_info);
+       if (ret == EFI_SECURITY_VIOLATION) {
+               /*
+                * TCG2 Protocol is installed but no TPM device found,
+                * this is not expected.
+                */
+               log_err("PE image measurement failed, no tpm device found\n");
+               goto err;
+       }
+
 #endif
 
        /* Copy PE headers */
index 59bce85028aa2bba25a564fd64e287d115e2c8bf..0ae07ef083920d263004711c8c068eb986a452f2 100644 (file)
@@ -977,7 +977,7 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
 
        ret = platform_get_tpm2_device(&dev);
        if (ret != EFI_SUCCESS)
-               return ret;
+               return EFI_SECURITY_VIOLATION;
 
        switch (handle->image_type) {
        case IMAGE_SUBSYSTEM_EFI_APPLICATION:
@@ -2200,7 +2200,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha
 
        ret = platform_get_tpm2_device(&dev);
        if (ret != EFI_SUCCESS)
-               return ret;
+               return EFI_SECURITY_VIOLATION;
 
        ret = tcg2_measure_boot_variable(dev);
        if (ret != EFI_SUCCESS)