From 83ab1908e8173cddc8405a341fe1dc79a2c8d911 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Thu, 13 Feb 2020 17:13:04 +0800 Subject: vboot: use vboot2 for storing kernel rollback versions Migrate to using vboot2 shared data fields for storing kernel rollback versions: kernel_version_tpm_start(1) --> kernel_version_secdata(2) kernel_version_tpm(1) --> kernel_version(2) kernel_version_lowest(1) --> [removed] Also remove VBSD from tests which no longer need it. BUG=b:124141368, chromium:1038260 TEST=make clean && make runtests BRANCH=none Change-Id: I26c2ccede5fba52e1477b625ef5fc6181f60aadf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2053179 Tested-by: Joel Kitching Reviewed-by: Julius Werner Commit-Queue: Joel Kitching --- firmware/lib/vboot_api_kernel.c | 17 +++++++++-------- firmware/lib/vboot_kernel.c | 10 ++++------ 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'firmware/lib') diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index e2c1a6c1..72224e19 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -168,7 +168,6 @@ static int vb2_reset_nv_requests(struct vb2_context *ctx) vb2_error_t VbBootNormal(struct vb2_context *ctx) { struct vb2_shared_data *sd = vb2_get_sd(ctx); - VbSharedDataHeader *shared = sd->vbsd; uint32_t max_rollforward = vb2_nv_get(ctx, VB2_NV_KERNEL_MAX_ROLLFORWARD); @@ -203,20 +202,20 @@ vb2_error_t VbBootNormal(struct vb2_context *ctx) * version to less than the version currently in the TPM. That is, * we're limiting rollforward, not allowing rollback. */ - if (max_rollforward < shared->kernel_version_tpm_start) - max_rollforward = shared->kernel_version_tpm_start; + if (max_rollforward < sd->kernel_version_secdata) + max_rollforward = sd->kernel_version_secdata; - if (shared->kernel_version_tpm > max_rollforward) { + if (sd->kernel_version > max_rollforward) { VB2_DEBUG("Limiting TPM kernel version roll-forward " "to %#x < %#x\n", - max_rollforward, shared->kernel_version_tpm); + max_rollforward, sd->kernel_version); - shared->kernel_version_tpm = max_rollforward; + sd->kernel_version = max_rollforward; } - if (shared->kernel_version_tpm > shared->kernel_version_tpm_start) { + if (sd->kernel_version > sd->kernel_version_secdata) { vb2_secdata_kernel_set(ctx, VB2_SECDATA_KERNEL_VERSIONS, - shared->kernel_version_tpm); + sd->kernel_version); } return rv; @@ -381,6 +380,8 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx, /* Translate vboot2 flags and fields into vboot1. */ if (sd->flags & VB2_SD_FLAG_KERNEL_SIGNED) sd->vbsd->flags |= VBSD_KERNEL_KEY_VERIFIED; + sd->vbsd->kernel_version_tpm_start = sd->kernel_version_secdata; + sd->vbsd->kernel_version_tpm = sd->kernel_version; return rv; } diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c index 722b74de..8118599d 100644 --- a/firmware/lib/vboot_kernel.c +++ b/firmware/lib/vboot_kernel.c @@ -439,7 +439,6 @@ vb2_error_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params) { struct vb2_shared_data *sd = vb2_get_sd(ctx); struct vb2_workbuf wb; - VbSharedDataHeader *shared = sd->vbsd; VbSharedDataKernelCall shcall; int found_partitions = 0; uint32_t lowest_version = LOWEST_TPM_VERSION; @@ -543,7 +542,7 @@ vb2_error_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params) kernel_subkey, lpflags, params, - shared->kernel_version_tpm, + sd->kernel_version, shpart, &wb); VbExStreamClose(stream); @@ -611,7 +610,7 @@ vb2_error_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params) * Otherwise, we'll check all the other headers to see if they * contain a newer key. */ - if (shpart->combined_version == shared->kernel_version_tpm) { + if (shpart->combined_version == sd->kernel_version) { VB2_DEBUG("Same kernel version\n"); break; } @@ -625,7 +624,6 @@ gpt_done: if (params->partition_number > 0) { VB2_DEBUG("Good partition %d\n", params->partition_number); shcall.check_result = VBSD_LKC_CHECK_GOOD_PARTITION; - shared->kernel_version_lowest = lowest_version; /* * Sanity check - only store a new TPM version if we found one. * If lowest_version is still at its initial value, we didn't @@ -633,8 +631,8 @@ gpt_done: * didn't look. */ if (lowest_version != LOWEST_TPM_VERSION && - lowest_version > shared->kernel_version_tpm) - shared->kernel_version_tpm = lowest_version; + lowest_version > sd->kernel_version) + sd->kernel_version = lowest_version; /* Success! */ rv = VB2_SUCCESS; -- cgit v1.2.1