diff options
Diffstat (limited to 'firmware/2lib')
-rw-r--r-- | firmware/2lib/2misc.c | 16 | ||||
-rw-r--r-- | firmware/2lib/include/2return_codes.h | 6 | ||||
-rw-r--r-- | firmware/2lib/include/2struct.h | 14 |
3 files changed, 34 insertions, 2 deletions
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c index 5d82fc03..95cbae35 100644 --- a/firmware/2lib/2misc.c +++ b/firmware/2lib/2misc.c @@ -121,9 +121,18 @@ int vb2_init_context(struct vb2_context *ctx) { struct vb2_shared_data *sd = vb2_get_sd(ctx); - /* Don't do anything if the context has already been initialized */ - if (ctx->workbuf_used) + /* Don't do anything if context and workbuf have already been + * initialized. */ + if (ctx->workbuf_used) { + if (sd->magic != VB2_SHARED_DATA_MAGIC) + return VB2_ERROR_SHARED_DATA_MAGIC; + + if (sd->struct_version_major != VB2_SHARED_DATA_VERSION_MAJOR || + sd->struct_version_minor < VB2_SHARED_DATA_VERSION_MINOR) + return VB2_ERROR_SHARED_DATA_VERSION; + return VB2_SUCCESS; + } /* * Workbuf had better be big enough for our shared data struct and @@ -137,6 +146,9 @@ int vb2_init_context(struct vb2_context *ctx) /* Initialize the shared data at the start of the work buffer */ memset(sd, 0, sizeof(*sd)); + sd->magic = VB2_SHARED_DATA_MAGIC; + sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR; + sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR; ctx->workbuf_used = vb2_wb_round_up(sizeof(*sd)); return VB2_SUCCESS; } diff --git a/firmware/2lib/include/2return_codes.h b/firmware/2lib/include/2return_codes.h index 92e4eb1c..5992806d 100644 --- a/firmware/2lib/include/2return_codes.h +++ b/firmware/2lib/include/2return_codes.h @@ -497,6 +497,12 @@ enum vb2_return_code { /* Expected and image hashes are different size in ec_sync_phase1() */ VB2_ERROR_EC_HASH_SIZE, + /* Incompatible version for vb2_shared_data structure being loaded */ + VB2_ERROR_SHARED_DATA_VERSION, + + /* Bad magic number in vb2_shared_data structure */ + VB2_ERROR_SHARED_DATA_MAGIC, + /********************************************************************** * API-level errors */ diff --git a/firmware/2lib/include/2struct.h b/firmware/2lib/include/2struct.h index d3f7f445..a67518c8 100644 --- a/firmware/2lib/include/2struct.h +++ b/firmware/2lib/include/2struct.h @@ -69,11 +69,25 @@ enum vb2_shared_data_status { VB2_SD_STATUS_SECDATAK_INIT = (1 << 4), }; +/* "V2SD" = vb2_shared_data.magic */ +#define VB2_SHARED_DATA_MAGIC 0x44533256 + +/* Current version of vb2_shared_data struct */ +#define VB2_SHARED_DATA_VERSION_MAJOR 1 +#define VB2_SHARED_DATA_VERSION_MINOR 0 + /* * Data shared between vboot API calls. Stored at the start of the work * buffer. */ struct vb2_shared_data { + /* Magic number for struct (VB2_SHARED_DATA_MAGIC) */ + uint32_t magic; + + /* Version of this structure */ + uint16_t struct_version_major; + uint16_t struct_version_minor; + /* Flags; see enum vb2_shared_data_flags */ uint32_t flags; |