avb_chain_partition_descriptor.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright (C) 2016 The Android Open Source Project
  4. */
  5. #include "avb_chain_partition_descriptor.h"
  6. #include "avb_util.h"
  7. bool avb_chain_partition_descriptor_validate_and_byteswap(
  8. const AvbChainPartitionDescriptor* src, AvbChainPartitionDescriptor* dest) {
  9. uint64_t expected_size;
  10. avb_memcpy(dest, src, sizeof(AvbChainPartitionDescriptor));
  11. if (!avb_descriptor_validate_and_byteswap((const AvbDescriptor*)src,
  12. (AvbDescriptor*)dest))
  13. return false;
  14. if (dest->parent_descriptor.tag != AVB_DESCRIPTOR_TAG_CHAIN_PARTITION) {
  15. avb_error("Invalid tag for chain partition descriptor.\n");
  16. return false;
  17. }
  18. dest->rollback_index_location = avb_be32toh(dest->rollback_index_location);
  19. dest->partition_name_len = avb_be32toh(dest->partition_name_len);
  20. dest->public_key_len = avb_be32toh(dest->public_key_len);
  21. if (dest->rollback_index_location < 1) {
  22. avb_error("Invalid rollback index location value.\n");
  23. return false;
  24. }
  25. /* Check that partition_name and public_key are fully contained. */
  26. expected_size = sizeof(AvbChainPartitionDescriptor) - sizeof(AvbDescriptor);
  27. if (!avb_safe_add_to(&expected_size, dest->partition_name_len) ||
  28. !avb_safe_add_to(&expected_size, dest->public_key_len)) {
  29. avb_error("Overflow while adding up sizes.\n");
  30. return false;
  31. }
  32. if (expected_size > dest->parent_descriptor.num_bytes_following) {
  33. avb_error("Descriptor payload size overflow.\n");
  34. return false;
  35. }
  36. return true;
  37. }