diff options
author | Joel Kitching <kitching@google.com> | 2019-01-11 19:16:18 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-15 02:06:22 -0700 |
commit | dccea9ae88059c8cb7dff76d2682835184fc8338 (patch) | |
tree | eeb9768deb8c25ea2158b6977a938a23388bb9cb /tests/vb2_misc_tests.c | |
parent | 351c005eddd763ba89997ebc08ad0e19d2d1c3a0 (diff) | |
download | vboot-dccea9ae88059c8cb7dff76d2682835184fc8338.tar.gz |
vboot: add magic and version to vb2_shared_data
In order for vb2_shared_data to cross application boundaries,
it needs magic and version fields.
These can be initialized in vb2_init_context, which is called
implicitly via vb2api_fw_phase1 and vb2api_fail.
On re-init, check fields for validity.
BUG=b:124141368, b:124192753
TEST=make clean && make runtests
BRANCH=none
Change-Id: I90005833836f13f60813bdf82f0e4dbb8d9afecd
Reviewed-on: https://chromium-review.googlesource.com/1521406
Commit-Ready: Joel Kitching <kitching@chromium.org>
Tested-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'tests/vb2_misc_tests.c')
-rw-r--r-- | tests/vb2_misc_tests.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/vb2_misc_tests.c b/tests/vb2_misc_tests.c index f17ac1b1..9b331cc1 100644 --- a/tests/vb2_misc_tests.c +++ b/tests/vb2_misc_tests.c @@ -88,12 +88,48 @@ static void init_context_tests(void) TEST_SUCC(vb2_init_context(&c), "Init context good"); TEST_EQ(c.workbuf_used, vb2_wb_round_up(sizeof(struct vb2_shared_data)), "Init vbsd"); + TEST_EQ(sd->magic, VB2_SHARED_DATA_MAGIC, "Bad magic"); + TEST_EQ(sd->struct_version_major, VB2_SHARED_DATA_VERSION_MAJOR, + "No major version"); + TEST_EQ(sd->struct_version_minor, VB2_SHARED_DATA_VERSION_MINOR, + "No minor version"); /* Don't re-init if used is non-zero */ c.workbuf_used = 200; TEST_SUCC(vb2_init_context(&c), "Re-init context good"); TEST_EQ(c.workbuf_used, 200, "Didn't re-init"); + /* Error if re-init with incorrect magic */ + sd->magic = 0xdeadbeef; + TEST_EQ(vb2_init_context(&c), + VB2_ERROR_SHARED_DATA_MAGIC, "Missed bad magic"); + sd->magic = VB2_SHARED_DATA_MAGIC; + + /* Success if re-init with higher minor version */ + sd->struct_version_minor++; + TEST_SUCC(vb2_init_context(&c), "Didn't allow higher minor version"); + sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR; + + /* Error if re-init with lower minor version */ + if (VB2_SHARED_DATA_VERSION_MINOR > 0) { + sd->struct_version_minor--; + TEST_EQ(vb2_init_context(&c), VB2_ERROR_SHARED_DATA_VERSION, + "Allowed lower minor version"); + sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR; + } + + /* Error if re-init with higher major version */ + sd->struct_version_major++; + TEST_EQ(vb2_init_context(&c), + VB2_ERROR_SHARED_DATA_VERSION, "Allowed higher major version"); + sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR; + + /* Error if re-init with lower major version */ + sd->struct_version_major--; + TEST_EQ(vb2_init_context(&c), + VB2_ERROR_SHARED_DATA_VERSION, "Allowed lower major version"); + sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR; + /* Handle workbuf errors */ c.workbuf_used = 0; c.workbuf_size = sizeof(struct vb2_shared_data) - 1; |