Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #include "update_engine/payload_consumer/delta_performer.h" |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 18 | |
Alex Deymo | 79715ad | 2015-10-02 14:27:53 -0700 | [diff] [blame] | 19 | #include <linux/fs.h> |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 20 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 21 | #include <algorithm> |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 22 | #include <chrono> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 23 | #include <cstring> |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 24 | #include <memory> |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 25 | #include <set> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 26 | #include <string> |
Amin Hassani | d87304c | 2017-08-29 11:40:03 -0700 | [diff] [blame] | 27 | #include <utility> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 28 | #include <vector> |
| 29 | |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 30 | #include <android-base/properties.h> |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 31 | #include <android-base/strings.h> |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 32 | #include <base/files/file_util.h> |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 33 | #include <base/format_macros.h> |
Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 34 | #include <base/metrics/histogram_macros.h> |
Alex Deymo | 6714084 | 2016-06-15 13:28:59 -0700 | [diff] [blame] | 35 | #include <base/strings/string_number_conversions.h> |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 36 | #include <base/strings/stringprintf.h> |
Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 37 | #include <base/time/time.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 38 | #include <brillo/data_encoding.h> |
Alex Deymo | 6765a68 | 2017-05-19 13:13:54 -0700 | [diff] [blame] | 39 | #include <bsdiff/bspatch.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 40 | #include <google/protobuf/repeated_field.h> |
Amin Hassani | 02855c2 | 2017-09-06 22:34:50 -0700 | [diff] [blame] | 41 | #include <puffin/puffpatch.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 42 | |
Kelvin Zhang | bfa1041 | 2023-03-17 11:19:14 -0700 | [diff] [blame] | 43 | #include "libsnapshot/cow_format.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 44 | #include "update_engine/common/constants.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 45 | #include "update_engine/common/download_action.h" |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 46 | #include "update_engine/common/error_code.h" |
| 47 | #include "update_engine/common/error_code_utils.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 48 | #include "update_engine/common/hardware_interface.h" |
Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 49 | #include "update_engine/common/prefs_interface.h" |
Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 50 | #include "update_engine/common/terminator.h" |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 51 | #include "update_engine/common/utils.h" |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 52 | #include "update_engine/payload_consumer/partition_update_generator_interface.h" |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 53 | #include "update_engine/payload_consumer/partition_writer.h" |
Daniel Zheng | 730ae9b | 2022-08-25 22:37:22 +0000 | [diff] [blame] | 54 | #include "update_engine/update_metadata.pb.h" |
Alex Deymo | 51c264e | 2016-11-04 15:49:53 -0700 | [diff] [blame] | 55 | #if USE_FEC |
| 56 | #include "update_engine/payload_consumer/fec_file_descriptor.h" |
| 57 | #endif // USE_FEC |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 58 | #include "update_engine/payload_consumer/payload_constants.h" |
| 59 | #include "update_engine/payload_consumer/payload_verifier.h" |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 60 | |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 61 | using google::protobuf::RepeatedPtrField; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 62 | using std::min; |
| 63 | using std::string; |
| 64 | using std::vector; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 65 | |
| 66 | namespace chromeos_update_engine { |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 67 | const unsigned DeltaPerformer::kProgressLogMaxChunks = 10; |
| 68 | const unsigned DeltaPerformer::kProgressLogTimeoutSeconds = 30; |
| 69 | const unsigned DeltaPerformer::kProgressDownloadWeight = 50; |
| 70 | const unsigned DeltaPerformer::kProgressOperationsWeight = 50; |
Colin Howes | 0e452c9 | 2018-11-02 13:18:44 -0700 | [diff] [blame] | 71 | const uint64_t DeltaPerformer::kCheckpointFrequencySeconds = 1; |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 72 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 73 | namespace { |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 74 | const int kUpdateStateOperationInvalid = -1; |
Darin Petkov | 6142614 | 2010-10-08 11:04:55 -0700 | [diff] [blame] | 75 | const int kMaxResumedUpdateFailures = 10; |
Nam T. Nguyen | f1d582e | 2014-12-08 15:07:17 -0800 | [diff] [blame] | 76 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 77 | } // namespace |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 78 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 79 | // Computes the ratio of |part| and |total|, scaled to |norm|, using integer |
| 80 | // arithmetic. |
| 81 | static uint64_t IntRatio(uint64_t part, uint64_t total, uint64_t norm) { |
| 82 | return part * norm / total; |
| 83 | } |
| 84 | |
| 85 | void DeltaPerformer::LogProgress(const char* message_prefix) { |
| 86 | // Format operations total count and percentage. |
| 87 | string total_operations_str("?"); |
| 88 | string completed_percentage_str(""); |
| 89 | if (num_total_operations_) { |
Alex Deymo | c00c98a | 2015-03-17 17:38:00 -0700 | [diff] [blame] | 90 | total_operations_str = std::to_string(num_total_operations_); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 91 | // Upcasting to 64-bit to avoid overflow, back to size_t for formatting. |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 92 | completed_percentage_str = base::StringPrintf( |
| 93 | " (%" PRIu64 "%%)", |
| 94 | IntRatio(next_operation_num_, num_total_operations_, 100)); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | // Format download total count and percentage. |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 98 | size_t payload_size = payload_->size; |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 99 | string payload_size_str("?"); |
| 100 | string downloaded_percentage_str(""); |
| 101 | if (payload_size) { |
Alex Deymo | c00c98a | 2015-03-17 17:38:00 -0700 | [diff] [blame] | 102 | payload_size_str = std::to_string(payload_size); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 103 | // Upcasting to 64-bit to avoid overflow, back to size_t for formatting. |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 104 | downloaded_percentage_str = base::StringPrintf( |
| 105 | " (%" PRIu64 "%%)", IntRatio(total_bytes_received_, payload_size, 100)); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | LOG(INFO) << (message_prefix ? message_prefix : "") << next_operation_num_ |
| 109 | << "/" << total_operations_str << " operations" |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 110 | << completed_percentage_str << ", " << total_bytes_received_ << "/" |
| 111 | << payload_size_str << " bytes downloaded" |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 112 | << downloaded_percentage_str << ", overall progress " |
| 113 | << overall_progress_ << "%"; |
| 114 | } |
| 115 | |
| 116 | void DeltaPerformer::UpdateOverallProgress(bool force_log, |
| 117 | const char* message_prefix) { |
| 118 | // Compute our download and overall progress. |
| 119 | unsigned new_overall_progress = 0; |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 120 | static_assert(kProgressDownloadWeight + kProgressOperationsWeight == 100, |
| 121 | "Progress weights don't add up"); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 122 | // Only consider download progress if its total size is known; otherwise |
| 123 | // adjust the operations weight to compensate for the absence of download |
| 124 | // progress. Also, make sure to cap the download portion at |
| 125 | // kProgressDownloadWeight, in case we end up downloading more than we |
| 126 | // initially expected (this indicates a problem, but could generally happen). |
| 127 | // TODO(garnold) the correction of operations weight when we do not have the |
| 128 | // total payload size, as well as the conditional guard below, should both be |
| 129 | // eliminated once we ensure that the payload_size in the install plan is |
| 130 | // always given and is non-zero. This currently isn't the case during unit |
| 131 | // tests (see chromium-os:37969). |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 132 | size_t payload_size = payload_->size; |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 133 | unsigned actual_operations_weight = kProgressOperationsWeight; |
| 134 | if (payload_size) |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 135 | new_overall_progress += |
| 136 | min(static_cast<unsigned>(IntRatio( |
| 137 | total_bytes_received_, payload_size, kProgressDownloadWeight)), |
| 138 | kProgressDownloadWeight); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 139 | else |
| 140 | actual_operations_weight += kProgressDownloadWeight; |
| 141 | |
| 142 | // Only add completed operations if their total number is known; we definitely |
| 143 | // expect an update to have at least one operation, so the expectation is that |
| 144 | // this will eventually reach |actual_operations_weight|. |
| 145 | if (num_total_operations_) |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 146 | new_overall_progress += IntRatio( |
| 147 | next_operation_num_, num_total_operations_, actual_operations_weight); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 148 | |
| 149 | // Progress ratio cannot recede, unless our assumptions about the total |
| 150 | // payload size, total number of operations, or the monotonicity of progress |
| 151 | // is breached. |
| 152 | if (new_overall_progress < overall_progress_) { |
| 153 | LOG(WARNING) << "progress counter receded from " << overall_progress_ |
| 154 | << "% down to " << new_overall_progress << "%; this is a bug"; |
| 155 | force_log = true; |
| 156 | } |
| 157 | overall_progress_ = new_overall_progress; |
| 158 | |
| 159 | // Update chunk index, log as needed: if forced by called, or we completed a |
| 160 | // progress chunk, or a timeout has expired. |
Sen Jiang | 53c2ec5 | 2019-01-10 15:27:59 -0800 | [diff] [blame] | 161 | base::TimeTicks curr_time = base::TimeTicks::Now(); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 162 | unsigned curr_progress_chunk = |
| 163 | overall_progress_ * kProgressLogMaxChunks / 100; |
| 164 | if (force_log || curr_progress_chunk > last_progress_chunk_ || |
| 165 | curr_time > forced_progress_log_time_) { |
| 166 | forced_progress_log_time_ = curr_time + forced_progress_log_wait_; |
| 167 | LogProgress(message_prefix); |
| 168 | } |
| 169 | last_progress_chunk_ = curr_progress_chunk; |
| 170 | } |
| 171 | |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 172 | size_t DeltaPerformer::CopyDataToBuffer(const char** bytes_p, |
| 173 | size_t* count_p, |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 174 | size_t max) { |
| 175 | const size_t count = *count_p; |
| 176 | if (!count) |
| 177 | return 0; // Special case shortcut. |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 178 | size_t read_len = min(count, max - buffer_.size()); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 179 | const char* bytes_start = *bytes_p; |
| 180 | const char* bytes_end = bytes_start + read_len; |
Sen Jiang | be19a24 | 2017-11-17 11:48:17 -0800 | [diff] [blame] | 181 | buffer_.reserve(max); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 182 | buffer_.insert(buffer_.end(), bytes_start, bytes_end); |
| 183 | *bytes_p = bytes_end; |
| 184 | *count_p = count - read_len; |
| 185 | return read_len; |
| 186 | } |
| 187 | |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 188 | bool DeltaPerformer::HandleOpResult(bool op_result, |
| 189 | const char* op_type_name, |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 190 | ErrorCode* error) { |
| 191 | if (op_result) |
| 192 | return true; |
| 193 | |
| 194 | LOG(ERROR) << "Failed to perform " << op_type_name << " operation " |
Alex Deymo | 3d00906 | 2016-05-13 15:51:25 -0700 | [diff] [blame] | 195 | << next_operation_num_ << ", which is the operation " |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 196 | << GetPartitionOperationNum() << " in partition \"" |
Alex Deymo | 3d00906 | 2016-05-13 15:51:25 -0700 | [diff] [blame] | 197 | << partitions_[current_partition_].partition_name() << "\""; |
Sen Jiang | be2c47b | 2016-06-15 14:09:27 -0700 | [diff] [blame] | 198 | if (*error == ErrorCode::kSuccess) |
| 199 | *error = ErrorCode::kDownloadOperationExecutionError; |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 203 | int DeltaPerformer::Close() { |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 204 | // Checkpoint update progress before canceling, so that subsequent attempts |
| 205 | // can resume from exactly where update_engine left last time. |
| 206 | CheckpointUpdateProgress(true); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 207 | int err = -CloseCurrentPartition(); |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 208 | LOG_IF(ERROR, |
| 209 | !payload_hash_calculator_.Finalize() || |
| 210 | !signed_hash_calculator_.Finalize()) |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 211 | << "Unable to finalize the hash."; |
Darin Petkov | 934bb41 | 2010-11-18 11:21:35 -0800 | [diff] [blame] | 212 | if (!buffer_.empty()) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 213 | LOG(INFO) << "Discarding " << buffer_.size() << " unused downloaded bytes"; |
| 214 | if (err >= 0) |
Darin Petkov | 934bb41 | 2010-11-18 11:21:35 -0800 | [diff] [blame] | 215 | err = 1; |
Darin Petkov | 934bb41 | 2010-11-18 11:21:35 -0800 | [diff] [blame] | 216 | } |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 217 | return -err; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 220 | int DeltaPerformer::CloseCurrentPartition() { |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 221 | if (!partition_writer_) { |
| 222 | return 0; |
| 223 | } |
| 224 | int err = partition_writer_->Close(); |
| 225 | partition_writer_ = nullptr; |
| 226 | return err; |
| 227 | } |
| 228 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 229 | bool DeltaPerformer::OpenCurrentPartition() { |
| 230 | if (current_partition_ >= partitions_.size()) |
| 231 | return false; |
| 232 | |
| 233 | const PartitionUpdate& partition = partitions_[current_partition_]; |
Sen Jiang | d2ff2a0 | 2017-04-06 14:53:31 -0700 | [diff] [blame] | 234 | size_t num_previous_partitions = |
| 235 | install_plan_->partitions.size() - partitions_.size(); |
| 236 | const InstallPlan::Partition& install_part = |
| 237 | install_plan_->partitions[num_previous_partitions + current_partition_]; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 238 | auto dynamic_control = boot_control_->GetDynamicPartitionControl(); |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 239 | partition_writer_ = CreatePartitionWriter( |
| 240 | partition, |
| 241 | install_part, |
| 242 | dynamic_control, |
| 243 | block_size_, |
| 244 | interactive_, |
| 245 | IsDynamicPartition(install_part.name, install_plan_->target_slot)); |
Tianjie | 55abd3c | 2020-06-19 00:22:59 -0700 | [diff] [blame] | 246 | // Open source fds if we have a delta payload, or for partitions in the |
| 247 | // partial update. |
Kelvin Zhang | df3c195 | 2021-10-06 18:56:55 -0700 | [diff] [blame] | 248 | const bool source_may_exist = manifest_.partial_update() || |
| 249 | payload_->type == InstallPayloadType::kDelta; |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 250 | const size_t partition_operation_num = GetPartitionOperationNum(); |
| 251 | |
| 252 | TEST_AND_RETURN_FALSE(partition_writer_->Init( |
| 253 | install_plan_, source_may_exist, partition_operation_num)); |
| 254 | CheckpointUpdateProgress(true); |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | size_t DeltaPerformer::GetPartitionOperationNum() { |
| 259 | return next_operation_num_ - |
| 260 | (current_partition_ ? acc_num_operations_[current_partition_ - 1] : 0); |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 263 | namespace { |
| 264 | |
| 265 | void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { |
Kelvin Zhang | 3fe4964 | 2021-10-04 15:35:02 -0700 | [diff] [blame] | 266 | string sha256 = HexEncode(info.hash()); |
Alex Vakulenko | 981a9fb | 2015-02-09 12:51:24 -0800 | [diff] [blame] | 267 | LOG(INFO) << "PartitionInfo " << tag << " sha256: " << sha256 |
| 268 | << " size: " << info.size(); |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 271 | void LogPartitionInfo(const vector<PartitionUpdate>& partitions) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 272 | for (const PartitionUpdate& partition : partitions) { |
Sen Jiang | 7b9a587 | 2018-01-17 13:25:06 -0800 | [diff] [blame] | 273 | if (partition.has_old_partition_info()) { |
| 274 | LogPartitionInfoHash(partition.old_partition_info(), |
| 275 | "old " + partition.partition_name()); |
| 276 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 277 | LogPartitionInfoHash(partition.new_partition_info(), |
| 278 | "new " + partition.partition_name()); |
| 279 | } |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 282 | } // namespace |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 283 | |
Sen Jiang | b8060e4 | 2015-09-24 17:30:50 -0700 | [diff] [blame] | 284 | bool DeltaPerformer::IsHeaderParsed() const { |
| 285 | return metadata_size_ != 0; |
| 286 | } |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 287 | |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 288 | MetadataParseResult DeltaPerformer::ParsePayloadMetadata( |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 289 | const brillo::Blob& payload, ErrorCode* error) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 290 | *error = ErrorCode::kSuccess; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 291 | |
Sen Jiang | b8060e4 | 2015-09-24 17:30:50 -0700 | [diff] [blame] | 292 | if (!IsHeaderParsed()) { |
Sen Jiang | f123663 | 2018-05-11 16:03:23 -0700 | [diff] [blame] | 293 | MetadataParseResult result = |
| 294 | payload_metadata_.ParsePayloadHeader(payload, error); |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 295 | if (result != MetadataParseResult::kSuccess) |
| 296 | return result; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 297 | |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 298 | metadata_size_ = payload_metadata_.GetMetadataSize(); |
| 299 | metadata_signature_size_ = payload_metadata_.GetMetadataSignatureSize(); |
| 300 | major_payload_version_ = payload_metadata_.GetMajorVersion(); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 301 | |
| 302 | // If the metadata size is present in install plan, check for it immediately |
| 303 | // even before waiting for that many number of bytes to be downloaded in the |
| 304 | // payload. This will prevent any attack which relies on us downloading data |
| 305 | // beyond the expected metadata size. |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 306 | if (install_plan_->hash_checks_mandatory) { |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 307 | if (payload_->metadata_size != metadata_size_) { |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 308 | LOG(ERROR) << "Mandatory metadata size in Omaha response (" |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 309 | << payload_->metadata_size |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 310 | << ") is missing/incorrect, actual = " << metadata_size_; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 311 | *error = ErrorCode::kDownloadInvalidMetadataSize; |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 312 | return MetadataParseResult::kError; |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 313 | } |
| 314 | } |
Andrew | 3a7dc26 | 2019-12-19 11:38:08 -0800 | [diff] [blame] | 315 | |
| 316 | // Check that the |metadata signature size_| and |metadata_size_| are not |
| 317 | // very big numbers. This is necessary since |update_engine| needs to write |
| 318 | // these values into the buffer before being able to use them, and if an |
| 319 | // attacker sets these values to a very big number, the buffer will overflow |
| 320 | // and |update_engine| will crash. A simple way of solving this is to check |
| 321 | // that the size of both values is smaller than the payload itself. |
| 322 | if (metadata_size_ + metadata_signature_size_ > payload_->size) { |
| 323 | LOG(ERROR) << "The size of the metadata_size(" << metadata_size_ << ")" |
| 324 | << " or metadata signature(" << metadata_signature_size_ << ")" |
Daniel Zheng | 1e56e35 | 2024-01-29 12:13:00 -0800 | [diff] [blame] | 325 | << " is greater than the size of the payload" << "(" |
| 326 | << payload_->size << ")"; |
Andrew | 3a7dc26 | 2019-12-19 11:38:08 -0800 | [diff] [blame] | 327 | *error = ErrorCode::kDownloadInvalidMetadataSize; |
| 328 | return MetadataParseResult::kError; |
| 329 | } |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Now that we have validated the metadata size, we should wait for the full |
Sen Jiang | 76bfa74 | 2015-10-12 17:13:26 -0700 | [diff] [blame] | 333 | // metadata and its signature (if exist) to be read in before we can parse it. |
| 334 | if (payload.size() < metadata_size_ + metadata_signature_size_) |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 335 | return MetadataParseResult::kInsufficientData; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 336 | |
| 337 | // Log whether we validated the size or simply trusting what's in the payload |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 338 | // here. This is logged here (after we received the full metadata data) so |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 339 | // that we just log once (instead of logging n times) if it takes n |
| 340 | // DeltaPerformer::Write calls to download the full manifest. |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 341 | if (payload_->metadata_size == metadata_size_) { |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 342 | LOG(INFO) << "Manifest size in payload matches expected value from Omaha"; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 343 | } else { |
| 344 | // For mandatory-cases, we'd have already returned a kMetadataParseError |
| 345 | // above. We'll be here only for non-mandatory cases. Just send a UMA stat. |
| 346 | LOG(WARNING) << "Ignoring missing/incorrect metadata size (" |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 347 | << payload_->metadata_size |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 348 | << ") in Omaha response as validation is not mandatory. " |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 349 | << "Trusting metadata size in payload = " << metadata_size_; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 350 | } |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 351 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 352 | // NOLINTNEXTLINE(whitespace/braces) |
Tianjie Xu | 7a78d63 | 2019-10-08 16:32:39 -0700 | [diff] [blame] | 353 | auto [payload_verifier, perform_verification] = CreatePayloadVerifier(); |
| 354 | if (!payload_verifier) { |
| 355 | LOG(ERROR) << "Failed to create payload verifier."; |
Sen Jiang | 08c6da1 | 2019-01-07 18:28:56 -0800 | [diff] [blame] | 356 | *error = ErrorCode::kDownloadMetadataSignatureVerificationError; |
Tianjie Xu | 6c70b93 | 2019-10-22 16:46:00 -0700 | [diff] [blame] | 357 | if (perform_verification) { |
| 358 | return MetadataParseResult::kError; |
| 359 | } |
| 360 | } else { |
| 361 | // We have the full metadata in |payload|. Verify its integrity |
| 362 | // and authenticity based on the information we have in Omaha response. |
| 363 | *error = payload_metadata_.ValidateMetadataSignature( |
| 364 | payload, payload_->metadata_signature, *payload_verifier); |
Sen Jiang | 08c6da1 | 2019-01-07 18:28:56 -0800 | [diff] [blame] | 365 | } |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 366 | if (*error != ErrorCode::kSuccess) { |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 367 | if (install_plan_->hash_checks_mandatory) { |
David Zeuthen | bc27aac | 2013-11-26 11:17:48 -0800 | [diff] [blame] | 368 | // The autoupdate_CatchBadSignatures test checks for this string |
| 369 | // in log-files. Keep in sync. |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 370 | LOG(ERROR) << "Mandatory metadata signature validation failed"; |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 371 | return MetadataParseResult::kError; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 372 | } |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 373 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 374 | // For non-mandatory cases, just send a UMA stat. |
| 375 | LOG(WARNING) << "Ignoring metadata signature validation failures"; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 376 | *error = ErrorCode::kSuccess; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 379 | // The payload metadata is deemed valid, it's safe to parse the protobuf. |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 380 | if (!payload_metadata_.GetManifest(payload, &manifest_)) { |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 381 | LOG(ERROR) << "Unable to parse manifest in update file."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 382 | *error = ErrorCode::kDownloadManifestParseError; |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 383 | return MetadataParseResult::kError; |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 384 | } |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 385 | |
| 386 | manifest_parsed_ = true; |
Sen Jiang | 9c89e84 | 2018-02-02 13:51:21 -0800 | [diff] [blame] | 387 | return MetadataParseResult::kSuccess; |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Tianjie | 8e0090d | 2021-08-30 22:35:21 -0700 | [diff] [blame] | 390 | #define OP_DURATION_HISTOGRAM(_op_name, _start_time) \ |
| 391 | LOCAL_HISTOGRAM_CUSTOM_TIMES( \ |
| 392 | "UpdateEngine.DownloadAction.InstallOperation::" + string(_op_name) + \ |
| 393 | ".Duration", \ |
| 394 | (base::TimeTicks::Now() - _start_time), \ |
| 395 | base::TimeDelta::FromMilliseconds(10), \ |
| 396 | base::TimeDelta::FromMinutes(5), \ |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 397 | 20); |
Lann Martin | 39f5714 | 2017-07-14 09:18:42 -0600 | [diff] [blame] | 398 | |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 399 | bool DeltaPerformer::CheckSPLDowngrade() { |
Kelvin Zhang | a10fd5a | 2022-09-01 23:39:39 +0000 | [diff] [blame] | 400 | if (!manifest_.has_security_patch_level()) { |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 401 | return true; |
Kelvin Zhang | a10fd5a | 2022-09-01 23:39:39 +0000 | [diff] [blame] | 402 | } |
Kelvin Zhang | 862c46c | 2022-09-02 17:01:12 +0000 | [diff] [blame] | 403 | if (manifest_.security_patch_level().empty()) { |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 404 | return true; |
Kelvin Zhang | 862c46c | 2022-09-02 17:01:12 +0000 | [diff] [blame] | 405 | } |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 406 | const auto new_spl = manifest_.security_patch_level(); |
| 407 | const auto current_spl = |
| 408 | android::base::GetProperty("ro.build.version.security_patch", ""); |
| 409 | if (current_spl.empty()) { |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 410 | LOG(WARNING) << "Failed to get ro.build.version.security_patch, unable to " |
| 411 | "determine if this OTA is a SPL downgrade. Assuming this " |
| 412 | "OTA is not SPL downgrade."; |
| 413 | return true; |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 414 | } |
| 415 | if (new_spl < current_spl) { |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 416 | const auto avb_state = |
| 417 | android::base::GetProperty("ro.boot.verifiedbootstate", "green"); |
| 418 | if (android::base::EqualsIgnoreCase(avb_state, "green")) { |
| 419 | LOG(ERROR) << "Target build SPL " << new_spl |
| 420 | << " is older than current build's SPL " << current_spl |
| 421 | << ", this OTA is an SPL downgrade. Your device's " |
| 422 | "ro.boot.verifiedbootstate=" |
| 423 | << avb_state |
| 424 | << ", it probably has a locked bootlaoder. Since a locked " |
| 425 | "bootloader will reject SPL downgrade no matter what, we " |
| 426 | "will reject this OTA."; |
| 427 | return false; |
| 428 | } |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 429 | install_plan_->powerwash_required = true; |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 430 | LOG(WARNING) |
| 431 | << "Target build SPL " << new_spl |
| 432 | << " is older than current build's SPL " << current_spl |
| 433 | << ", this OTA is an SPL downgrade. Data wipe will be required"; |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 434 | } |
Kelvin Zhang | bdba354 | 2023-02-24 11:08:55 -0800 | [diff] [blame] | 435 | return true; |
Kelvin Zhang | cfc531f | 2022-08-24 17:58:53 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Don Garrett | e410e0f | 2011-11-10 15:39:01 -0800 | [diff] [blame] | 438 | // Wrapper around write. Returns true if all requested bytes |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 439 | // were written, or false on any error, regardless of progress |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 440 | // and stores an action exit code in |error|. |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 441 | bool DeltaPerformer::Write(const void* bytes, size_t count, ErrorCode* error) { |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 442 | if (!error) { |
Daniel Zheng | 1e56e35 | 2024-01-29 12:13:00 -0800 | [diff] [blame] | 443 | LOG(INFO) << "Error Code is not initialized"; |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 444 | return false; |
| 445 | } |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 446 | *error = ErrorCode::kSuccess; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 447 | const char* c_bytes = reinterpret_cast<const char*>(bytes); |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 448 | |
| 449 | // Update the total byte downloaded count and the progress logs. |
| 450 | total_bytes_received_ += count; |
| 451 | UpdateOverallProgress(false, "Completed "); |
| 452 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 453 | while (!manifest_valid_) { |
Daniel Zheng | 40354f8 | 2024-01-30 13:40:02 -0800 | [diff] [blame^] | 454 | bool insufficient_bytes = false; |
| 455 | if (!ParseManifest(&c_bytes, &count, error, &insufficient_bytes)) { |
| 456 | LOG(ERROR) << "Failed to parse manifest"; |
Don Garrett | e410e0f | 2011-11-10 15:39:01 -0800 | [diff] [blame] | 457 | return false; |
Daniel Zheng | 40354f8 | 2024-01-30 13:40:02 -0800 | [diff] [blame^] | 458 | } |
| 459 | if (insufficient_bytes) { |
Don Garrett | e410e0f | 2011-11-10 15:39:01 -0800 | [diff] [blame] | 460 | return true; |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 461 | } |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 462 | } |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 463 | |
| 464 | while (next_operation_num_ < num_total_operations_) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 465 | // Check if we should cancel the current attempt for any reason. |
| 466 | // In this case, *error will have already been populated with the reason |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 467 | // why we're canceling. |
Alex Deymo | 542c19b | 2015-12-03 07:43:31 -0300 | [diff] [blame] | 468 | if (download_delegate_ && download_delegate_->ShouldCancel(error)) |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 469 | return false; |
| 470 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 471 | // We know there are more operations to perform because we didn't reach the |
| 472 | // |num_total_operations_| limit yet. |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 473 | if (next_operation_num_ >= acc_num_operations_[current_partition_]) { |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 474 | if (partition_writer_) { |
Kelvin Zhang | 02fe662 | 2021-11-01 16:37:58 -0700 | [diff] [blame] | 475 | if (!partition_writer_->FinishedInstallOps()) { |
| 476 | *error = ErrorCode::kDownloadWriteError; |
| 477 | return false; |
| 478 | } |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 479 | } |
Kelvin Zhang | b1c0524 | 2023-12-14 13:49:53 -0800 | [diff] [blame] | 480 | const auto err = CloseCurrentPartition(); |
| 481 | if (err < 0) { |
| 482 | LOG(ERROR) << "Failed to close partition " |
| 483 | << partitions_[current_partition_].partition_name() << " " |
| 484 | << strerror(-err); |
| 485 | return false; |
| 486 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 487 | // Skip until there are operations for current_partition_. |
| 488 | while (next_operation_num_ >= acc_num_operations_[current_partition_]) { |
| 489 | current_partition_++; |
| 490 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 491 | if (!OpenCurrentPartition()) { |
| 492 | *error = ErrorCode::kInstallDeviceOpenError; |
| 493 | return false; |
| 494 | } |
| 495 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 496 | |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 497 | const InstallOperation& op = |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 498 | partitions_[current_partition_].operations(GetPartitionOperationNum()); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 499 | |
| 500 | CopyDataToBuffer(&c_bytes, &count, op.data_length()); |
| 501 | |
| 502 | // Check whether we received all of the next operation's data payload. |
| 503 | if (!CanPerformInstallOperation(op)) |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 504 | return true; |
Daniel Zheng | 0dc25a6 | 2024-01-29 13:01:53 -0800 | [diff] [blame] | 505 | if (!ProcessOperation(&op, error)) { |
| 506 | LOG(ERROR) << "unable to process operation: " << *error; |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 507 | return false; |
Daniel Zheng | 0dc25a6 | 2024-01-29 13:01:53 -0800 | [diff] [blame] | 508 | } |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 509 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 510 | next_operation_num_++; |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 511 | UpdateOverallProgress(false, "Completed "); |
Sen Jiang | 3a25dc2 | 2019-01-10 14:14:41 -0800 | [diff] [blame] | 512 | CheckpointUpdateProgress(false); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 513 | } |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 514 | |
Kelvin Zhang | 4f28a6c | 2021-01-14 14:04:57 -0500 | [diff] [blame] | 515 | if (partition_writer_) { |
| 516 | TEST_AND_RETURN_FALSE(partition_writer_->FinishedInstallOps()); |
| 517 | } |
| 518 | CloseCurrentPartition(); |
| 519 | |
Saint Chou | 0a92a62 | 2020-07-29 14:25:35 +0000 | [diff] [blame] | 520 | // In major version 2, we don't add unused operation to the payload. |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 521 | // If we already extracted the signature we should skip this step. |
Amin Hassani | 822d485 | 2020-03-10 01:50:42 +0000 | [diff] [blame] | 522 | if (manifest_.has_signatures_offset() && manifest_.has_signatures_size() && |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 523 | signatures_message_data_.empty()) { |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 524 | if (manifest_.signatures_offset() != buffer_offset_) { |
| 525 | LOG(ERROR) << "Payload signatures offset points to blob offset " |
| 526 | << manifest_.signatures_offset() |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 527 | << " but signatures are expected at offset " << buffer_offset_; |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 528 | *error = ErrorCode::kDownloadPayloadVerificationError; |
| 529 | return false; |
| 530 | } |
| 531 | CopyDataToBuffer(&c_bytes, &count, manifest_.signatures_size()); |
| 532 | // Needs more data to cover entire signature. |
| 533 | if (buffer_.size() < manifest_.signatures_size()) |
| 534 | return true; |
| 535 | if (!ExtractSignatureMessage()) { |
| 536 | LOG(ERROR) << "Extract payload signature failed."; |
| 537 | *error = ErrorCode::kDownloadPayloadVerificationError; |
| 538 | return false; |
| 539 | } |
| 540 | DiscardBuffer(true, 0); |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 541 | // Since we extracted the SignatureMessage we need to advance the |
| 542 | // checkpoint, otherwise we would reload the signature and try to extract |
| 543 | // it again. |
Sen Jiang | 3a25dc2 | 2019-01-10 14:14:41 -0800 | [diff] [blame] | 544 | // This is the last checkpoint for an update, force this checkpoint to be |
| 545 | // saved. |
| 546 | CheckpointUpdateProgress(true); |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Don Garrett | e410e0f | 2011-11-10 15:39:01 -0800 | [diff] [blame] | 549 | return true; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Daniel Zheng | 40354f8 | 2024-01-30 13:40:02 -0800 | [diff] [blame^] | 552 | bool DeltaPerformer::ParseManifest(const char** c_bytes, |
| 553 | size_t* count, |
| 554 | ErrorCode* error, |
| 555 | bool* should_return) { |
| 556 | // Read data up to the needed limit; this is either maximium payload header |
| 557 | // size, or the full metadata size (once it becomes known). |
| 558 | const bool do_read_header = !IsHeaderParsed(); |
| 559 | CopyDataToBuffer( |
| 560 | c_bytes, |
| 561 | count, |
| 562 | (do_read_header ? kMaxPayloadHeaderSize |
| 563 | : metadata_size_ + metadata_signature_size_)); |
| 564 | MetadataParseResult result = ParsePayloadMetadata(buffer_, error); |
| 565 | if (result == MetadataParseResult::kError) |
| 566 | return false; |
| 567 | if (result == MetadataParseResult::kInsufficientData) { |
| 568 | // If we just processed the header, make an attempt on the manifest. |
| 569 | if (do_read_header && IsHeaderParsed()) { |
| 570 | return true; |
| 571 | } |
| 572 | *should_return = true; |
| 573 | return true; |
| 574 | } |
| 575 | |
| 576 | // Checks the integrity of the payload manifest. |
| 577 | if ((*error = ValidateManifest()) != ErrorCode::kSuccess) |
| 578 | return false; |
| 579 | manifest_valid_ = true; |
| 580 | if (!install_plan_->is_resume) { |
| 581 | auto begin = reinterpret_cast<const char*>(buffer_.data()); |
| 582 | prefs_->SetString(kPrefsManifestBytes, {begin, buffer_.size()}); |
| 583 | } |
| 584 | |
| 585 | // Clear the download buffer. |
| 586 | DiscardBuffer(false, metadata_size_); |
| 587 | |
| 588 | block_size_ = manifest_.block_size(); |
| 589 | |
| 590 | if (!install_plan_->spl_downgrade && !CheckSPLDowngrade()) { |
| 591 | *error = ErrorCode::kPayloadTimestampError; |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | // update estimate_cow_size if VABC is disabled |
| 596 | // new_cow_size per partition = partition_size - (#blocks in Copy |
| 597 | // operations part of the partition) |
| 598 | if (install_plan_->vabc_none) { |
| 599 | LOG(INFO) << "Setting Virtual AB Compression algorithm to none. This " |
| 600 | "would also disable VABC XOR as XOR only saves space if " |
| 601 | "compression is enabled."; |
| 602 | manifest_.mutable_dynamic_partition_metadata()->set_vabc_compression_param( |
| 603 | "none"); |
| 604 | for (auto& partition : *manifest_.mutable_partitions()) { |
| 605 | if (!partition.has_estimate_cow_size()) { |
| 606 | continue; |
| 607 | } |
| 608 | auto new_cow_size = partition.new_partition_info().size(); |
| 609 | for (const auto& operation : partition.merge_operations()) { |
| 610 | if (operation.type() == CowMergeOperation::COW_COPY) { |
| 611 | new_cow_size -= |
| 612 | operation.dst_extent().num_blocks() * manifest_.block_size(); |
| 613 | } |
| 614 | } |
| 615 | // Remove all COW_XOR merge ops, as XOR without compression is useless. |
| 616 | // It increases CPU usage but does not reduce space usage at all. |
| 617 | auto&& merge_ops = *partition.mutable_merge_operations(); |
| 618 | merge_ops.erase(std::remove_if(merge_ops.begin(), |
| 619 | merge_ops.end(), |
| 620 | [](const auto& op) { |
| 621 | return op.type() == |
| 622 | CowMergeOperation::COW_XOR; |
| 623 | }), |
| 624 | merge_ops.end()); |
| 625 | |
| 626 | // Every block written to COW device will come with a header which |
| 627 | // stores src/dst block info along with other data. |
| 628 | const auto cow_metadata_size = partition.new_partition_info().size() / |
| 629 | manifest_.block_size() * |
| 630 | sizeof(android::snapshot::CowOperation); |
| 631 | // update_engine will emit a label op every op or every two seconds, |
| 632 | // whichever one is longer. In the worst case, we add 1 label per |
| 633 | // InstallOp. So take size of label ops into account. |
| 634 | const auto label_ops_size = |
| 635 | partition.operations_size() * sizeof(android::snapshot::CowOperation); |
| 636 | // Adding extra 2MB headroom just for any unexpected space usage. |
| 637 | // If we overrun reserved COW size, entire OTA will fail |
| 638 | // and no way for user to retry OTA |
| 639 | partition.set_estimate_cow_size(new_cow_size + (1024 * 1024 * 2) + |
| 640 | cow_metadata_size + label_ops_size); |
| 641 | // Setting op count max to 0 will defer to num_blocks as the op buffer |
| 642 | // size. |
| 643 | partition.set_estimate_op_count_max(0); |
| 644 | LOG(INFO) << "New COW size for partition " << partition.partition_name() |
| 645 | << " is " << partition.estimate_cow_size(); |
| 646 | } |
| 647 | } |
| 648 | if (install_plan_->disable_vabc) { |
| 649 | manifest_.mutable_dynamic_partition_metadata()->set_vabc_enabled(false); |
| 650 | } |
| 651 | if (install_plan_->enable_threading) { |
| 652 | manifest_.mutable_dynamic_partition_metadata() |
| 653 | ->mutable_vabc_feature_set() |
| 654 | ->set_threaded(install_plan_->enable_threading.value()); |
| 655 | LOG(INFO) << "Attempting to " |
| 656 | << (install_plan_->enable_threading.value() ? "enable" |
| 657 | : "disable") |
| 658 | << " multi-threaded compression for VABC"; |
| 659 | } |
| 660 | if (install_plan_->batched_writes) { |
| 661 | manifest_.mutable_dynamic_partition_metadata() |
| 662 | ->mutable_vabc_feature_set() |
| 663 | ->set_batch_writes(true); |
| 664 | LOG(INFO) << "Attempting to enable batched writes for VABC"; |
| 665 | } |
| 666 | |
| 667 | // This populates |partitions_| and the |install_plan.partitions| with the |
| 668 | // list of partitions from the manifest. |
| 669 | if (!ParseManifestPartitions(error)) |
| 670 | return false; |
| 671 | |
| 672 | // |install_plan.partitions| was filled in, nothing need to be done here if |
| 673 | // the payload was already applied, returns false to terminate http fetcher, |
| 674 | // but keep |error| as ErrorCode::kSuccess. |
| 675 | if (payload_->already_applied) |
| 676 | return false; |
| 677 | |
| 678 | num_total_operations_ = 0; |
| 679 | for (const auto& partition : partitions_) { |
| 680 | num_total_operations_ += partition.operations_size(); |
| 681 | acc_num_operations_.push_back(num_total_operations_); |
| 682 | } |
| 683 | |
| 684 | LOG_IF(WARNING, !prefs_->SetInt64(kPrefsManifestMetadataSize, metadata_size_)) |
| 685 | << "Unable to save the manifest metadata size."; |
| 686 | LOG_IF( |
| 687 | WARNING, |
| 688 | !prefs_->SetInt64(kPrefsManifestSignatureSize, metadata_signature_size_)) |
| 689 | << "Unable to save the manifest signature size."; |
| 690 | |
| 691 | if (!PrimeUpdateState()) { |
| 692 | *error = ErrorCode::kDownloadStateInitializationError; |
| 693 | LOG(ERROR) << "Unable to prime the update state."; |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | if (next_operation_num_ < acc_num_operations_[current_partition_]) { |
| 698 | if (!OpenCurrentPartition()) { |
| 699 | *error = ErrorCode::kInstallDeviceOpenError; |
| 700 | return false; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (next_operation_num_ > 0) |
| 705 | UpdateOverallProgress(true, "Resuming after "); |
| 706 | LOG(INFO) << "Starting to apply update payload operations"; |
| 707 | return true; |
| 708 | } |
Daniel Zheng | 0dc25a6 | 2024-01-29 13:01:53 -0800 | [diff] [blame] | 709 | bool DeltaPerformer::ProcessOperation(const InstallOperation* op, |
| 710 | ErrorCode* error) { |
| 711 | // Validate the operation unconditionally. This helps prevent the |
| 712 | // exploitation of vulnerabilities in the patching libraries, e.g. bspatch. |
| 713 | // The hash of the patch data for a given operation is embedded in the |
| 714 | // payload metadata; and thus has been verified against the public key on |
| 715 | // device. |
| 716 | // Note: Validate must be called only if CanPerformInstallOperation is |
| 717 | // called. Otherwise, we might be failing operations before even if there |
| 718 | // isn't sufficient data to compute the proper hash. |
| 719 | *error = ValidateOperationHash(*op); |
| 720 | if (*error != ErrorCode::kSuccess) { |
| 721 | if (install_plan_->hash_checks_mandatory) { |
| 722 | LOG(ERROR) << "Mandatory operation hash check failed"; |
| 723 | return false; |
| 724 | } |
| 725 | |
| 726 | // For non-mandatory cases, just send a UMA stat. |
| 727 | LOG(WARNING) << "Ignoring operation validation errors"; |
| 728 | *error = ErrorCode::kSuccess; |
| 729 | } |
| 730 | |
| 731 | // Makes sure we unblock exit when this operation completes. |
| 732 | ScopedTerminatorExitUnblocker exit_unblocker = |
| 733 | ScopedTerminatorExitUnblocker(); // Avoids a compiler unused var bug. |
| 734 | |
| 735 | base::TimeTicks op_start_time = base::TimeTicks::Now(); |
| 736 | |
| 737 | bool op_result{}; |
| 738 | const string op_name = InstallOperationTypeName(op->type()); |
| 739 | switch (op->type()) { |
| 740 | case InstallOperation::REPLACE: |
| 741 | case InstallOperation::REPLACE_BZ: |
| 742 | case InstallOperation::REPLACE_XZ: |
| 743 | op_result = PerformReplaceOperation(*op); |
| 744 | OP_DURATION_HISTOGRAM("REPLACE", op_start_time); |
| 745 | break; |
| 746 | case InstallOperation::ZERO: |
| 747 | case InstallOperation::DISCARD: |
| 748 | op_result = PerformZeroOrDiscardOperation(*op); |
| 749 | OP_DURATION_HISTOGRAM("ZERO_OR_DISCARD", op_start_time); |
| 750 | break; |
| 751 | case InstallOperation::SOURCE_COPY: |
| 752 | op_result = PerformSourceCopyOperation(*op, error); |
| 753 | OP_DURATION_HISTOGRAM("SOURCE_COPY", op_start_time); |
| 754 | break; |
| 755 | case InstallOperation::SOURCE_BSDIFF: |
| 756 | case InstallOperation::BROTLI_BSDIFF: |
| 757 | case InstallOperation::PUFFDIFF: |
| 758 | case InstallOperation::ZUCCHINI: |
| 759 | case InstallOperation::LZ4DIFF_PUFFDIFF: |
| 760 | case InstallOperation::LZ4DIFF_BSDIFF: |
| 761 | op_result = PerformDiffOperation(*op, error); |
| 762 | OP_DURATION_HISTOGRAM(op_name, op_start_time); |
| 763 | break; |
| 764 | default: |
| 765 | op_result = false; |
| 766 | } |
| 767 | if (!HandleOpResult(op_result, op_name.c_str(), error)) |
| 768 | return false; |
| 769 | |
| 770 | return true; |
| 771 | } |
| 772 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 773 | bool DeltaPerformer::IsManifestValid() { |
| 774 | return manifest_valid_; |
| 775 | } |
| 776 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 777 | bool DeltaPerformer::ParseManifestPartitions(ErrorCode* error) { |
Kelvin Zhang | 20982a5 | 2021-08-13 12:31:16 -0700 | [diff] [blame] | 778 | partitions_.assign(manifest_.partitions().begin(), |
| 779 | manifest_.partitions().end()); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 780 | |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 781 | // For VAB and partial updates, the partition preparation will copy the |
| 782 | // dynamic partitions metadata to the target metadata slot, and rename the |
| 783 | // slot suffix of the partitions in the metadata. |
| 784 | if (install_plan_->target_slot != BootControlInterface::kInvalidSlot) { |
| 785 | uint64_t required_size = 0; |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 786 | if (!PreparePartitionsForUpdate(&required_size, error)) { |
| 787 | if (*error == ErrorCode::kOverlayfsenabledError) { |
| 788 | return false; |
| 789 | } else if (required_size > 0) { |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 790 | *error = ErrorCode::kNotEnoughSpace; |
| 791 | } else { |
| 792 | *error = ErrorCode::kInstallDeviceOpenError; |
| 793 | } |
| 794 | return false; |
| 795 | } |
| 796 | } |
| 797 | |
Tianjie | 55abd3c | 2020-06-19 00:22:59 -0700 | [diff] [blame] | 798 | // Partitions in manifest are no longer needed after preparing partitions. |
Amin Hassani | 822d485 | 2020-03-10 01:50:42 +0000 | [diff] [blame] | 799 | manifest_.clear_partitions(); |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 800 | // TODO(xunchang) TBD: allow partial update only on devices with dynamic |
| 801 | // partition. |
| 802 | if (manifest_.partial_update()) { |
| 803 | std::set<std::string> touched_partitions; |
| 804 | for (const auto& partition_update : partitions_) { |
| 805 | touched_partitions.insert(partition_update.partition_name()); |
| 806 | } |
| 807 | |
Tianjie | 99d570d | 2020-06-04 14:57:19 -0700 | [diff] [blame] | 808 | auto generator = partition_update_generator::Create(boot_control_, |
| 809 | manifest_.block_size()); |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 810 | std::vector<PartitionUpdate> untouched_static_partitions; |
Kelvin Zhang | 430852d | 2023-05-25 17:00:24 -0700 | [diff] [blame] | 811 | if (!generator->GenerateOperationsForPartitionsNotInPayload( |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 812 | install_plan_->source_slot, |
| 813 | install_plan_->target_slot, |
| 814 | touched_partitions, |
Kelvin Zhang | 430852d | 2023-05-25 17:00:24 -0700 | [diff] [blame] | 815 | &untouched_static_partitions)) { |
| 816 | LOG(ERROR) |
| 817 | << "Failed to generate operations for partitions not in payload " |
| 818 | << android::base::Join(touched_partitions, ", "); |
| 819 | *error = ErrorCode::kDownloadStateInitializationError; |
| 820 | return false; |
| 821 | } |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 822 | partitions_.insert(partitions_.end(), |
| 823 | untouched_static_partitions.begin(), |
| 824 | untouched_static_partitions.end()); |
| 825 | |
| 826 | // Save the untouched dynamic partitions in install plan. |
| 827 | std::vector<std::string> dynamic_partitions; |
| 828 | if (!boot_control_->GetDynamicPartitionControl() |
| 829 | ->ListDynamicPartitionsForSlot(install_plan_->source_slot, |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 830 | boot_control_->GetCurrentSlot(), |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 831 | &dynamic_partitions)) { |
| 832 | LOG(ERROR) << "Failed to load dynamic partitions from slot " |
| 833 | << install_plan_->source_slot; |
| 834 | return false; |
| 835 | } |
| 836 | install_plan_->untouched_dynamic_partitions.clear(); |
| 837 | for (const auto& name : dynamic_partitions) { |
| 838 | if (touched_partitions.find(name) == touched_partitions.end()) { |
| 839 | install_plan_->untouched_dynamic_partitions.push_back(name); |
| 840 | } |
| 841 | } |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 844 | const auto start = std::chrono::system_clock::now(); |
Kelvin Zhang | 20982a5 | 2021-08-13 12:31:16 -0700 | [diff] [blame] | 845 | if (!install_plan_->ParsePartitions( |
| 846 | partitions_, boot_control_, block_size_, error)) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 847 | return false; |
| 848 | } |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 849 | const auto duration = std::chrono::system_clock::now() - start; |
| 850 | LOG(INFO) |
| 851 | << "ParsePartitions done. took " |
| 852 | << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() |
| 853 | << " ms"; |
| 854 | |
Kelvin Zhang | ab15beb | 2022-12-05 10:19:52 -0800 | [diff] [blame] | 855 | auto&& has_verity = [](const auto& part) { |
| 856 | return part.fec_extent().num_blocks() > 0 || |
| 857 | part.hash_tree_extent().num_blocks() > 0; |
| 858 | }; |
| 859 | if (!std::any_of(partitions_.begin(), partitions_.end(), has_verity)) { |
| 860 | install_plan_->write_verity = false; |
| 861 | } |
Kelvin Zhang | 20982a5 | 2021-08-13 12:31:16 -0700 | [diff] [blame] | 862 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 863 | LogPartitionInfo(partitions_); |
| 864 | return true; |
| 865 | } |
| 866 | |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 867 | bool DeltaPerformer::PreparePartitionsForUpdate(uint64_t* required_size, |
| 868 | ErrorCode* error) { |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 869 | // Call static PreparePartitionsForUpdate with hash from |
| 870 | // kPrefsUpdateCheckResponseHash to ensure hash of payload that space is |
| 871 | // preallocated for is the same as the hash of payload being applied. |
| 872 | string update_check_response_hash; |
| 873 | ignore_result(prefs_->GetString(kPrefsUpdateCheckResponseHash, |
| 874 | &update_check_response_hash)); |
| 875 | return PreparePartitionsForUpdate(prefs_, |
| 876 | boot_control_, |
| 877 | install_plan_->target_slot, |
| 878 | manifest_, |
| 879 | update_check_response_hash, |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 880 | required_size, |
| 881 | error); |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | bool DeltaPerformer::PreparePartitionsForUpdate( |
| 885 | PrefsInterface* prefs, |
| 886 | BootControlInterface* boot_control, |
| 887 | BootControlInterface::Slot target_slot, |
| 888 | const DeltaArchiveManifest& manifest, |
| 889 | const std::string& update_check_response_hash, |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 890 | uint64_t* required_size, |
| 891 | ErrorCode* error) { |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 892 | string last_hash; |
| 893 | ignore_result( |
| 894 | prefs->GetString(kPrefsDynamicPartitionMetadataUpdated, &last_hash)); |
| 895 | |
| 896 | bool is_resume = !update_check_response_hash.empty() && |
| 897 | last_hash == update_check_response_hash; |
| 898 | |
| 899 | if (is_resume) { |
| 900 | LOG(INFO) << "Using previously prepared partitions for update. hash = " |
| 901 | << last_hash; |
| 902 | } else { |
| 903 | LOG(INFO) << "Preparing partitions for new update. last hash = " |
| 904 | << last_hash << ", new hash = " << update_check_response_hash; |
Kelvin Zhang | 51e08b9 | 2021-02-19 14:54:21 -0500 | [diff] [blame] | 905 | ResetUpdateProgress(prefs, false); |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 908 | const auto start = std::chrono::system_clock::now(); |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 909 | if (!boot_control->GetDynamicPartitionControl()->PreparePartitionsForUpdate( |
| 910 | boot_control->GetCurrentSlot(), |
| 911 | target_slot, |
| 912 | manifest, |
| 913 | !is_resume /* should update */, |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 914 | required_size, |
| 915 | error)) { |
Yifan Hong | 9acd9cb | 2018-10-19 14:52:45 -0700 | [diff] [blame] | 916 | LOG(ERROR) << "Unable to initialize partition metadata for slot " |
Daniel Zheng | eede4c8 | 2023-06-13 11:21:06 -0700 | [diff] [blame] | 917 | << BootControlInterface::SlotName(target_slot) << " " |
| 918 | << utils::ErrorCodeToString(*error); |
Yifan Hong | 9acd9cb | 2018-10-19 14:52:45 -0700 | [diff] [blame] | 919 | return false; |
| 920 | } |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 921 | const auto duration = std::chrono::system_clock::now() - start; |
Yifan Hong | b9d6357 | 2020-01-09 17:50:46 -0800 | [diff] [blame] | 922 | |
| 923 | TEST_AND_RETURN_FALSE(prefs->SetString(kPrefsDynamicPartitionMetadataUpdated, |
| 924 | update_check_response_hash)); |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 925 | LOG(INFO) |
| 926 | << "PreparePartitionsForUpdate done. took " |
| 927 | << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() |
| 928 | << " ms"; |
Yifan Hong | 9acd9cb | 2018-10-19 14:52:45 -0700 | [diff] [blame] | 929 | |
| 930 | return true; |
| 931 | } |
| 932 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 933 | bool DeltaPerformer::CanPerformInstallOperation( |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 934 | const chromeos_update_engine::InstallOperation& operation) { |
Alex Deymo | 0497d05 | 2016-03-23 09:16:59 -0700 | [diff] [blame] | 935 | // If we don't have a data blob we can apply it right away. |
| 936 | if (!operation.has_data_offset() && !operation.has_data_length()) |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 937 | return true; |
| 938 | |
| 939 | // See if we have the entire data blob in the buffer |
| 940 | if (operation.data_offset() < buffer_offset_) { |
| 941 | LOG(ERROR) << "we threw away data it seems?"; |
| 942 | return false; |
| 943 | } |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 944 | |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 945 | return (operation.data_offset() + operation.data_length() <= |
| 946 | buffer_offset_ + buffer_.size()); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 949 | bool DeltaPerformer::PerformReplaceOperation( |
| 950 | const InstallOperation& operation) { |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 951 | CHECK(operation.type() == InstallOperation::REPLACE || |
Alex Deymo | 2d621a3 | 2015-10-01 11:09:01 -0700 | [diff] [blame] | 952 | operation.type() == InstallOperation::REPLACE_BZ || |
| 953 | operation.type() == InstallOperation::REPLACE_XZ); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 954 | |
| 955 | // Since we delete data off the beginning of the buffer as we use it, |
| 956 | // the data we need should be exactly at the beginning of the buffer. |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 957 | TEST_AND_RETURN_FALSE(buffer_.size() >= operation.data_length()); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 958 | |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 959 | TEST_AND_RETURN_FALSE(partition_writer_->PerformReplaceOperation( |
| 960 | operation, buffer_.data(), buffer_.size())); |
| 961 | // Update buffer |
| 962 | DiscardBuffer(true, buffer_.size()); |
| 963 | return true; |
| 964 | } |
| 965 | |
Alex Deymo | 79715ad | 2015-10-02 14:27:53 -0700 | [diff] [blame] | 966 | bool DeltaPerformer::PerformZeroOrDiscardOperation( |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 967 | const InstallOperation& operation) { |
Alex Deymo | 79715ad | 2015-10-02 14:27:53 -0700 | [diff] [blame] | 968 | CHECK(operation.type() == InstallOperation::DISCARD || |
| 969 | operation.type() == InstallOperation::ZERO); |
| 970 | |
| 971 | // These operations have no blob. |
| 972 | TEST_AND_RETURN_FALSE(!operation.has_data_offset()); |
| 973 | TEST_AND_RETURN_FALSE(!operation.has_data_length()); |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 974 | |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 975 | return partition_writer_->PerformZeroOrDiscardOperation(operation); |
| 976 | } |
Alex Deymo | 79715ad | 2015-10-02 14:27:53 -0700 | [diff] [blame] | 977 | |
Allie Wood | 9f6f0a5 | 2015-03-30 11:25:47 -0700 | [diff] [blame] | 978 | bool DeltaPerformer::PerformSourceCopyOperation( |
Sen Jiang | be2c47b | 2016-06-15 14:09:27 -0700 | [diff] [blame] | 979 | const InstallOperation& operation, ErrorCode* error) { |
Allie Wood | 9f6f0a5 | 2015-03-30 11:25:47 -0700 | [diff] [blame] | 980 | if (operation.has_src_length()) |
| 981 | TEST_AND_RETURN_FALSE(operation.src_length() % block_size_ == 0); |
| 982 | if (operation.has_dst_length()) |
| 983 | TEST_AND_RETURN_FALSE(operation.dst_length() % block_size_ == 0); |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 984 | return partition_writer_->PerformSourceCopyOperation(operation, error); |
| 985 | } |
Allie Wood | 9f6f0a5 | 2015-03-30 11:25:47 -0700 | [diff] [blame] | 986 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 987 | bool DeltaPerformer::ExtentsToBsdiffPositionsString( |
| 988 | const RepeatedPtrField<Extent>& extents, |
| 989 | uint64_t block_size, |
| 990 | uint64_t full_length, |
| 991 | string* positions_string) { |
| 992 | string ret; |
| 993 | uint64_t length = 0; |
Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 994 | for (const Extent& extent : extents) { |
Allie Wood | 5687345 | 2015-03-27 17:48:40 -0700 | [diff] [blame] | 995 | int64_t start = extent.start_block() * block_size; |
Tamas Berghammer | 9d66d76 | 2016-07-15 14:19:04 +0100 | [diff] [blame] | 996 | uint64_t this_length = |
| 997 | min(full_length - length, |
| 998 | static_cast<uint64_t>(extent.num_blocks()) * block_size); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 999 | ret += base::StringPrintf("%" PRIi64 ":%" PRIu64 ",", start, this_length); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 1000 | length += this_length; |
| 1001 | } |
| 1002 | TEST_AND_RETURN_FALSE(length == full_length); |
| 1003 | if (!ret.empty()) |
| 1004 | ret.resize(ret.size() - 1); // Strip trailing comma off |
| 1005 | *positions_string = ret; |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
Tianjie | 8e0090d | 2021-08-30 22:35:21 -0700 | [diff] [blame] | 1009 | bool DeltaPerformer::PerformDiffOperation(const InstallOperation& operation, |
| 1010 | ErrorCode* error) { |
Allie Wood | 9f6f0a5 | 2015-03-30 11:25:47 -0700 | [diff] [blame] | 1011 | // Since we delete data off the beginning of the buffer as we use it, |
| 1012 | // the data we need should be exactly at the beginning of the buffer. |
| 1013 | TEST_AND_RETURN_FALSE(buffer_offset_ == operation.data_offset()); |
| 1014 | TEST_AND_RETURN_FALSE(buffer_.size() >= operation.data_length()); |
| 1015 | if (operation.has_src_length()) |
| 1016 | TEST_AND_RETURN_FALSE(operation.src_length() % block_size_ == 0); |
| 1017 | if (operation.has_dst_length()) |
| 1018 | TEST_AND_RETURN_FALSE(operation.dst_length() % block_size_ == 0); |
| 1019 | |
Tianjie | 8e0090d | 2021-08-30 22:35:21 -0700 | [diff] [blame] | 1020 | TEST_AND_RETURN_FALSE(partition_writer_->PerformDiffOperation( |
Kelvin Zhang | 9bd519d | 2020-09-23 12:55:19 -0400 | [diff] [blame] | 1021 | operation, error, buffer_.data(), buffer_.size())); |
| 1022 | DiscardBuffer(true, buffer_.size()); |
| 1023 | return true; |
| 1024 | } |
Amin Hassani | 02855c2 | 2017-09-06 22:34:50 -0700 | [diff] [blame] | 1025 | |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1026 | bool DeltaPerformer::ExtractSignatureMessage() { |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 1027 | TEST_AND_RETURN_FALSE(signatures_message_data_.empty()); |
| 1028 | TEST_AND_RETURN_FALSE(buffer_offset_ == manifest_.signatures_offset()); |
| 1029 | TEST_AND_RETURN_FALSE(buffer_.size() >= manifest_.signatures_size()); |
Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1030 | signatures_message_data_.assign( |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1031 | buffer_.begin(), buffer_.begin() + manifest_.signatures_size()); |
Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1032 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 1033 | LOG(INFO) << "Extracted signature data of size " |
| 1034 | << manifest_.signatures_size() << " at " |
| 1035 | << manifest_.signatures_offset(); |
| 1036 | return true; |
| 1037 | } |
| 1038 | |
Sen Jiang | 08c6da1 | 2019-01-07 18:28:56 -0800 | [diff] [blame] | 1039 | bool DeltaPerformer::GetPublicKey(string* out_public_key) { |
| 1040 | out_public_key->clear(); |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 1041 | |
Sen Jiang | 08c6da1 | 2019-01-07 18:28:56 -0800 | [diff] [blame] | 1042 | if (utils::FileExists(public_key_path_.c_str())) { |
| 1043 | LOG(INFO) << "Verifying using public key: " << public_key_path_; |
| 1044 | return utils::ReadFile(public_key_path_, out_public_key); |
| 1045 | } |
| 1046 | |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 1047 | // If this is an official build then we are not allowed to use public key |
| 1048 | // from Omaha response. |
Sen Jiang | 08c6da1 | 2019-01-07 18:28:56 -0800 | [diff] [blame] | 1049 | if (!hardware_->IsOfficialBuild() && !install_plan_->public_key_rsa.empty()) { |
| 1050 | LOG(INFO) << "Verifying using public key from Omaha response."; |
| 1051 | return brillo::data_encoding::Base64Decode(install_plan_->public_key_rsa, |
| 1052 | out_public_key); |
| 1053 | } |
Tianjie Xu | 7a78d63 | 2019-10-08 16:32:39 -0700 | [diff] [blame] | 1054 | LOG(INFO) << "No public keys found for verification."; |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 1055 | return true; |
| 1056 | } |
| 1057 | |
Tianjie Xu | 7a78d63 | 2019-10-08 16:32:39 -0700 | [diff] [blame] | 1058 | std::pair<std::unique_ptr<PayloadVerifier>, bool> |
| 1059 | DeltaPerformer::CreatePayloadVerifier() { |
| 1060 | if (utils::FileExists(update_certificates_path_.c_str())) { |
| 1061 | LOG(INFO) << "Verifying using certificates: " << update_certificates_path_; |
| 1062 | return { |
| 1063 | PayloadVerifier::CreateInstanceFromZipPath(update_certificates_path_), |
| 1064 | true}; |
| 1065 | } |
| 1066 | |
| 1067 | string public_key; |
| 1068 | if (!GetPublicKey(&public_key)) { |
| 1069 | LOG(ERROR) << "Failed to read public key"; |
| 1070 | return {nullptr, true}; |
| 1071 | } |
| 1072 | |
| 1073 | // Skips the verification if the public key is empty. |
| 1074 | if (public_key.empty()) { |
| 1075 | return {nullptr, false}; |
| 1076 | } |
Kelvin Zhang | 3fe4964 | 2021-10-04 15:35:02 -0700 | [diff] [blame] | 1077 | LOG(INFO) << "Verifing using public key: " << public_key; |
Tianjie Xu | 7a78d63 | 2019-10-08 16:32:39 -0700 | [diff] [blame] | 1078 | return {PayloadVerifier::CreateInstance(public_key), true}; |
| 1079 | } |
| 1080 | |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 1081 | ErrorCode DeltaPerformer::ValidateManifest() { |
Saint Chou | 0a92a62 | 2020-07-29 14:25:35 +0000 | [diff] [blame] | 1082 | // Perform assorted checks to validation check the manifest, make sure it |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 1083 | // matches data from other sources, and that it is a supported version. |
Amin Hassani | 822d485 | 2020-03-10 01:50:42 +0000 | [diff] [blame] | 1084 | bool has_old_fields = std::any_of(manifest_.partitions().begin(), |
| 1085 | manifest_.partitions().end(), |
| 1086 | [](const PartitionUpdate& partition) { |
| 1087 | return partition.has_old_partition_info(); |
| 1088 | }); |
Sen Jiang | c8f6b7a | 2015-10-21 11:09:59 -0700 | [diff] [blame] | 1089 | |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1090 | // The presence of an old partition hash is the sole indicator for a delta |
Tianjie | f5baff4 | 2020-07-17 21:43:22 -0700 | [diff] [blame] | 1091 | // update. Also, always treat the partial update as delta so that we can |
| 1092 | // perform the minor version check correctly. |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1093 | InstallPayloadType actual_payload_type = |
Tianjie | f5baff4 | 2020-07-17 21:43:22 -0700 | [diff] [blame] | 1094 | (has_old_fields || manifest_.partial_update()) |
| 1095 | ? InstallPayloadType::kDelta |
| 1096 | : InstallPayloadType::kFull; |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1097 | |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 1098 | if (payload_->type == InstallPayloadType::kUnknown) { |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1099 | LOG(INFO) << "Detected a '" |
| 1100 | << InstallPayloadTypeToString(actual_payload_type) |
| 1101 | << "' payload."; |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 1102 | payload_->type = actual_payload_type; |
| 1103 | } else if (payload_->type != actual_payload_type) { |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1104 | LOG(ERROR) << "InstallPlan expected a '" |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 1105 | << InstallPayloadTypeToString(payload_->type) |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1106 | << "' payload but the downloaded manifest contains a '" |
| 1107 | << InstallPayloadTypeToString(actual_payload_type) |
| 1108 | << "' payload."; |
| 1109 | return ErrorCode::kPayloadMismatchedType; |
| 1110 | } |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1111 | // Check that the minor version is compatible. |
Tianjie | d3865d1 | 2020-06-03 15:25:17 -0700 | [diff] [blame] | 1112 | // TODO(xunchang) increment minor version & add check for partial update |
Alex Deymo | 64d9878 | 2016-02-05 18:03:48 -0800 | [diff] [blame] | 1113 | if (actual_payload_type == InstallPayloadType::kFull) { |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 1114 | if (manifest_.minor_version() != kFullPayloadMinorVersion) { |
| 1115 | LOG(ERROR) << "Manifest contains minor version " |
| 1116 | << manifest_.minor_version() |
| 1117 | << ", but all full payloads should have version " |
| 1118 | << kFullPayloadMinorVersion << "."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1119 | return ErrorCode::kUnsupportedMinorPayloadVersion; |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 1120 | } |
| 1121 | } else { |
Sen Jiang | f123663 | 2018-05-11 16:03:23 -0700 | [diff] [blame] | 1122 | if (manifest_.minor_version() < kMinSupportedMinorPayloadVersion || |
| 1123 | manifest_.minor_version() > kMaxSupportedMinorPayloadVersion) { |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 1124 | LOG(ERROR) << "Manifest contains minor version " |
| 1125 | << manifest_.minor_version() |
Sen Jiang | f123663 | 2018-05-11 16:03:23 -0700 | [diff] [blame] | 1126 | << " not in the range of supported minor versions [" |
| 1127 | << kMinSupportedMinorPayloadVersion << ", " |
| 1128 | << kMaxSupportedMinorPayloadVersion << "]."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1129 | return ErrorCode::kUnsupportedMinorPayloadVersion; |
Don Garrett | b8dd1d9 | 2013-11-22 17:40:02 -0800 | [diff] [blame] | 1130 | } |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1133 | ErrorCode error_code = CheckTimestampError(); |
| 1134 | if (error_code != ErrorCode::kSuccess) { |
| 1135 | if (error_code == ErrorCode::kPayloadTimestampError) { |
| 1136 | if (!hardware_->AllowDowngrade()) { |
| 1137 | return ErrorCode::kPayloadTimestampError; |
| 1138 | } |
| 1139 | LOG(INFO) << "The current OS build allows downgrade, continuing to apply" |
| 1140 | " the payload with an older timestamp."; |
| 1141 | } else { |
| 1142 | LOG(ERROR) << "Timestamp check returned " |
| 1143 | << utils::ErrorCodeToString(error_code); |
| 1144 | return error_code; |
Tianjie Xu | 4ad3af6 | 2019-10-30 11:59:45 -0700 | [diff] [blame] | 1145 | } |
Sen Jiang | 8e768e9 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Amin Hassani | 55c7541 | 2019-10-07 11:20:39 -0700 | [diff] [blame] | 1148 | // TODO(crbug.com/37661) we should be adding more and more manifest checks, |
| 1149 | // such as partition boundaries, etc. |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 1150 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1151 | return ErrorCode::kSuccess; |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1154 | ErrorCode DeltaPerformer::CheckTimestampError() const { |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1155 | bool is_partial_update = |
| 1156 | manifest_.has_partial_update() && manifest_.partial_update(); |
| 1157 | const auto& partitions = manifest_.partitions(); |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1158 | |
| 1159 | // Check version field for a given PartitionUpdate object. If an error |
| 1160 | // is encountered, set |error_code| accordingly. If downgrade is detected, |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 1161 | // |downgrade_detected| is set. Return true if the program should continue |
| 1162 | // to check the next partition or not, or false if it should exit early due |
| 1163 | // to errors. |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1164 | auto&& timestamp_valid = [this](const PartitionUpdate& partition, |
| 1165 | bool allow_empty_version, |
| 1166 | bool* downgrade_detected) -> ErrorCode { |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1167 | const auto& partition_name = partition.partition_name(); |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1168 | if (!partition.has_version()) { |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1169 | if (hardware_->GetVersionForLogging(partition_name).empty()) { |
| 1170 | LOG(INFO) << partition_name << " does't have version, skipping " |
| 1171 | << "downgrade check."; |
| 1172 | return ErrorCode::kSuccess; |
| 1173 | } |
| 1174 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1175 | if (allow_empty_version) { |
| 1176 | return ErrorCode::kSuccess; |
| 1177 | } |
| 1178 | LOG(ERROR) |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1179 | << "PartitionUpdate " << partition_name |
| 1180 | << " doesn't have a version field. Not allowed in partial updates."; |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1181 | return ErrorCode::kDownloadManifestParseError; |
| 1182 | } |
| 1183 | |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1184 | auto error_code = |
| 1185 | hardware_->IsPartitionUpdateValid(partition_name, partition.version()); |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1186 | switch (error_code) { |
| 1187 | case ErrorCode::kSuccess: |
| 1188 | break; |
| 1189 | case ErrorCode::kPayloadTimestampError: |
| 1190 | *downgrade_detected = true; |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1191 | LOG(WARNING) << "PartitionUpdate " << partition_name |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1192 | << " has an older version than partition on device."; |
| 1193 | break; |
| 1194 | default: |
Tianjie | 19e5529 | 2020-10-19 21:49:37 -0700 | [diff] [blame] | 1195 | LOG(ERROR) << "IsPartitionUpdateValid(" << partition_name |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1196 | << ") returned" << utils::ErrorCodeToString(error_code); |
| 1197 | break; |
| 1198 | } |
| 1199 | return error_code; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1200 | }; |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1201 | |
| 1202 | bool downgrade_detected = false; |
| 1203 | |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1204 | if (is_partial_update) { |
| 1205 | // for partial updates, all partition MUST have valid timestamps |
| 1206 | // But max_timestamp can be empty |
| 1207 | for (const auto& partition : partitions) { |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1208 | auto error_code = timestamp_valid( |
| 1209 | partition, false /* allow_empty_version */, &downgrade_detected); |
| 1210 | if (error_code != ErrorCode::kSuccess && |
| 1211 | error_code != ErrorCode::kPayloadTimestampError) { |
| 1212 | return error_code; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1213 | } |
| 1214 | } |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1215 | if (downgrade_detected) { |
| 1216 | return ErrorCode::kPayloadTimestampError; |
| 1217 | } |
| 1218 | return ErrorCode::kSuccess; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1219 | } |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1220 | |
| 1221 | // For non-partial updates, check max_timestamp first. |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1222 | if (manifest_.max_timestamp() < hardware_->GetBuildTimestamp()) { |
| 1223 | LOG(ERROR) << "The current OS build timestamp (" |
| 1224 | << hardware_->GetBuildTimestamp() |
| 1225 | << ") is newer than the maximum timestamp in the manifest (" |
| 1226 | << manifest_.max_timestamp() << ")"; |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1227 | return ErrorCode::kPayloadTimestampError; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1228 | } |
| 1229 | // Otherwise... partitions can have empty timestamps. |
| 1230 | for (const auto& partition : partitions) { |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1231 | auto error_code = timestamp_valid( |
| 1232 | partition, true /* allow_empty_version */, &downgrade_detected); |
| 1233 | if (error_code != ErrorCode::kSuccess && |
| 1234 | error_code != ErrorCode::kPayloadTimestampError) { |
| 1235 | return error_code; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1236 | } |
| 1237 | } |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 1238 | if (downgrade_detected) { |
| 1239 | return ErrorCode::kPayloadTimestampError; |
| 1240 | } |
| 1241 | return ErrorCode::kSuccess; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 1244 | ErrorCode DeltaPerformer::ValidateOperationHash( |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 1245 | const InstallOperation& operation) { |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1246 | if (!operation.data_sha256_hash().size()) { |
| 1247 | if (!operation.data_length()) { |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 1248 | // Operations that do not have any data blob won't have any operation |
| 1249 | // hash either. So, these operations are always considered validated |
| 1250 | // since the metadata that contains all the non-data-blob portions of |
| 1251 | // the operation has already been validated. This is true for both HTTP |
| 1252 | // and HTTPS cases. |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1253 | return ErrorCode::kSuccess; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 1256 | // No hash is present for an operation that has data blobs. This shouldn't |
| 1257 | // happen normally for any client that has this code, because the |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1258 | // corresponding update should have been produced with the operation |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 1259 | // hashes. So if it happens it means either we've turned operation hash |
| 1260 | // generation off in DeltaDiffGenerator or it's a regression of some sort. |
Saint Chou | 0a92a62 | 2020-07-29 14:25:35 +0000 | [diff] [blame] | 1261 | // One caveat though: The last operation is a unused signature operation |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1262 | // that doesn't have a hash at the time the manifest is created. So we |
| 1263 | // should not complaint about that operation. This operation can be |
| 1264 | // recognized by the fact that it's offset is mentioned in the manifest. |
| 1265 | if (manifest_.signatures_offset() && |
| 1266 | manifest_.signatures_offset() == operation.data_offset()) { |
| 1267 | LOG(INFO) << "Skipping hash verification for signature operation " |
| 1268 | << next_operation_num_ + 1; |
| 1269 | } else { |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 1270 | if (install_plan_->hash_checks_mandatory) { |
| 1271 | LOG(ERROR) << "Missing mandatory operation hash for operation " |
| 1272 | << next_operation_num_ + 1; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1273 | return ErrorCode::kDownloadOperationHashMissingError; |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Jay Srinivasan | 738fdf3 | 2012-12-07 17:40:54 -0800 | [diff] [blame] | 1276 | LOG(WARNING) << "Cannot validate operation " << next_operation_num_ + 1 |
| 1277 | << " as there's no operation hash in manifest"; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1278 | } |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1279 | return ErrorCode::kSuccess; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1282 | brillo::Blob expected_op_hash; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1283 | expected_op_hash.assign(operation.data_sha256_hash().data(), |
| 1284 | (operation.data_sha256_hash().data() + |
| 1285 | operation.data_sha256_hash().size())); |
| 1286 | |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1287 | brillo::Blob calculated_op_hash; |
| 1288 | if (!HashCalculator::RawHashOfBytes( |
| 1289 | buffer_.data(), operation.data_length(), &calculated_op_hash)) { |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1290 | LOG(ERROR) << "Unable to compute actual hash of operation " |
| 1291 | << next_operation_num_; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1292 | return ErrorCode::kDownloadOperationHashVerificationError; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1295 | if (calculated_op_hash != expected_op_hash) { |
| 1296 | LOG(ERROR) << "Hash verification failed for operation " |
Kelvin Zhang | b936892 | 2022-03-17 21:11:32 -0700 | [diff] [blame] | 1297 | << next_operation_num_ |
| 1298 | << ". Expected hash = " << HexEncode(expected_op_hash); |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1299 | LOG(ERROR) << "Calculated hash over " << operation.data_length() |
Kelvin Zhang | b936892 | 2022-03-17 21:11:32 -0700 | [diff] [blame] | 1300 | << " bytes at offset: " << operation.data_offset() << " = " |
| 1301 | << HexEncode(calculated_op_hash); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1302 | return ErrorCode::kDownloadOperationHashMismatch; |
Jay Srinivasan | 00f76b6 | 2012-09-17 18:48:36 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1305 | return ErrorCode::kSuccess; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1308 | #define TEST_AND_RETURN_VAL(_retval, _condition) \ |
| 1309 | do { \ |
| 1310 | if (!(_condition)) { \ |
| 1311 | LOG(ERROR) << "VerifyPayload failure: " << #_condition; \ |
| 1312 | return _retval; \ |
| 1313 | } \ |
Andrew de los Reyes | 771e1bd | 2011-08-30 14:47:23 -0700 | [diff] [blame] | 1314 | } while (0); |
Andrew de los Reyes | fb830ba | 2011-04-04 11:42:43 -0700 | [diff] [blame] | 1315 | |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 1316 | ErrorCode DeltaPerformer::VerifyPayload( |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1317 | const brillo::Blob& update_check_response_hash, |
Andrew de los Reyes | 771e1bd | 2011-08-30 14:47:23 -0700 | [diff] [blame] | 1318 | const uint64_t update_check_response_size) { |
Jay Srinivasan | 0d8fb40 | 2012-05-07 19:19:38 -0700 | [diff] [blame] | 1319 | // Verifies the download size. |
Sen Jiang | 3a25dc2 | 2019-01-10 14:14:41 -0800 | [diff] [blame] | 1320 | if (update_check_response_size != |
| 1321 | metadata_size_ + metadata_signature_size_ + buffer_offset_) { |
| 1322 | LOG(ERROR) << "update_check_response_size (" << update_check_response_size |
| 1323 | << ") doesn't match metadata_size (" << metadata_size_ |
| 1324 | << ") + metadata_signature_size (" << metadata_signature_size_ |
| 1325 | << ") + buffer_offset (" << buffer_offset_ << ")."; |
| 1326 | return ErrorCode::kPayloadSizeMismatchError; |
| 1327 | } |
Jay Srinivasan | 0d8fb40 | 2012-05-07 19:19:38 -0700 | [diff] [blame] | 1328 | |
Amin Hassani | e331f5a | 2020-10-06 15:53:29 -0700 | [diff] [blame] | 1329 | // Verifies the payload hash. |
| 1330 | TEST_AND_RETURN_VAL(ErrorCode::kDownloadPayloadVerificationError, |
| 1331 | !payload_hash_calculator_.raw_hash().empty()); |
Kelvin Zhang | df3c195 | 2021-10-06 18:56:55 -0700 | [diff] [blame] | 1332 | if (payload_hash_calculator_.raw_hash() != update_check_response_hash) { |
| 1333 | LOG(ERROR) << "Actual hash: " |
| 1334 | << HexEncode(payload_hash_calculator_.raw_hash()) |
| 1335 | << ", expected hash: " << HexEncode(update_check_response_hash); |
| 1336 | return ErrorCode::kPayloadHashMismatchError; |
| 1337 | } |
Amin Hassani | e331f5a | 2020-10-06 15:53:29 -0700 | [diff] [blame] | 1338 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 1339 | // NOLINTNEXTLINE(whitespace/braces) |
Amin Hassani | f624e11 | 2020-09-15 15:30:08 -0700 | [diff] [blame] | 1340 | auto [payload_verifier, perform_verification] = CreatePayloadVerifier(); |
| 1341 | if (!perform_verification) { |
| 1342 | LOG(WARNING) << "Not verifying signed delta payload -- missing public key."; |
| 1343 | return ErrorCode::kSuccess; |
| 1344 | } |
| 1345 | if (!payload_verifier) { |
| 1346 | LOG(ERROR) << "Failed to create the payload verifier."; |
| 1347 | return ErrorCode::kDownloadPayloadPubKeyVerificationError; |
| 1348 | } |
| 1349 | |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1350 | TEST_AND_RETURN_VAL(ErrorCode::kSignedDeltaPayloadExpectedError, |
Andrew de los Reyes | 771e1bd | 2011-08-30 14:47:23 -0700 | [diff] [blame] | 1351 | !signatures_message_data_.empty()); |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1352 | brillo::Blob hash_data = signed_hash_calculator_.raw_hash(); |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 1353 | TEST_AND_RETURN_VAL(ErrorCode::kDownloadPayloadPubKeyVerificationError, |
xunchang | cda3c03 | 2019-03-26 15:41:14 -0700 | [diff] [blame] | 1354 | hash_data.size() == kSHA256Size); |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 1355 | |
Tianjie Xu | 6cf830b | 2019-09-30 11:31:49 -0700 | [diff] [blame] | 1356 | if (!payload_verifier->VerifySignature(signatures_message_data_, hash_data)) { |
David Zeuthen | bc27aac | 2013-11-26 11:17:48 -0800 | [diff] [blame] | 1357 | // The autoupdate_CatchBadSignatures test checks for this string |
| 1358 | // in log-files. Keep in sync. |
Alex Deymo | b552a68 | 2015-09-30 09:36:49 -0700 | [diff] [blame] | 1359 | LOG(ERROR) << "Public key verification failed, thus update failed."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1360 | return ErrorCode::kDownloadPayloadPubKeyVerificationError; |
Andrew de los Reyes | fb830ba | 2011-04-04 11:42:43 -0700 | [diff] [blame] | 1361 | } |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 1362 | |
David Zeuthen | e7f8917 | 2013-10-31 10:21:04 -0700 | [diff] [blame] | 1363 | LOG(INFO) << "Payload hash matches value in payload."; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1364 | return ErrorCode::kSuccess; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 1365 | } |
| 1366 | |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1367 | void DeltaPerformer::DiscardBuffer(bool do_advance_offset, |
| 1368 | size_t signed_hash_buffer_size) { |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 1369 | // Update the buffer offset. |
Gilad Arnold | daa2740 | 2014-01-23 11:56:17 -0800 | [diff] [blame] | 1370 | if (do_advance_offset) |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 1371 | buffer_offset_ += buffer_.size(); |
| 1372 | |
| 1373 | // Hash the content. |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1374 | payload_hash_calculator_.Update(buffer_.data(), buffer_.size()); |
| 1375 | signed_hash_calculator_.Update(buffer_.data(), signed_hash_buffer_size); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 1376 | |
| 1377 | // Swap content with an empty vector to ensure that all memory is released. |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1378 | brillo::Blob().swap(buffer_); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1381 | bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs, |
Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 1382 | const string& update_check_response_hash) { |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1383 | int64_t next_operation = kUpdateStateOperationInvalid; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1384 | if (!(prefs->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1385 | next_operation != kUpdateStateOperationInvalid && next_operation > 0)) { |
| 1386 | LOG(WARNING) << "Failed to resume update " << kPrefsUpdateStateNextOperation |
| 1387 | << " invalid: " << next_operation; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1388 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1389 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1390 | |
| 1391 | string interrupted_hash; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1392 | if (!(prefs->GetString(kPrefsUpdateCheckResponseHash, &interrupted_hash) && |
| 1393 | !interrupted_hash.empty() && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1394 | interrupted_hash == update_check_response_hash)) { |
| 1395 | LOG(WARNING) << "Failed to resume update " << kPrefsUpdateCheckResponseHash |
| 1396 | << " mismatch, last hash: " << interrupted_hash |
| 1397 | << ", current hash: " << update_check_response_hash << ""; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1398 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1399 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1400 | |
Daniel Zheng | da4f729 | 2022-09-02 22:59:32 +0000 | [diff] [blame] | 1401 | int64_t resumed_update_failures{}; |
Kelvin Zhang | 50bac65 | 2020-09-28 15:51:41 -0400 | [diff] [blame] | 1402 | // Note that storing this value is optional, but if it is there it should |
| 1403 | // not be more than the limit. |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1404 | if (prefs->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1405 | resumed_update_failures > kMaxResumedUpdateFailures) { |
| 1406 | LOG(WARNING) << "Failed to resume update " << kPrefsResumedUpdateFailures |
Kelvin Zhang | 8ddadd3 | 2023-12-12 12:54:30 -0800 | [diff] [blame] | 1407 | << " has value " << resumed_update_failures |
| 1408 | << " is over the limit " << kMaxResumedUpdateFailures; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1409 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1410 | } |
Darin Petkov | 6142614 | 2010-10-08 11:04:55 -0700 | [diff] [blame] | 1411 | |
Saint Chou | 0a92a62 | 2020-07-29 14:25:35 +0000 | [diff] [blame] | 1412 | // Validation check the rest. |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1413 | int64_t next_data_offset = -1; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1414 | if (!(prefs->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1415 | next_data_offset >= 0)) { |
| 1416 | LOG(WARNING) << "Failed to resume update " |
| 1417 | << kPrefsUpdateStateNextDataOffset |
| 1418 | << " invalid: " << next_data_offset; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1419 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1420 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1421 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 1422 | string sha256_context; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1423 | if (!(prefs->GetString(kPrefsUpdateStateSHA256Context, &sha256_context) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1424 | !sha256_context.empty())) { |
| 1425 | LOG(WARNING) << "Failed to resume update " << kPrefsUpdateStateSHA256Context |
| 1426 | << " is empty."; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1427 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1428 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1429 | |
| 1430 | int64_t manifest_metadata_size = 0; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1431 | if (!(prefs->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1432 | manifest_metadata_size > 0)) { |
| 1433 | LOG(WARNING) << "Failed to resume update " << kPrefsManifestMetadataSize |
| 1434 | << " invalid: " << manifest_metadata_size; |
Alex Deymo | 3310b22 | 2015-03-30 15:59:07 -0700 | [diff] [blame] | 1435 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1436 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1437 | |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1438 | int64_t manifest_signature_size = 0; |
| 1439 | if (!(prefs->GetInt64(kPrefsManifestSignatureSize, |
| 1440 | &manifest_signature_size) && |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1441 | manifest_signature_size >= 0)) { |
| 1442 | LOG(WARNING) << "Failed to resume update " << kPrefsManifestSignatureSize |
| 1443 | << " invalid: " << manifest_signature_size; |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1444 | return false; |
Kelvin Zhang | 42f81b8 | 2022-10-04 10:43:08 -0700 | [diff] [blame] | 1445 | } |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1446 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1447 | return true; |
| 1448 | } |
| 1449 | |
Daniel Zheng | f978480 | 2023-06-08 08:39:48 -0700 | [diff] [blame] | 1450 | bool DeltaPerformer::ResetUpdateProgress( |
| 1451 | PrefsInterface* prefs, |
| 1452 | bool quick, |
| 1453 | bool skip_dynamic_partititon_metadata_updated) { |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1454 | TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation, |
| 1455 | kUpdateStateOperationInvalid)); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1456 | if (!quick) { |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1457 | prefs->SetInt64(kPrefsUpdateStateNextDataOffset, -1); |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1458 | prefs->SetInt64(kPrefsUpdateStateNextDataLength, 0); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1459 | prefs->SetString(kPrefsUpdateStateSHA256Context, ""); |
| 1460 | prefs->SetString(kPrefsUpdateStateSignedSHA256Context, ""); |
Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1461 | prefs->SetString(kPrefsUpdateStateSignatureBlob, ""); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1462 | prefs->SetInt64(kPrefsManifestMetadataSize, -1); |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1463 | prefs->SetInt64(kPrefsManifestSignatureSize, -1); |
Darin Petkov | 6142614 | 2010-10-08 11:04:55 -0700 | [diff] [blame] | 1464 | prefs->SetInt64(kPrefsResumedUpdateFailures, 0); |
Sen Jiang | fe52282 | 2017-10-31 15:14:11 -0700 | [diff] [blame] | 1465 | prefs->Delete(kPrefsPostInstallSucceeded); |
Sen Jiang | 3eeaf7d | 2018-10-11 13:55:32 -0700 | [diff] [blame] | 1466 | prefs->Delete(kPrefsVerityWritten); |
Daniel Zheng | f978480 | 2023-06-08 08:39:48 -0700 | [diff] [blame] | 1467 | if (!skip_dynamic_partititon_metadata_updated) { |
| 1468 | LOG(INFO) << "Resetting recorded hash for prepared partitions."; |
| 1469 | prefs->Delete(kPrefsDynamicPartitionMetadataUpdated); |
| 1470 | } |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1471 | } |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 1472 | return true; |
| 1473 | } |
| 1474 | |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1475 | bool DeltaPerformer::ShouldCheckpoint() { |
Sen Jiang | 53c2ec5 | 2019-01-10 15:27:59 -0800 | [diff] [blame] | 1476 | base::TimeTicks curr_time = base::TimeTicks::Now(); |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1477 | if (curr_time > update_checkpoint_time_) { |
Colin Howes | 0e452c9 | 2018-11-02 13:18:44 -0700 | [diff] [blame] | 1478 | update_checkpoint_time_ = curr_time + update_checkpoint_wait_; |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1479 | return true; |
| 1480 | } |
| 1481 | return false; |
| 1482 | } |
| 1483 | |
| 1484 | bool DeltaPerformer::CheckpointUpdateProgress(bool force) { |
| 1485 | if (!force && !ShouldCheckpoint()) { |
Colin Howes | 0e452c9 | 2018-11-02 13:18:44 -0700 | [diff] [blame] | 1486 | return false; |
| 1487 | } |
Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 1488 | Terminator::set_exit_blocked(true); |
Daniel Zheng | 5eece04 | 2023-05-17 14:44:10 -0700 | [diff] [blame] | 1489 | LOG_IF(WARNING, !prefs_->StartTransaction()) |
| 1490 | << "unable to start transaction in checkpointing"; |
| 1491 | DEFER { |
| 1492 | prefs_->CancelTransaction(); |
| 1493 | }; |
Kelvin Zhang | 3265b31 | 2020-12-16 15:51:30 -0500 | [diff] [blame] | 1494 | if (last_updated_operation_num_ != next_operation_num_ || force) { |
Kelvin Zhang | bb8e999 | 2020-12-28 10:28:48 -0500 | [diff] [blame] | 1495 | if (!signatures_message_data_.empty()) { |
| 1496 | // Save the signature blob because if the update is interrupted after the |
| 1497 | // download phase we don't go through this path anymore. Some alternatives |
| 1498 | // to consider: |
| 1499 | // |
| 1500 | // 1. On resume, re-download the signature blob from the server and |
| 1501 | // re-verify it. |
| 1502 | // |
| 1503 | // 2. Verify the signature as soon as it's received and don't checkpoint |
| 1504 | // the blob and the signed sha-256 context. |
| 1505 | LOG_IF(WARNING, |
| 1506 | !prefs_->SetString(kPrefsUpdateStateSignatureBlob, |
| 1507 | signatures_message_data_)) |
| 1508 | << "Unable to store the signature blob."; |
| 1509 | } |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1510 | TEST_AND_RETURN_FALSE(prefs_->SetString( |
| 1511 | kPrefsUpdateStateSHA256Context, payload_hash_calculator_.GetContext())); |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1512 | TEST_AND_RETURN_FALSE( |
| 1513 | prefs_->SetString(kPrefsUpdateStateSignedSHA256Context, |
| 1514 | signed_hash_calculator_.GetContext())); |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1515 | TEST_AND_RETURN_FALSE( |
| 1516 | prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, buffer_offset_)); |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1517 | last_updated_operation_num_ = next_operation_num_; |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1518 | |
| 1519 | if (next_operation_num_ < num_total_operations_) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 1520 | size_t partition_index = current_partition_; |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1521 | while (next_operation_num_ >= acc_num_operations_[partition_index]) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 1522 | partition_index++; |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1523 | } |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1524 | const size_t partition_operation_num = |
| 1525 | next_operation_num_ - |
| 1526 | (partition_index ? acc_num_operations_[partition_index - 1] : 0); |
Alex Deymo | a12ee11 | 2015-08-12 22:19:32 -0700 | [diff] [blame] | 1527 | const InstallOperation& op = |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 1528 | partitions_[partition_index].operations(partition_operation_num); |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1529 | TEST_AND_RETURN_FALSE( |
| 1530 | prefs_->SetInt64(kPrefsUpdateStateNextDataLength, op.data_length())); |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1531 | } else { |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1532 | TEST_AND_RETURN_FALSE( |
| 1533 | prefs_->SetInt64(kPrefsUpdateStateNextDataLength, 0)); |
David Zeuthen | 41996ad | 2013-09-24 15:43:24 -0700 | [diff] [blame] | 1534 | } |
Kelvin Zhang | e4235b0 | 2020-11-23 13:57:51 -0500 | [diff] [blame] | 1535 | if (partition_writer_) { |
| 1536 | partition_writer_->CheckpointUpdateProgress(GetPartitionOperationNum()); |
| 1537 | } else { |
| 1538 | CHECK_EQ(next_operation_num_, num_total_operations_) |
| 1539 | << "Partition writer is null, we are expected to finish all " |
| 1540 | "operations: " |
| 1541 | << next_operation_num_ << "/" << num_total_operations_; |
| 1542 | } |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 1543 | } |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1544 | TEST_AND_RETURN_FALSE( |
| 1545 | prefs_->SetInt64(kPrefsUpdateStateNextOperation, next_operation_num_)); |
Daniel Zheng | 5eece04 | 2023-05-17 14:44:10 -0700 | [diff] [blame] | 1546 | if (!prefs_->SubmitTransaction()) { |
| 1547 | LOG(ERROR) << "Failed to submit transaction in checkpointing"; |
| 1548 | } |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 1549 | return true; |
| 1550 | } |
| 1551 | |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1552 | bool DeltaPerformer::PrimeUpdateState() { |
| 1553 | CHECK(manifest_valid_); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1554 | |
| 1555 | int64_t next_operation = kUpdateStateOperationInvalid; |
| 1556 | if (!prefs_->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) || |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1557 | next_operation == kUpdateStateOperationInvalid || next_operation <= 0) { |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1558 | // Initiating a new update, no more state needs to be initialized. |
| 1559 | return true; |
| 1560 | } |
| 1561 | next_operation_num_ = next_operation; |
| 1562 | |
| 1563 | // Resuming an update -- load the rest of the update state. |
| 1564 | int64_t next_data_offset = -1; |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1565 | TEST_AND_RETURN_FALSE( |
| 1566 | prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset) && |
| 1567 | next_data_offset >= 0); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1568 | buffer_offset_ = next_data_offset; |
| 1569 | |
Darin Petkov | 4f0a07b | 2011-05-25 16:47:20 -0700 | [diff] [blame] | 1570 | // The signed hash context and the signature blob may be empty if the |
| 1571 | // interrupted update didn't reach the signature. |
Sen Jiang | f681380 | 2015-11-03 21:27:29 -0800 | [diff] [blame] | 1572 | string signed_hash_context; |
| 1573 | if (prefs_->GetString(kPrefsUpdateStateSignedSHA256Context, |
| 1574 | &signed_hash_context)) { |
| 1575 | TEST_AND_RETURN_FALSE( |
| 1576 | signed_hash_calculator_.SetContext(signed_hash_context)); |
| 1577 | } |
| 1578 | |
Sen Jiang | 9b2f178 | 2019-01-24 14:27:50 -0800 | [diff] [blame] | 1579 | prefs_->GetString(kPrefsUpdateStateSignatureBlob, &signatures_message_data_); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1580 | |
| 1581 | string hash_context; |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1582 | TEST_AND_RETURN_FALSE( |
| 1583 | prefs_->GetString(kPrefsUpdateStateSHA256Context, &hash_context) && |
| 1584 | payload_hash_calculator_.SetContext(hash_context)); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1585 | |
| 1586 | int64_t manifest_metadata_size = 0; |
Amin Hassani | 008c458 | 2019-01-13 16:22:47 -0800 | [diff] [blame] | 1587 | TEST_AND_RETURN_FALSE( |
| 1588 | prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size) && |
| 1589 | manifest_metadata_size > 0); |
Gilad Arnold | fe13393 | 2014-01-14 12:25:50 -0800 | [diff] [blame] | 1590 | metadata_size_ = manifest_metadata_size; |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1591 | |
Alex Deymo | f25eb49 | 2016-02-26 00:20:08 -0800 | [diff] [blame] | 1592 | int64_t manifest_signature_size = 0; |
| 1593 | TEST_AND_RETURN_FALSE( |
| 1594 | prefs_->GetInt64(kPrefsManifestSignatureSize, &manifest_signature_size) && |
| 1595 | manifest_signature_size >= 0); |
| 1596 | metadata_signature_size_ = manifest_signature_size; |
| 1597 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 1598 | // Advance the download progress to reflect what doesn't need to be |
| 1599 | // re-downloaded. |
| 1600 | total_bytes_received_ += buffer_offset_; |
| 1601 | |
Darin Petkov | 6142614 | 2010-10-08 11:04:55 -0700 | [diff] [blame] | 1602 | // Speculatively count the resume as a failure. |
Daniel Zheng | da4f729 | 2022-09-02 22:59:32 +0000 | [diff] [blame] | 1603 | int64_t resumed_update_failures{}; |
Darin Petkov | 6142614 | 2010-10-08 11:04:55 -0700 | [diff] [blame] | 1604 | if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
| 1605 | resumed_update_failures++; |
| 1606 | } else { |
| 1607 | resumed_update_failures = 1; |
| 1608 | } |
| 1609 | prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 1610 | return true; |
| 1611 | } |
| 1612 | |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1613 | bool DeltaPerformer::IsDynamicPartition(const std::string& part_name, |
| 1614 | uint32_t slot) { |
Tianjie | 3a55fc2 | 2021-02-13 16:02:22 -0800 | [diff] [blame] | 1615 | return boot_control_->GetDynamicPartitionControl()->IsDynamicPartition( |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1616 | part_name, slot); |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 1617 | } |
| 1618 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame] | 1619 | std::unique_ptr<PartitionWriterInterface> DeltaPerformer::CreatePartitionWriter( |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1620 | const PartitionUpdate& partition_update, |
| 1621 | const InstallPlan::Partition& install_part, |
| 1622 | DynamicPartitionControlInterface* dynamic_control, |
| 1623 | size_t block_size, |
| 1624 | bool is_interactive, |
| 1625 | bool is_dynamic_partition) { |
| 1626 | return partition_writer::CreatePartitionWriter( |
| 1627 | partition_update, |
| 1628 | install_part, |
| 1629 | dynamic_control, |
| 1630 | block_size_, |
| 1631 | interactive_, |
Kelvin Zhang | ebd115e | 2021-03-08 16:10:25 -0500 | [diff] [blame] | 1632 | IsDynamicPartition(install_part.name, install_plan_->target_slot)); |
Kelvin Zhang | cfe694f | 2020-11-13 13:10:42 -0500 | [diff] [blame] | 1633 | } |
| 1634 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 1635 | } // namespace chromeos_update_engine |