diff options
author | Joel Kitching <kitching@google.com> | 2019-07-25 16:39:56 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-16 07:25:30 +0000 |
commit | eb10ebf76d78a7ac7cb6b66c6f1bba747d4e10ca (patch) | |
tree | 31e71507502a3a233fae0fd5fbbbe2fadd494659 /firmware/2lib | |
parent | 445e371ebc7afaca6be293f43055eae0fbeb67be (diff) | |
download | vboot-eb10ebf76d78a7ac7cb6b66c6f1bba747d4e10ca.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/2lib')
-rw-r--r-- | firmware/2lib/2api.c | 4 | ||||
-rw-r--r-- | firmware/2lib/2common.c | 6 | ||||
-rw-r--r-- | firmware/2lib/include/2common.h | 9 | ||||
-rw-r--r-- | firmware/2lib/include/2struct.h | 19 |
4 files changed, 26 insertions, 12 deletions
diff --git a/firmware/2lib/2api.c b/firmware/2lib/2api.c index f39ba290..e6ed5eb0 100644 --- a/firmware/2lib/2api.c +++ b/firmware/2lib/2api.c @@ -165,10 +165,10 @@ vb2_error_t vb2api_extend_hash(struct vb2_context *ctx, { struct vb2_shared_data *sd = vb2_get_sd(ctx); struct vb2_digest_context *dc = (struct vb2_digest_context *) - (ctx->workbuf + sd->workbuf_hash_offset); + vb2_member_of(sd, sd->hash_offset); /* Must have initialized hash digest work area */ - if (!sd->workbuf_hash_size) + if (!sd->hash_size) return VB2_ERROR_API_EXTEND_HASH_WORKBUF; /* Don't extend past the data we expect to hash */ diff --git a/firmware/2lib/2common.c b/firmware/2lib/2common.c index de1fc498..c0eb4479 100644 --- a/firmware/2lib/2common.c +++ b/firmware/2lib/2common.c @@ -104,6 +104,12 @@ ptrdiff_t vb2_offset_of(const void *base, const void *ptr) return (uintptr_t)ptr - (uintptr_t)base; } +void *vb2_member_of(void *parent, ptrdiff_t offset) +{ + /* TODO(kitching): vb2_assert(parent && offset) */ + return parent + offset; +} + vb2_error_t vb2_verify_member_inside(const void *parent, size_t parent_size, const void *member, size_t member_size, ptrdiff_t member_data_offset, diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h index f0df9c0b..ccc0bfc4 100644 --- a/firmware/2lib/include/2common.h +++ b/firmware/2lib/include/2common.h @@ -166,6 +166,15 @@ vb2_error_t vb2_align(uint8_t **ptr, uint32_t *size, uint32_t align, ptrdiff_t vb2_offset_of(const void *base, const void *ptr); /** + * Return member of given object. + * + * @param parent Pointer to parent object + * @param offset Offset from base + * @return Pointer to child object. + */ +void *vb2_member_of(void *parent, ptrdiff_t offset); + +/** * Return expected signature size for a signature/hash algorithm pair * * @param sig_alg Signature algorithm diff --git a/firmware/2lib/include/2struct.h b/firmware/2lib/include/2struct.h index 52783b6a..a045fef3 100644 --- a/firmware/2lib/include/2struct.h +++ b/firmware/2lib/include/2struct.h @@ -169,22 +169,22 @@ struct vb2_shared_data { * Offset and size of packed data key in work buffer. Size is 0 if * data key is not stored in the work buffer. */ - uint32_t workbuf_data_key_offset; - uint32_t workbuf_data_key_size; + uint32_t data_key_offset; + uint32_t data_key_size; /* * Offset and size of firmware preamble in work buffer. Size is 0 if * preamble is not stored in the work buffer. */ - uint32_t workbuf_preamble_offset; - uint32_t workbuf_preamble_size; + uint32_t preamble_offset; + uint32_t preamble_size; /* * Offset and size of hash context in work buffer. Size is 0 if * hash context is not stored in the work buffer. */ - uint32_t workbuf_hash_offset; - uint32_t workbuf_hash_size; + uint32_t hash_offset; + uint32_t hash_size; /* * Current tag we're hashing @@ -192,8 +192,7 @@ struct vb2_shared_data { * For new structs, this is the offset of the vb2_signature struct * in the work buffer. * - * TODO: rename to workbuf_hash_sig_offset when vboot1 structs are - * deprecated. + * TODO: rename to hash_sig_offset when vboot1 structs are deprecated. */ uint32_t hash_tag; @@ -222,8 +221,8 @@ struct vb2_shared_data { * subkey is not stored in the work buffer. Note that kernel key may * be inside the firmware preamble. */ - uint32_t workbuf_kernel_key_offset; - uint32_t workbuf_kernel_key_size; + uint32_t kernel_key_offset; + uint32_t kernel_key_size; } __attribute__((packed)); /****************************************************************************/ |