diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-01-20 10:26:29 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2016-05-17 17:13:50 +0000 |
commit | 2565067fcdfb3426ad4366e901d39ea85adf2455 (patch) | |
tree | 0c945d0625b86296efb6a083d1cf891cc86e8825 | |
parent | 7162809cd5074d4177853b7f81b427b0b0198ffb (diff) | |
download | chrome-ec-2565067fcdfb3426ad4366e901d39ea85adf2455.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/345441
-rw-r--r-- | common/system.c | 8 | ||||
-rw-r--r-- | common/vboot_hash.c | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/common/system.c b/common/system.c index de15f62aa3..f13b9e800b 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 */ |