summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-01-20 10:26:29 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2016-05-17 17:14:02 +0000
commit9263a682185a05d8b71e1f10fa8dcd34c7532925 (patch)
treed4dd4211e7137b2b647d2020ca8e136ccb68377c
parent5c3eb68d080102ae81ec9e6627f38c5a473747b1 (diff)
downloadchrome-ec-9263a682185a05d8b71e1f10fa8dcd34c7532925.tar.gz
vboot_hash: Properly handle hash of zero-byte region
If we're asked to compute a hash of an image on a region of storage, we may find that the region actually contains no image. In that case, we need to compute a hash of zero bytes. Properly handle this case from image size detection to hash computation to hash invalidation. BUG=chrome-os-partner:49529 TEST=Manual on chell. `dd conv=notrunc if=/dev/zero of=ec.bin bs=131072 count=1`, then write ec.bin and verify SW sync occurs, RW hash is computed correctly, and the system boots into dev mode. BRANCH=glados, strago Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ie5a023d13d2521f9c224615666950aea8fbc22bb Reviewed-on: https://chromium-review.googlesource.com/322750 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 17ffa6b1abdec63015054623226a09c60c38a1ee) Reviewed-on: https://chromium-review.googlesource.com/345443
-rw-r--r--common/system.c8
-rw-r--r--common/vboot_hash.c11
2 files changed, 17 insertions, 2 deletions
diff --git a/common/system.c b/common/system.c
index 08de7e3dfa..9edc81dfe2 100644
--- a/common/system.c
+++ b/common/system.c
@@ -119,6 +119,10 @@ static uintptr_t get_program_memory_addr(enum system_image_copy_t copy)
*/
static uint32_t get_size(enum system_image_copy_t copy)
{
+ /* Ensure we return aligned sizes. */
+ BUILD_ASSERT(CONFIG_RO_SIZE % SPI_FLASH_MAX_WRITE_SIZE == 0);
+ BUILD_ASSERT(CONFIG_RW_SIZE % SPI_FLASH_MAX_WRITE_SIZE == 0);
+
switch (copy) {
case SYSTEM_IMAGE_RO:
return CONFIG_RO_SIZE;
@@ -361,6 +365,10 @@ int system_get_image_used(enum system_image_copy_t copy)
do {
if (image == buf) {
+ /* No valid image found? */
+ if (size < SPI_FLASH_MAX_WRITE_SIZE)
+ return 0;
+
flash_read(image_offset + size -
SPI_FLASH_MAX_WRITE_SIZE,
SPI_FLASH_MAX_WRITE_SIZE, buf);
diff --git a/common/vboot_hash.c b/common/vboot_hash.c
index ff2c56fb59..9890fc7a0f 100644
--- a/common/vboot_hash.c
+++ b/common/vboot_hash.c
@@ -72,6 +72,9 @@ static int read_and_hash_chunk(int offset, int size)
char *buf;
int rv;
+ if (size == 0)
+ return EC_SUCCESS;
+
rv = shared_mem_acquire(size, &buf);
if (rv == EC_ERROR_BUSY) {
/* Couldn't update hash right now; try again later */
@@ -190,8 +193,12 @@ int vboot_hash_invalidate(int offset, int size)
if (!hash)
return 0;
- /* No overlap if passed region is off either end of hashed region */
- if (offset + size <= data_offset || offset >= data_offset + data_size)
+ /*
+ * Always invalidate zero-size hash. No overlap if passed region is off
+ * either end of hashed region.
+ */
+ if (data_size > 0 &&
+ (offset + size <= data_offset || offset >= data_offset + data_size))
return 0;
/* Invalidate the hash */