summaryrefslogtreecommitdiff
path: root/firmware/lib20/kernel.c
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-07-25 16:39:56 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-16 07:25:30 +0000
commiteb10ebf76d78a7ac7cb6b66c6f1bba747d4e10ca (patch)
tree31e71507502a3a233fae0fd5fbbbe2fadd494659 /firmware/lib20/kernel.c
parent445e371ebc7afaca6be293f43055eae0fbeb67be (diff)
downloadvboot-stabilize-12428.B.tar.gz
vboot: vb2_shared_data offsets should hang off parentstabilize-12428.B
vb2_shared_data struct has many offsets to other objects in the workbuf. They are all prefixed with `workbuf_`, e.g.: uint32_t workbuf_data_key_offset; uint32_t workbuf_data_key_size; In order to adhere to a hierarchical structure on the workbuf, remove the workbuf_ prefix from these symbols to reflect the relationship between vb2_shared_data and its children more accurately. Create a helper function vb2_member_of to safely look up a child of a particular object in the workbuf by offset. Pointer arithmetic to find vb2_shared_data children is replaced with calls to this function. BUG=b:124141368, chromium:994060 TEST=make clean && make runtests BRANCH=none Change-Id: Ia82417a35d2067ee5e4f42fea0396e6325127223 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1753400 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1718264 Commit-Queue: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'firmware/lib20/kernel.c')
-rw-r--r--firmware/lib20/kernel.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/firmware/lib20/kernel.c b/firmware/lib20/kernel.c
index 4d8f7721..10cf158f 100644
--- a/firmware/lib20/kernel.c
+++ b/firmware/lib20/kernel.c
@@ -121,8 +121,8 @@ vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx)
sd->flags &= ~VB2_SD_FLAG_KERNEL_SIGNED;
/* Unpack the kernel key */
- key_data = ctx->workbuf + sd->workbuf_kernel_key_offset;
- key_size = sd->workbuf_kernel_key_size;
+ key_data = vb2_member_of(sd, sd->kernel_key_offset);
+ key_size = sd->kernel_key_size;
rv = vb2_unpack_key_buffer(&kernel_key, key_data, key_size);
if (rv)
return rv;
@@ -217,8 +217,8 @@ vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx)
* (which we might still need to verify the next kernel, if the
* assoiciated kernel preamble and data don't verify).
*/
- sd->workbuf_data_key_offset = ctx->workbuf_used;
- key_data = ctx->workbuf + sd->workbuf_data_key_offset;
+ sd->data_key_offset = ctx->workbuf_used;
+ key_data = vb2_member_of(sd, sd->data_key_offset);
packed_key = (struct vb2_packed_key *)key_data;
memmove(packed_key, &kb->data_key, sizeof(*packed_key));
packed_key->key_offset = sizeof(*packed_key);
@@ -227,7 +227,7 @@ vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx)
packed_key->key_size);
/* Save the packed key size */
- sd->workbuf_data_key_size =
+ sd->data_key_size =
packed_key->key_offset + packed_key->key_size;
/*
@@ -238,8 +238,8 @@ vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx)
* - kernel key
* - packed kernel data key
*/
- vb2_set_workbuf_used(ctx, sd->workbuf_data_key_offset +
- sd->workbuf_data_key_size);
+ vb2_set_workbuf_used(ctx, sd->data_key_offset +
+ sd->data_key_size);
return VB2_SUCCESS;
}
@@ -357,8 +357,8 @@ vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx)
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_workbuf wb;
- uint8_t *key_data = ctx->workbuf + sd->workbuf_data_key_offset;
- uint32_t key_size = sd->workbuf_data_key_size;
+ uint8_t *key_data = vb2_member_of(sd, sd->data_key_offset);
+ uint32_t key_size = sd->data_key_size;
struct vb2_public_key data_key;
/* Preamble goes in the next unused chunk of work buffer */
@@ -372,7 +372,7 @@ vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx)
vb2_workbuf_from_ctx(ctx, &wb);
/* Unpack the kernel data key */
- if (!sd->workbuf_data_key_size)
+ if (!sd->data_key_size)
return VB2_ERROR_KERNEL_PREAMBLE2_DATA_KEY;
rv = vb2_unpack_key_buffer(&data_key, key_data, key_size);
@@ -431,8 +431,8 @@ vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx)
return VB2_ERROR_KERNEL_PREAMBLE_VERSION_ROLLBACK;
/* Keep track of where we put the preamble */
- sd->workbuf_preamble_offset = vb2_offset_of(ctx->workbuf, pre);
- sd->workbuf_preamble_size = pre_size;
+ sd->preamble_offset = vb2_offset_of(sd, pre);
+ sd->preamble_size = pre_size;
/*
* Preamble will persist in work buffer after we return.
@@ -447,7 +447,7 @@ vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx)
* TODO: we could move the preamble down over the kernel data key
* since we don't need it anymore.
*/
- vb2_set_workbuf_used(ctx, sd->workbuf_preamble_offset + pre_size);
+ vb2_set_workbuf_used(ctx, sd->preamble_offset + pre_size);
return VB2_SUCCESS;
}