summaryrefslogtreecommitdiff
path: root/tests/vboot_api_kernel5_tests.c
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-04-01 20:43:45 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-04-13 01:32:21 -0700
commit6ed4c9938ff0026bb2837171242cd39141e34055 (patch)
tree1d63ac0a7952b48ef764c2bd30b4f8d627b129c4 /tests/vboot_api_kernel5_tests.c
parent79a76d201579fb1b6b48931de1eabe2f968c1070 (diff)
downloadvboot-6ed4c9938ff0026bb2837171242cd39141e34055.tar.gz
vboot: fix vboot_api_kernel_tests after ctx change
CL:1517061 pulled vb2_context storage up to a higher level in the call stack. It also changed vboot_api_kernel{4,5}_tests to use the same context object as that used for VbExNvStorageRead and VbExNvStorageWrite calls. These tests were already initializing the vb2_context workbuf. Since VbSelectAndLoadKernel and VbVerifyMemoryBootImage both initialize the context object internally, ctx.workbuf was being overwritten as part of the call, causing issues later on when calling free(). (See chromium:946970 for more details.) Separate these two context objects to clarify which one is being used as an NVRAM backend, and which one is the classical "context" object passed around in vboot flow. Also remove the NVRAM context's workbuf, since it is not used. BUG=b:124141368, chromium:946970 TEST=make clean && make runtests BRANCH=none Change-Id: Ic1da92ce754e61d4102ca8a6eb9587cd8d9eca10 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/1547711 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'tests/vboot_api_kernel5_tests.c')
-rw-r--r--tests/vboot_api_kernel5_tests.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index d836349e..65899aec 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -27,9 +27,8 @@
#include "vboot_struct.h"
/* Mock data */
-static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
-static struct vb2_shared_data *sd;
+static struct vb2_context ctx_nvram_backend;
static VbCommonParams cparams;
static VbSelectAndLoadKernelParams kparams;
static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
@@ -68,14 +67,18 @@ static void ResetMocks(void)
gbb->rootkey_offset = sizeof(*gbb);
gbb->rootkey_size = sizeof(VbPublicKey);
+ /* ctx.workbuf will be allocated and initialized by
+ * VbVerifyMemoryBootImage. */
memset(&ctx, 0, sizeof(ctx));
- ctx.workbuf = workbuf;
- ctx.workbuf_size = sizeof(workbuf);
- vb2_init_context(&ctx);
- vb2_nv_init(&ctx);
- sd = vb2_get_sd(&ctx);
- sd->vbsd = shared;
+ /*
+ * ctx_nvram_backend is only used as an NVRAM backend (see
+ * VbExNvStorageRead and VbExNvStorageWrite), and with
+ * vb2_set_nvdata and nv2_get_nvdata to manually read and tweak
+ * contents. No other initialization is needed.
+ */
+ memset(&ctx_nvram_backend, 0, sizeof(ctx_nvram_backend));
+ vb2_nv_init(&ctx_nvram_backend);
memset(&shared_data, 0, sizeof(shared_data));
VbSharedDataInit(shared, sizeof(shared_data));
@@ -174,7 +177,8 @@ int vb2_verify_data(const uint8_t *data,
VbError_t VbExNvStorageRead(uint8_t *buf)
{
- memcpy(buf, ctx.nvdata, vb2_nv_get_size(&ctx));
+ memcpy(buf, ctx_nvram_backend.nvdata,
+ vb2_nv_get_size(&ctx_nvram_backend));
return VBERROR_SUCCESS;
}
@@ -238,7 +242,7 @@ static void VerifyMemoryBootImageTest(void)
ResetMocks();
shared->flags = VBSD_BOOT_DEV_SWITCH_ON;
key_block_verify_fail = 1;
- vb2_nv_set(&ctx, VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, 1);
+ vb2_nv_set(&ctx_nvram_backend, VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, 1);
TEST_EQ(VbVerifyMemoryBootImage(&ctx, &cparams, &kparams, kernel_buffer,
kernel_buffer_size),
VBERROR_INVALID_KERNEL_FOUND, "Key verify failed");