summaryrefslogtreecommitdiff
path: root/common/vboot_hash.c
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 /common/vboot_hash.c
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>
Diffstat (limited to 'common/vboot_hash.c')
-rw-r--r--common/vboot_hash.c11
1 files changed, 9 insertions, 2 deletions
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 */