aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelvin Zhang <zhangkelvin@google.com>2023-01-31 00:05:50 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-01-31 00:05:50 +0000
commit10e3b3fc42ba6bf3e912f0e8a87f6ef1ed9b57d4 (patch)
treecb229d3c8748e21a0cbad896180940081463e51b
parente7dba5c8d6d4b9414aca4f793dd71d291b6825e4 (diff)
parent0e68760ac3c1c2fbb09ac624f907d8c7958fc888 (diff)
downloadavb-10e3b3fc42ba6bf3e912f0e8a87f6ef1ed9b57d4.tar.gz
Truncate vbmeta size to partition size am: da0c7cffd4 am: 0e68760ac3
Original change: https://android-review.googlesource.com/c/platform/external/avb/+/2400885 Change-Id: Iddc6a67da80d31d81ff8029b069b9e62663486d1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--libavb/avb_slot_verify.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/libavb/avb_slot_verify.c b/libavb/avb_slot_verify.c
index 3a066f5..a548c80 100644
--- a/libavb/avb_slot_verify.c
+++ b/libavb/avb_slot_verify.c
@@ -558,22 +558,6 @@ out:
return ret;
}
-static AvbIOResult read_one_byte_from_partition(AvbOps* ops,
- const char* partition_name) {
- /* test_buf is a one-byte buffer used to check the existence of the
- * current partition before allocating the big chunk of memory on heap
- * for vbmeta later.
- */
- uint8_t test_buf[TEST_BUFFER_SIZE];
- size_t test_num_read;
- return ops->read_from_partition(ops,
- partition_name,
- 0 /* offset */,
- TEST_BUFFER_SIZE,
- test_buf,
- &test_num_read);
-}
-
static AvbSlotVerifyResult load_and_verify_vbmeta(
AvbOps* ops,
const char* const* requested_partitions,
@@ -691,14 +675,34 @@ static AvbSlotVerifyResult load_and_verify_vbmeta(
vbmeta_size = footer.vbmeta_size;
}
}
+ } else {
+ uint64_t partition_size = 0;
+ io_ret =
+ ops->get_size_of_partition(ops, full_partition_name, &partition_size);
+ if (io_ret == AVB_IO_RESULT_OK) {
+ if (partition_size < vbmeta_size && partition_size > 0) {
+ avb_debugv(full_partition_name,
+ ": Using partition size as vbmeta size\n",
+ NULL);
+ vbmeta_size = partition_size;
+ }
+ } else {
+ avb_debugv(full_partition_name, ": Failed to get partition size\n", NULL);
+ // libavb might fall back to other partitions if current vbmeta partition
+ // isn't found. So AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION is recoverable,
+ // but other errors are not.
+ if (io_ret != AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION) {
+ ret = AVB_SLOT_VERIFY_RESULT_ERROR_IO;
+ goto out;
+ }
+ }
}
- /* Read one byte from the partition to check the existence of the
+ /* Use result from previous I/O operation to check the existence of the
* partition before allocating the big chunk of memory on heap
* for vbmeta later. `io_ret` will be used later to decide whether
* to fallback on the `boot` partition.
*/
- io_ret = read_one_byte_from_partition(ops, full_partition_name);
if (io_ret != AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION) {
vbmeta_buf = avb_malloc(vbmeta_size);
if (vbmeta_buf == NULL) {