summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-01-20 10:26:29 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-01-20 18:25:42 -0800
commit17ffa6b1abdec63015054623226a09c60c38a1ee (patch)
treedea3324f8d91a329469ef5b3991a2727fae71734
parent4c290b058a3393e8842de1583b29310d99c93d9a (diff)
downloadchrome-ec-17ffa6b1abdec63015054623226a09c60c38a1ee.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>
-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 cd86423dc0..afa278884d 100644
--- a/common/system.c
+++ b/common/system.c
@@ -117,6 +117,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;
@@ -364,6 +368,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 30eaec661a..c200d15ba2 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 */