diff options
author | Randall Spangler <rspangler@chromium.org> | 2010-06-15 21:36:24 -0700 |
---|---|---|
committer | Randall Spangler <rspangler@chromium.org> | 2010-06-15 21:36:24 -0700 |
commit | e995895b1809e5218834707e131f8f69f1294b19 (patch) | |
tree | 4bcceaf76bd6a24028609ac9d34f60e6d1172858 | |
parent | 962483c1e27627aad843a2c394f11b830dd1ce02 (diff) | |
download | vboot-e995895b1809e5218834707e131f8f69f1294b19.tar.gz |
Explicitly pack vboot_struct structures, since they're going on disk.
Review URL: http://codereview.chromium.org/2829004
-rw-r--r-- | vboot_firmware/include/load_firmware_fw.h | 7 | ||||
-rw-r--r-- | vboot_firmware/lib/cgptlib/cgptlib_internal.c | 8 | ||||
-rw-r--r-- | vboot_firmware/lib/include/vboot_struct.h | 10 | ||||
-rw-r--r-- | vboot_firmware/stub/load_firmware_stub.c | 4 |
4 files changed, 15 insertions, 14 deletions
diff --git a/vboot_firmware/include/load_firmware_fw.h b/vboot_firmware/include/load_firmware_fw.h index af971161..c6693c33 100644 --- a/vboot_firmware/include/load_firmware_fw.h +++ b/vboot_firmware/include/load_firmware_fw.h @@ -11,9 +11,10 @@ #include <stdint.h> -/* Maximum size of kernel_sign_key_blob in bytes, for implementations - * which must preallocate a transfer buffer between boot phases */ -#define LOAD_FIRMWARE_KEY_BLOB_MAX 2104 +/* Recommended size of kernel_sign_key_blob in bytes, for + * implementations which must preallocate a transfer buffer between + * boot phases */ +#define LOAD_FIRMWARE_KEY_BLOB_REC_SIZE 2104 /* Return codes for LoadFirmware() */ #define LOAD_FIRMWARE_SUCCESS 0 /* Success */ diff --git a/vboot_firmware/lib/cgptlib/cgptlib_internal.c b/vboot_firmware/lib/cgptlib/cgptlib_internal.c index 4f022936..7faf3832 100644 --- a/vboot_firmware/lib/cgptlib/cgptlib_internal.c +++ b/vboot_firmware/lib/cgptlib/cgptlib_internal.c @@ -102,16 +102,16 @@ int CheckHeader(GptHeader *h, int is_secondary, uint64_t drive_sectors) { } -/* Return 1 if the entry is unused, 0 if it is used. */ +/* Return non-zero if the entry is unused, 0 if it is used. */ int IsUnusedEntry(const GptEntry* e) { static Guid zero = {{{0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}}}}; - return (Memcmp(&zero, (const uint8_t*)(&e->type), sizeof(zero)) ? 0 : 1); + return !Memcmp(&zero, (const uint8_t*)(&e->type), sizeof(zero)); } -/* Returns 1 if the entry is a Chrome OS kernel partition, else 0. */ +/* Returns non-zero if the entry is a Chrome OS kernel partition, else 0. */ int IsKernelEntry(const GptEntry* e) { static Guid chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; - return (Memcmp(&e->type, &chromeos_kernel, sizeof(Guid)) ? 0 : 1); + return !Memcmp(&e->type, &chromeos_kernel, sizeof(Guid)); } diff --git a/vboot_firmware/lib/include/vboot_struct.h b/vboot_firmware/lib/include/vboot_struct.h index c77fa4bc..98366fb2 100644 --- a/vboot_firmware/lib/include/vboot_struct.h +++ b/vboot_firmware/lib/include/vboot_struct.h @@ -19,7 +19,7 @@ typedef struct VbPublicKey { * in bits) */ uint64_t algorithm; /* Signature algorithm used by the key */ uint64_t key_version; /* Key version */ -} VbPublicKey; +} __attribute__((packed)) VbPublicKey; /* Signature data (a secure hash, possibly signed) */ @@ -28,7 +28,7 @@ typedef struct VbSignature { * struct */ uint64_t sig_size; /* Size of signature data in bytes */ uint64_t data_size; /* Size of the data block which was signed in bytes */ -} VbSignature; +} __attribute__((packed)) VbSignature; #define KEY_BLOCK_MAGIC "CHROMEOS" @@ -61,7 +61,7 @@ typedef struct VbKeyBlockHeader { * For use with unsigned data keys */ uint64_t key_block_flags; /* Flags for key (KEY_BLOCK_FLAG_*) */ VbPublicKey data_key; /* Key to verify the chunk of data */ -} VbKeyBlockHeader; +} __attribute__((packed)) VbKeyBlockHeader; /* This should be followed by: * 1) The data_key key data, pointed to by data_key.key_offset. * 2) The checksum data for (VBKeyBlockHeader + data_key data), pointed to @@ -86,7 +86,7 @@ typedef struct VbFirmwarePreambleHeader { uint64_t firmware_version; /* Firmware version */ VbPublicKey kernel_subkey; /* Key to verify kernel key block */ VbSignature body_signature; /* Signature for the firmware body */ -} VbFirmwarePreambleHeader; +} __attribute__((packed)) VbFirmwarePreambleHeader; /* This should be followed by: * 1) The kernel_subkey key data, pointed to by kernel_subkey.key_offset. * 2) The signature data for the firmware body, pointed to by @@ -114,7 +114,7 @@ typedef struct VbKernelPreambleHeader { * loaded at body_load_address */ uint64_t bootloader_size; /* Size of bootloader in bytes */ VbSignature body_signature; /* Signature for the kernel body */ -} VbKernelPreambleHeader; +} __attribute__((packed)) VbKernelPreambleHeader; /* This should be followed by: * 2) The signature data for the kernel body, pointed to by * body_signature.sig_offset. diff --git a/vboot_firmware/stub/load_firmware_stub.c b/vboot_firmware/stub/load_firmware_stub.c index 5bca57da..1570f70b 100644 --- a/vboot_firmware/stub/load_firmware_stub.c +++ b/vboot_firmware/stub/load_firmware_stub.c @@ -83,8 +83,8 @@ int VerifyFirmwareDriver_stub(uint8_t* root_key_blob, p.verification_block_1 = verification_headerB; /* Allocate a key blob buffer */ - p.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_MAX); - p.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_MAX; + p.kernel_sign_key_blob = Malloc(LOAD_FIRMWARE_KEY_BLOB_REC_SIZE); + p.kernel_sign_key_size = LOAD_FIRMWARE_KEY_BLOB_REC_SIZE; /* Call LoadFirmware() */ rv = LoadFirmware(&p); |