blob: 274465cd12a58b3e92728673812c34d4f1fabecd [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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 Reyes09e56d62010-04-23 13:45:53 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/payload_consumer/delta_performer.h"
Darin Petkovd7061ab2010-10-06 14:37:09 -070018
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070019#include <errno.h>
Alex Deymo79715ad2015-10-02 14:27:53 -070020#include <linux/fs.h>
Darin Petkovd7061ab2010-10-06 14:37:09 -070021
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070022#include <algorithm>
23#include <cstring>
Yifan Hong537802d2018-08-15 13:15:42 -070024#include <map>
Ben Chan02f7c1d2014-10-18 15:18:02 -070025#include <memory>
Tianjied3865d12020-06-03 15:25:17 -070026#include <set>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070027#include <string>
Amin Hassanid87304c2017-08-29 11:40:03 -070028#include <utility>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070029#include <vector>
30
Ben Chan06c76a42014-09-05 08:21:06 -070031#include <base/files/file_util.h>
Alex Deymo161c4a12014-05-16 15:56:21 -070032#include <base/format_macros.h>
Lann Martin39f57142017-07-14 09:18:42 -060033#include <base/metrics/histogram_macros.h>
Alex Deymo67140842016-06-15 13:28:59 -070034#include <base/strings/string_number_conversions.h>
Lann Martin39f57142017-07-14 09:18:42 -060035#include <base/time/time.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070036#include <brillo/data_encoding.h>
Alex Deymo6765a682017-05-19 13:13:54 -070037#include <bsdiff/bspatch.h>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070038#include <google/protobuf/repeated_field.h>
Amin Hassani02855c22017-09-06 22:34:50 -070039#include <puffin/puffpatch.h>
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070040
Alex Deymo39910dc2015-11-09 17:04:30 -080041#include "update_engine/common/constants.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070042#include "update_engine/common/download_action.h"
Yifan Hong87029332020-09-01 17:20:08 -070043#include "update_engine/common/error_code.h"
44#include "update_engine/common/error_code_utils.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080045#include "update_engine/common/hardware_interface.h"
Alex Deymo542c19b2015-12-03 07:43:31 -030046#include "update_engine/common/prefs_interface.h"
47#include "update_engine/common/subprocess.h"
48#include "update_engine/common/terminator.h"
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040049#include "update_engine/common/utils.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080050#include "update_engine/payload_consumer/bzip_extent_writer.h"
Amin Hassania3fc20a2017-09-19 17:19:34 -070051#include "update_engine/payload_consumer/cached_file_descriptor.h"
Tianjie Xu7a78d632019-10-08 16:32:39 -070052#include "update_engine/payload_consumer/certificate_parser_interface.h"
Amin Hassanidb56be92017-09-06 12:41:23 -070053#include "update_engine/payload_consumer/extent_reader.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080054#include "update_engine/payload_consumer/extent_writer.h"
Tianjied3865d12020-06-03 15:25:17 -070055#include "update_engine/payload_consumer/partition_update_generator_interface.h"
Kelvin Zhang50bac652020-09-28 15:51:41 -040056#include "update_engine/payload_consumer/partition_writer.h"
Alex Deymo51c264e2016-11-04 15:49:53 -070057#if USE_FEC
58#include "update_engine/payload_consumer/fec_file_descriptor.h"
59#endif // USE_FEC
Alex Deymoa48f6302016-11-04 15:49:53 -070060#include "update_engine/payload_consumer/file_descriptor_utils.h"
HÃ¥kan Kvist4e13cf42018-01-23 12:57:55 +010061#include "update_engine/payload_consumer/mount_history.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080062#include "update_engine/payload_consumer/payload_constants.h"
63#include "update_engine/payload_consumer/payload_verifier.h"
64#include "update_engine/payload_consumer/xz_extent_writer.h"
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070065
Alex Deymo161c4a12014-05-16 15:56:21 -070066using google::protobuf::RepeatedPtrField;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070067using std::min;
68using std::string;
69using std::vector;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070070
71namespace chromeos_update_engine {
Gilad Arnold8a86fa52013-01-15 12:35:05 -080072const unsigned DeltaPerformer::kProgressLogMaxChunks = 10;
73const unsigned DeltaPerformer::kProgressLogTimeoutSeconds = 30;
74const unsigned DeltaPerformer::kProgressDownloadWeight = 50;
75const unsigned DeltaPerformer::kProgressOperationsWeight = 50;
Colin Howes0e452c92018-11-02 13:18:44 -070076const uint64_t DeltaPerformer::kCheckpointFrequencySeconds = 1;
Darin Petkovabc7bc02011-02-23 14:39:43 -080077
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070078namespace {
Darin Petkov73058b42010-10-06 16:32:19 -070079const int kUpdateStateOperationInvalid = -1;
Darin Petkov61426142010-10-08 11:04:55 -070080const int kMaxResumedUpdateFailures = 10;
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -080081
Alex Vakulenkod2779df2014-06-16 13:19:00 -070082} // namespace
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070083
Gilad Arnold8a86fa52013-01-15 12:35:05 -080084// Computes the ratio of |part| and |total|, scaled to |norm|, using integer
85// arithmetic.
86static uint64_t IntRatio(uint64_t part, uint64_t total, uint64_t norm) {
87 return part * norm / total;
88}
89
90void DeltaPerformer::LogProgress(const char* message_prefix) {
91 // Format operations total count and percentage.
92 string total_operations_str("?");
93 string completed_percentage_str("");
94 if (num_total_operations_) {
Alex Deymoc00c98a2015-03-17 17:38:00 -070095 total_operations_str = std::to_string(num_total_operations_);
Gilad Arnold8a86fa52013-01-15 12:35:05 -080096 // Upcasting to 64-bit to avoid overflow, back to size_t for formatting.
Amin Hassani008c4582019-01-13 16:22:47 -080097 completed_percentage_str = base::StringPrintf(
98 " (%" PRIu64 "%%)",
99 IntRatio(next_operation_num_, num_total_operations_, 100));
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800100 }
101
102 // Format download total count and percentage.
Sen Jiang0affc2c2017-02-10 15:55:05 -0800103 size_t payload_size = payload_->size;
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800104 string payload_size_str("?");
105 string downloaded_percentage_str("");
106 if (payload_size) {
Alex Deymoc00c98a2015-03-17 17:38:00 -0700107 payload_size_str = std::to_string(payload_size);
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800108 // Upcasting to 64-bit to avoid overflow, back to size_t for formatting.
Amin Hassani008c4582019-01-13 16:22:47 -0800109 downloaded_percentage_str = base::StringPrintf(
110 " (%" PRIu64 "%%)", IntRatio(total_bytes_received_, payload_size, 100));
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800111 }
112
113 LOG(INFO) << (message_prefix ? message_prefix : "") << next_operation_num_
114 << "/" << total_operations_str << " operations"
Amin Hassani008c4582019-01-13 16:22:47 -0800115 << completed_percentage_str << ", " << total_bytes_received_ << "/"
116 << payload_size_str << " bytes downloaded"
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800117 << downloaded_percentage_str << ", overall progress "
118 << overall_progress_ << "%";
119}
120
121void DeltaPerformer::UpdateOverallProgress(bool force_log,
122 const char* message_prefix) {
123 // Compute our download and overall progress.
124 unsigned new_overall_progress = 0;
Alex Vakulenko0103c362016-01-20 07:56:15 -0800125 static_assert(kProgressDownloadWeight + kProgressOperationsWeight == 100,
126 "Progress weights don't add up");
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800127 // Only consider download progress if its total size is known; otherwise
128 // adjust the operations weight to compensate for the absence of download
129 // progress. Also, make sure to cap the download portion at
130 // kProgressDownloadWeight, in case we end up downloading more than we
131 // initially expected (this indicates a problem, but could generally happen).
132 // TODO(garnold) the correction of operations weight when we do not have the
133 // total payload size, as well as the conditional guard below, should both be
134 // eliminated once we ensure that the payload_size in the install plan is
135 // always given and is non-zero. This currently isn't the case during unit
136 // tests (see chromium-os:37969).
Sen Jiang0affc2c2017-02-10 15:55:05 -0800137 size_t payload_size = payload_->size;
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800138 unsigned actual_operations_weight = kProgressOperationsWeight;
139 if (payload_size)
Amin Hassani008c4582019-01-13 16:22:47 -0800140 new_overall_progress +=
141 min(static_cast<unsigned>(IntRatio(
142 total_bytes_received_, payload_size, kProgressDownloadWeight)),
143 kProgressDownloadWeight);
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800144 else
145 actual_operations_weight += kProgressDownloadWeight;
146
147 // Only add completed operations if their total number is known; we definitely
148 // expect an update to have at least one operation, so the expectation is that
149 // this will eventually reach |actual_operations_weight|.
150 if (num_total_operations_)
Amin Hassani008c4582019-01-13 16:22:47 -0800151 new_overall_progress += IntRatio(
152 next_operation_num_, num_total_operations_, actual_operations_weight);
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800153
154 // Progress ratio cannot recede, unless our assumptions about the total
155 // payload size, total number of operations, or the monotonicity of progress
156 // is breached.
157 if (new_overall_progress < overall_progress_) {
158 LOG(WARNING) << "progress counter receded from " << overall_progress_
159 << "% down to " << new_overall_progress << "%; this is a bug";
160 force_log = true;
161 }
162 overall_progress_ = new_overall_progress;
163
164 // Update chunk index, log as needed: if forced by called, or we completed a
165 // progress chunk, or a timeout has expired.
Sen Jiang53c2ec52019-01-10 15:27:59 -0800166 base::TimeTicks curr_time = base::TimeTicks::Now();
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800167 unsigned curr_progress_chunk =
168 overall_progress_ * kProgressLogMaxChunks / 100;
169 if (force_log || curr_progress_chunk > last_progress_chunk_ ||
170 curr_time > forced_progress_log_time_) {
171 forced_progress_log_time_ = curr_time + forced_progress_log_wait_;
172 LogProgress(message_prefix);
173 }
174 last_progress_chunk_ = curr_progress_chunk;
175}
176
Amin Hassani008c4582019-01-13 16:22:47 -0800177size_t DeltaPerformer::CopyDataToBuffer(const char** bytes_p,
178 size_t* count_p,
Gilad Arnoldfe133932014-01-14 12:25:50 -0800179 size_t max) {
180 const size_t count = *count_p;
181 if (!count)
182 return 0; // Special case shortcut.
Alex Deymof329b932014-10-30 01:37:48 -0700183 size_t read_len = min(count, max - buffer_.size());
Gilad Arnoldfe133932014-01-14 12:25:50 -0800184 const char* bytes_start = *bytes_p;
185 const char* bytes_end = bytes_start + read_len;
Sen Jiangbe19a242017-11-17 11:48:17 -0800186 buffer_.reserve(max);
Gilad Arnoldfe133932014-01-14 12:25:50 -0800187 buffer_.insert(buffer_.end(), bytes_start, bytes_end);
188 *bytes_p = bytes_end;
189 *count_p = count - read_len;
190 return read_len;
191}
192
Amin Hassani008c4582019-01-13 16:22:47 -0800193bool DeltaPerformer::HandleOpResult(bool op_result,
194 const char* op_type_name,
Gilad Arnoldfe133932014-01-14 12:25:50 -0800195 ErrorCode* error) {
196 if (op_result)
197 return true;
198
199 LOG(ERROR) << "Failed to perform " << op_type_name << " operation "
Alex Deymo3d009062016-05-13 15:51:25 -0700200 << next_operation_num_ << ", which is the operation "
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400201 << GetPartitionOperationNum() << " in partition \""
Alex Deymo3d009062016-05-13 15:51:25 -0700202 << partitions_[current_partition_].partition_name() << "\"";
Sen Jiangbe2c47b2016-06-15 14:09:27 -0700203 if (*error == ErrorCode::kSuccess)
204 *error = ErrorCode::kDownloadOperationExecutionError;
Gilad Arnoldfe133932014-01-14 12:25:50 -0800205 return false;
206}
207
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700208int DeltaPerformer::Close() {
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700209 int err = -CloseCurrentPartition();
Amin Hassani008c4582019-01-13 16:22:47 -0800210 LOG_IF(ERROR,
211 !payload_hash_calculator_.Finalize() ||
212 !signed_hash_calculator_.Finalize())
Sen Jiangf6813802015-11-03 21:27:29 -0800213 << "Unable to finalize the hash.";
Darin Petkov934bb412010-11-18 11:21:35 -0800214 if (!buffer_.empty()) {
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700215 LOG(INFO) << "Discarding " << buffer_.size() << " unused downloaded bytes";
216 if (err >= 0)
Darin Petkov934bb412010-11-18 11:21:35 -0800217 err = 1;
Darin Petkov934bb412010-11-18 11:21:35 -0800218 }
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700219 return -err;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700220}
221
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700222int DeltaPerformer::CloseCurrentPartition() {
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400223 if (!partition_writer_) {
224 return 0;
225 }
226 int err = partition_writer_->Close();
227 partition_writer_ = nullptr;
228 return err;
229}
230
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700231bool DeltaPerformer::OpenCurrentPartition() {
232 if (current_partition_ >= partitions_.size())
233 return false;
234
235 const PartitionUpdate& partition = partitions_[current_partition_];
Sen Jiangd2ff2a02017-04-06 14:53:31 -0700236 size_t num_previous_partitions =
237 install_plan_->partitions.size() - partitions_.size();
238 const InstallPlan::Partition& install_part =
239 install_plan_->partitions[num_previous_partitions + current_partition_];
Kelvin Zhang94f51cc2020-09-25 11:34:49 -0400240 auto dynamic_control = boot_control_->GetDynamicPartitionControl();
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500241 partition_writer_ = CreatePartitionWriter(
242 partition,
243 install_part,
244 dynamic_control,
245 block_size_,
246 interactive_,
247 IsDynamicPartition(install_part.name, install_plan_->target_slot));
Tianjie55abd3c2020-06-19 00:22:59 -0700248 // Open source fds if we have a delta payload, or for partitions in the
249 // partial update.
Tianjied3865d12020-06-03 15:25:17 -0700250 bool source_may_exist = manifest_.partial_update() ||
Tianjie55abd3c2020-06-19 00:22:59 -0700251 payload_->type == InstallPayloadType::kDelta;
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400252 const size_t partition_operation_num = GetPartitionOperationNum();
253
254 TEST_AND_RETURN_FALSE(partition_writer_->Init(
255 install_plan_, source_may_exist, partition_operation_num));
256 CheckpointUpdateProgress(true);
257 return true;
258}
259
260size_t DeltaPerformer::GetPartitionOperationNum() {
261 return next_operation_num_ -
262 (current_partition_ ? acc_num_operations_[current_partition_ - 1] : 0);
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400263}
264
Andrew de los Reyes89f17be2010-10-22 13:39:09 -0700265namespace {
266
267void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700268 string sha256 = brillo::data_encoding::Base64Encode(info.hash());
Alex Vakulenko981a9fb2015-02-09 12:51:24 -0800269 LOG(INFO) << "PartitionInfo " << tag << " sha256: " << sha256
270 << " size: " << info.size();
Andrew de los Reyes89f17be2010-10-22 13:39:09 -0700271}
272
Alex Deymo39910dc2015-11-09 17:04:30 -0800273void LogPartitionInfo(const vector<PartitionUpdate>& partitions) {
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700274 for (const PartitionUpdate& partition : partitions) {
Sen Jiang7b9a5872018-01-17 13:25:06 -0800275 if (partition.has_old_partition_info()) {
276 LogPartitionInfoHash(partition.old_partition_info(),
277 "old " + partition.partition_name());
278 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700279 LogPartitionInfoHash(partition.new_partition_info(),
280 "new " + partition.partition_name());
281 }
Andrew de los Reyes89f17be2010-10-22 13:39:09 -0700282}
283
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700284} // namespace
Andrew de los Reyes89f17be2010-10-22 13:39:09 -0700285
Sen Jiangb8060e42015-09-24 17:30:50 -0700286bool DeltaPerformer::IsHeaderParsed() const {
287 return metadata_size_ != 0;
288}
Jay Srinivasanf4318702012-09-24 11:56:24 -0700289
Sen Jiang9c89e842018-02-02 13:51:21 -0800290MetadataParseResult DeltaPerformer::ParsePayloadMetadata(
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700291 const brillo::Blob& payload, ErrorCode* error) {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700292 *error = ErrorCode::kSuccess;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700293
Sen Jiangb8060e42015-09-24 17:30:50 -0700294 if (!IsHeaderParsed()) {
Sen Jiangf1236632018-05-11 16:03:23 -0700295 MetadataParseResult result =
296 payload_metadata_.ParsePayloadHeader(payload, error);
Sen Jiang9c89e842018-02-02 13:51:21 -0800297 if (result != MetadataParseResult::kSuccess)
298 return result;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700299
Sen Jiang9c89e842018-02-02 13:51:21 -0800300 metadata_size_ = payload_metadata_.GetMetadataSize();
301 metadata_signature_size_ = payload_metadata_.GetMetadataSignatureSize();
302 major_payload_version_ = payload_metadata_.GetMajorVersion();
Gilad Arnoldfe133932014-01-14 12:25:50 -0800303
304 // If the metadata size is present in install plan, check for it immediately
305 // even before waiting for that many number of bytes to be downloaded in the
306 // payload. This will prevent any attack which relies on us downloading data
307 // beyond the expected metadata size.
Gilad Arnoldfe133932014-01-14 12:25:50 -0800308 if (install_plan_->hash_checks_mandatory) {
Sen Jiang0affc2c2017-02-10 15:55:05 -0800309 if (payload_->metadata_size != metadata_size_) {
Gilad Arnoldfe133932014-01-14 12:25:50 -0800310 LOG(ERROR) << "Mandatory metadata size in Omaha response ("
Sen Jiang0affc2c2017-02-10 15:55:05 -0800311 << payload_->metadata_size
Gilad Arnoldfe133932014-01-14 12:25:50 -0800312 << ") is missing/incorrect, actual = " << metadata_size_;
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700313 *error = ErrorCode::kDownloadInvalidMetadataSize;
Sen Jiang9c89e842018-02-02 13:51:21 -0800314 return MetadataParseResult::kError;
Gilad Arnoldfe133932014-01-14 12:25:50 -0800315 }
316 }
Andrew3a7dc262019-12-19 11:38:08 -0800317
318 // Check that the |metadata signature size_| and |metadata_size_| are not
319 // very big numbers. This is necessary since |update_engine| needs to write
320 // these values into the buffer before being able to use them, and if an
321 // attacker sets these values to a very big number, the buffer will overflow
322 // and |update_engine| will crash. A simple way of solving this is to check
323 // that the size of both values is smaller than the payload itself.
324 if (metadata_size_ + metadata_signature_size_ > payload_->size) {
325 LOG(ERROR) << "The size of the metadata_size(" << metadata_size_ << ")"
326 << " or metadata signature(" << metadata_signature_size_ << ")"
327 << " is greater than the size of the payload"
328 << "(" << payload_->size << ")";
329 *error = ErrorCode::kDownloadInvalidMetadataSize;
330 return MetadataParseResult::kError;
331 }
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700332 }
333
334 // Now that we have validated the metadata size, we should wait for the full
Sen Jiang76bfa742015-10-12 17:13:26 -0700335 // metadata and its signature (if exist) to be read in before we can parse it.
336 if (payload.size() < metadata_size_ + metadata_signature_size_)
Sen Jiang9c89e842018-02-02 13:51:21 -0800337 return MetadataParseResult::kInsufficientData;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700338
339 // Log whether we validated the size or simply trusting what's in the payload
Jay Srinivasanf4318702012-09-24 11:56:24 -0700340 // here. This is logged here (after we received the full metadata data) so
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700341 // that we just log once (instead of logging n times) if it takes n
342 // DeltaPerformer::Write calls to download the full manifest.
Sen Jiang0affc2c2017-02-10 15:55:05 -0800343 if (payload_->metadata_size == metadata_size_) {
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700344 LOG(INFO) << "Manifest size in payload matches expected value from Omaha";
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800345 } else {
346 // For mandatory-cases, we'd have already returned a kMetadataParseError
347 // above. We'll be here only for non-mandatory cases. Just send a UMA stat.
348 LOG(WARNING) << "Ignoring missing/incorrect metadata size ("
Sen Jiang0affc2c2017-02-10 15:55:05 -0800349 << payload_->metadata_size
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800350 << ") in Omaha response as validation is not mandatory. "
Gilad Arnoldfe133932014-01-14 12:25:50 -0800351 << "Trusting metadata size in payload = " << metadata_size_;
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800352 }
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700353
Amin Hassaniec7bc112020-10-29 16:47:58 -0700354 // NOLINTNEXTLINE(whitespace/braces)
Tianjie Xu7a78d632019-10-08 16:32:39 -0700355 auto [payload_verifier, perform_verification] = CreatePayloadVerifier();
356 if (!payload_verifier) {
357 LOG(ERROR) << "Failed to create payload verifier.";
Sen Jiang08c6da12019-01-07 18:28:56 -0800358 *error = ErrorCode::kDownloadMetadataSignatureVerificationError;
Tianjie Xu6c70b932019-10-22 16:46:00 -0700359 if (perform_verification) {
360 return MetadataParseResult::kError;
361 }
362 } else {
363 // We have the full metadata in |payload|. Verify its integrity
364 // and authenticity based on the information we have in Omaha response.
365 *error = payload_metadata_.ValidateMetadataSignature(
366 payload, payload_->metadata_signature, *payload_verifier);
Sen Jiang08c6da12019-01-07 18:28:56 -0800367 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700368 if (*error != ErrorCode::kSuccess) {
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800369 if (install_plan_->hash_checks_mandatory) {
David Zeuthenbc27aac2013-11-26 11:17:48 -0800370 // The autoupdate_CatchBadSignatures test checks for this string
371 // in log-files. Keep in sync.
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800372 LOG(ERROR) << "Mandatory metadata signature validation failed";
Sen Jiang9c89e842018-02-02 13:51:21 -0800373 return MetadataParseResult::kError;
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800374 }
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700375
Jay Srinivasan738fdf32012-12-07 17:40:54 -0800376 // For non-mandatory cases, just send a UMA stat.
377 LOG(WARNING) << "Ignoring metadata signature validation failures";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700378 *error = ErrorCode::kSuccess;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700379 }
380
Gilad Arnolddaa27402014-01-23 11:56:17 -0800381 // The payload metadata is deemed valid, it's safe to parse the protobuf.
Sen Jiang9c89e842018-02-02 13:51:21 -0800382 if (!payload_metadata_.GetManifest(payload, &manifest_)) {
Darin Petkov9574f7e2011-01-13 10:48:12 -0800383 LOG(ERROR) << "Unable to parse manifest in update file.";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700384 *error = ErrorCode::kDownloadManifestParseError;
Sen Jiang9c89e842018-02-02 13:51:21 -0800385 return MetadataParseResult::kError;
Darin Petkov9574f7e2011-01-13 10:48:12 -0800386 }
Gilad Arnolddaa27402014-01-23 11:56:17 -0800387
388 manifest_parsed_ = true;
Sen Jiang9c89e842018-02-02 13:51:21 -0800389 return MetadataParseResult::kSuccess;
Darin Petkov9574f7e2011-01-13 10:48:12 -0800390}
391
Tianjie8e0090d2021-08-30 22:35:21 -0700392#define OP_DURATION_HISTOGRAM(_op_name, _start_time) \
393 LOCAL_HISTOGRAM_CUSTOM_TIMES( \
394 "UpdateEngine.DownloadAction.InstallOperation::" + string(_op_name) + \
395 ".Duration", \
396 (base::TimeTicks::Now() - _start_time), \
397 base::TimeDelta::FromMilliseconds(10), \
398 base::TimeDelta::FromMinutes(5), \
Amin Hassani008c4582019-01-13 16:22:47 -0800399 20);
Lann Martin39f57142017-07-14 09:18:42 -0600400
Don Garrette410e0f2011-11-10 15:39:01 -0800401// Wrapper around write. Returns true if all requested bytes
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -0800402// were written, or false on any error, regardless of progress
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700403// and stores an action exit code in |error|.
Amin Hassani008c4582019-01-13 16:22:47 -0800404bool DeltaPerformer::Write(const void* bytes, size_t count, ErrorCode* error) {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700405 *error = ErrorCode::kSuccess;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700406 const char* c_bytes = reinterpret_cast<const char*>(bytes);
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800407
408 // Update the total byte downloaded count and the progress logs.
409 total_bytes_received_ += count;
410 UpdateOverallProgress(false, "Completed ");
411
Gilad Arnoldfe133932014-01-14 12:25:50 -0800412 while (!manifest_valid_) {
Sen Jiangb8060e42015-09-24 17:30:50 -0700413 // Read data up to the needed limit; this is either maximium payload header
414 // size, or the full metadata size (once it becomes known).
415 const bool do_read_header = !IsHeaderParsed();
Amin Hassani008c4582019-01-13 16:22:47 -0800416 CopyDataToBuffer(
417 &c_bytes,
418 &count,
419 (do_read_header ? kMaxPayloadHeaderSize
420 : metadata_size_ + metadata_signature_size_));
Gilad Arnoldfe133932014-01-14 12:25:50 -0800421
Gilad Arnolddaa27402014-01-23 11:56:17 -0800422 MetadataParseResult result = ParsePayloadMetadata(buffer_, error);
Sen Jiang9c89e842018-02-02 13:51:21 -0800423 if (result == MetadataParseResult::kError)
Don Garrette410e0f2011-11-10 15:39:01 -0800424 return false;
Sen Jiang9c89e842018-02-02 13:51:21 -0800425 if (result == MetadataParseResult::kInsufficientData) {
Gilad Arnoldfe133932014-01-14 12:25:50 -0800426 // If we just processed the header, make an attempt on the manifest.
Sen Jiangb8060e42015-09-24 17:30:50 -0700427 if (do_read_header && IsHeaderParsed())
Gilad Arnoldfe133932014-01-14 12:25:50 -0800428 continue;
429
Don Garrette410e0f2011-11-10 15:39:01 -0800430 return true;
Gilad Arnoldfe133932014-01-14 12:25:50 -0800431 }
Gilad Arnold21504f02013-05-24 08:51:22 -0700432
433 // Checks the integrity of the payload manifest.
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700434 if ((*error = ValidateManifest()) != ErrorCode::kSuccess)
Gilad Arnold21504f02013-05-24 08:51:22 -0700435 return false;
Gilad Arnolddaa27402014-01-23 11:56:17 -0800436 manifest_valid_ = true;
Kelvin Zhangcc011d32020-07-10 18:20:08 -0400437 if (!install_plan_->is_resume) {
Kelvin Zhangcf4600e2020-10-27 15:50:33 -0400438 auto begin = reinterpret_cast<const char*>(buffer_.data());
439 prefs_->SetString(kPrefsManifestBytes, {begin, buffer_.size()});
Kelvin Zhangcc011d32020-07-10 18:20:08 -0400440 }
Gilad Arnold21504f02013-05-24 08:51:22 -0700441
Gilad Arnoldfe133932014-01-14 12:25:50 -0800442 // Clear the download buffer.
Sen Jiangf6813802015-11-03 21:27:29 -0800443 DiscardBuffer(false, metadata_size_);
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700444
Sen Jiang57f91802017-11-14 17:42:13 -0800445 block_size_ = manifest_.block_size();
446
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700447 // This populates |partitions_| and the |install_plan.partitions| with the
448 // list of partitions from the manifest.
449 if (!ParseManifestPartitions(error))
450 return false;
451
Sen Jiang5ae865b2017-04-18 14:24:40 -0700452 // |install_plan.partitions| was filled in, nothing need to be done here if
453 // the payload was already applied, returns false to terminate http fetcher,
454 // but keep |error| as ErrorCode::kSuccess.
455 if (payload_->already_applied)
456 return false;
457
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700458 num_total_operations_ = 0;
459 for (const auto& partition : partitions_) {
460 num_total_operations_ += partition.operations_size();
461 acc_num_operations_.push_back(num_total_operations_);
462 }
463
Amin Hassani008c4582019-01-13 16:22:47 -0800464 LOG_IF(WARNING,
465 !prefs_->SetInt64(kPrefsManifestMetadataSize, metadata_size_))
Darin Petkov73058b42010-10-06 16:32:19 -0700466 << "Unable to save the manifest metadata size.";
Amin Hassani008c4582019-01-13 16:22:47 -0800467 LOG_IF(WARNING,
468 !prefs_->SetInt64(kPrefsManifestSignatureSize,
469 metadata_signature_size_))
Alex Deymof25eb492016-02-26 00:20:08 -0800470 << "Unable to save the manifest signature size.";
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700471
Darin Petkov9b230572010-10-08 10:20:09 -0700472 if (!PrimeUpdateState()) {
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700473 *error = ErrorCode::kDownloadStateInitializationError;
Darin Petkov9b230572010-10-08 10:20:09 -0700474 LOG(ERROR) << "Unable to prime the update state.";
Don Garrette410e0f2011-11-10 15:39:01 -0800475 return false;
Darin Petkov9b230572010-10-08 10:20:09 -0700476 }
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800477
Yifan Hong537802d2018-08-15 13:15:42 -0700478 if (next_operation_num_ < acc_num_operations_[current_partition_]) {
479 if (!OpenCurrentPartition()) {
480 *error = ErrorCode::kInstallDeviceOpenError;
481 return false;
482 }
Allie Woodfdf00512015-03-02 13:34:55 -0800483 }
484
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800485 if (next_operation_num_ > 0)
486 UpdateOverallProgress(true, "Resuming after ");
487 LOG(INFO) << "Starting to apply update payload operations";
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700488 }
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800489
490 while (next_operation_num_ < num_total_operations_) {
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700491 // Check if we should cancel the current attempt for any reason.
492 // In this case, *error will have already been populated with the reason
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700493 // why we're canceling.
Alex Deymo542c19b2015-12-03 07:43:31 -0300494 if (download_delegate_ && download_delegate_->ShouldCancel(error))
Jay Srinivasan1c0fe792013-03-28 16:45:25 -0700495 return false;
496
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700497 // We know there are more operations to perform because we didn't reach the
498 // |num_total_operations_| limit yet.
Yifan Hong537802d2018-08-15 13:15:42 -0700499 if (next_operation_num_ >= acc_num_operations_[current_partition_]) {
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400500 if (partition_writer_) {
501 TEST_AND_RETURN_FALSE(partition_writer_->FinishedInstallOps());
502 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700503 CloseCurrentPartition();
Yifan Hong537802d2018-08-15 13:15:42 -0700504 // Skip until there are operations for current_partition_.
505 while (next_operation_num_ >= acc_num_operations_[current_partition_]) {
506 current_partition_++;
507 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700508 if (!OpenCurrentPartition()) {
509 *error = ErrorCode::kInstallDeviceOpenError;
510 return false;
511 }
512 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700513
Alex Deymoa12ee112015-08-12 22:19:32 -0700514 const InstallOperation& op =
Kelvin Zhang52cb1d72020-10-27 13:44:25 -0400515 partitions_[current_partition_].operations(GetPartitionOperationNum());
Gilad Arnoldfe133932014-01-14 12:25:50 -0800516
517 CopyDataToBuffer(&c_bytes, &count, op.data_length());
518
519 // Check whether we received all of the next operation's data payload.
520 if (!CanPerformInstallOperation(op))
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700521 return true;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700522
Tianjie1205ea62020-07-09 17:04:28 -0700523 // Validate the operation unconditionally. This helps prevent the
524 // exploitation of vulnerabilities in the patching libraries, e.g. bspatch.
525 // The hash of the patch data for a given operation is embedded in the
526 // payload metadata; and thus has been verified against the public key on
527 // device.
528 // Note: Validate must be called only if CanPerformInstallOperation is
529 // called. Otherwise, we might be failing operations before even if there
530 // isn't sufficient data to compute the proper hash.
531 *error = ValidateOperationHash(op);
532 if (*error != ErrorCode::kSuccess) {
533 if (install_plan_->hash_checks_mandatory) {
534 LOG(ERROR) << "Mandatory operation hash check failed";
535 return false;
Jay Srinivasan00f76b62012-09-17 18:48:36 -0700536 }
Tianjie1205ea62020-07-09 17:04:28 -0700537
538 // For non-mandatory cases, just send a UMA stat.
539 LOG(WARNING) << "Ignoring operation validation errors";
540 *error = ErrorCode::kSuccess;
Jay Srinivasan51dcf262012-09-13 17:24:32 -0700541 }
542
Darin Petkov45580e42010-10-08 14:02:40 -0700543 // Makes sure we unblock exit when this operation completes.
Darin Petkov9c0baf82010-10-07 13:44:48 -0700544 ScopedTerminatorExitUnblocker exit_unblocker =
545 ScopedTerminatorExitUnblocker(); // Avoids a compiler unused var bug.
Gilad Arnoldfe133932014-01-14 12:25:50 -0800546
Lann Martin39f57142017-07-14 09:18:42 -0600547 base::TimeTicks op_start_time = base::TimeTicks::Now();
548
Gilad Arnoldfe133932014-01-14 12:25:50 -0800549 bool op_result;
Tianjie8e0090d2021-08-30 22:35:21 -0700550 const string op_name = InstallOperationTypeName(op.type());
Alex Deymo2d621a32015-10-01 11:09:01 -0700551 switch (op.type()) {
552 case InstallOperation::REPLACE:
553 case InstallOperation::REPLACE_BZ:
554 case InstallOperation::REPLACE_XZ:
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700555 op_result = PerformReplaceOperation(op);
Lann Martin39f57142017-07-14 09:18:42 -0600556 OP_DURATION_HISTOGRAM("REPLACE", op_start_time);
Alex Deymo2d621a32015-10-01 11:09:01 -0700557 break;
Alex Deymo79715ad2015-10-02 14:27:53 -0700558 case InstallOperation::ZERO:
559 case InstallOperation::DISCARD:
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700560 op_result = PerformZeroOrDiscardOperation(op);
Lann Martin39f57142017-07-14 09:18:42 -0600561 OP_DURATION_HISTOGRAM("ZERO_OR_DISCARD", op_start_time);
Alex Deymo79715ad2015-10-02 14:27:53 -0700562 break;
Alex Deymo2d621a32015-10-01 11:09:01 -0700563 case InstallOperation::SOURCE_COPY:
Sen Jiangbe2c47b2016-06-15 14:09:27 -0700564 op_result = PerformSourceCopyOperation(op, error);
Lann Martin39f57142017-07-14 09:18:42 -0600565 OP_DURATION_HISTOGRAM("SOURCE_COPY", op_start_time);
Alex Deymo2d621a32015-10-01 11:09:01 -0700566 break;
567 case InstallOperation::SOURCE_BSDIFF:
Amin Hassaniefa62d92017-11-09 13:46:56 -0800568 case InstallOperation::BROTLI_BSDIFF:
Amin Hassani49fdb092017-08-04 13:10:59 -0700569 case InstallOperation::PUFFDIFF:
Tianjie8e0090d2021-08-30 22:35:21 -0700570 case InstallOperation::ZUCCHINI:
571 op_result = PerformDiffOperation(op, error);
572 OP_DURATION_HISTOGRAM(op_name, op_start_time);
Sen Jiangbc3e6b02016-01-19 18:39:26 +0800573 break;
Alex Deymo2d621a32015-10-01 11:09:01 -0700574 default:
Alex Deymoeecb0a52017-05-19 15:15:08 -0700575 op_result = false;
Alex Deymo2d621a32015-10-01 11:09:01 -0700576 }
Tianjie8e0090d2021-08-30 22:35:21 -0700577 if (!HandleOpResult(op_result, op_name.c_str(), error))
Gilad Arnoldfe133932014-01-14 12:25:50 -0800578 return false;
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800579
Andrew de los Reyesf4c7ef12010-04-30 10:37:00 -0700580 next_operation_num_++;
Gilad Arnold8a86fa52013-01-15 12:35:05 -0800581 UpdateOverallProgress(false, "Completed ");
Sen Jiang3a25dc22019-01-10 14:14:41 -0800582 CheckpointUpdateProgress(false);
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700583 }
Sen Jiangf6813802015-11-03 21:27:29 -0800584
Kelvin Zhang4f28a6c2021-01-14 14:04:57 -0500585 if (partition_writer_) {
586 TEST_AND_RETURN_FALSE(partition_writer_->FinishedInstallOps());
587 }
588 CloseCurrentPartition();
589
Saint Chou0a92a622020-07-29 14:25:35 +0000590 // In major version 2, we don't add unused operation to the payload.
Alex Deymof25eb492016-02-26 00:20:08 -0800591 // If we already extracted the signature we should skip this step.
Amin Hassani822d4852020-03-10 01:50:42 +0000592 if (manifest_.has_signatures_offset() && manifest_.has_signatures_size() &&
Alex Deymof25eb492016-02-26 00:20:08 -0800593 signatures_message_data_.empty()) {
Sen Jiangf6813802015-11-03 21:27:29 -0800594 if (manifest_.signatures_offset() != buffer_offset_) {
595 LOG(ERROR) << "Payload signatures offset points to blob offset "
596 << manifest_.signatures_offset()
Amin Hassani008c4582019-01-13 16:22:47 -0800597 << " but signatures are expected at offset " << buffer_offset_;
Sen Jiangf6813802015-11-03 21:27:29 -0800598 *error = ErrorCode::kDownloadPayloadVerificationError;
599 return false;
600 }
601 CopyDataToBuffer(&c_bytes, &count, manifest_.signatures_size());
602 // Needs more data to cover entire signature.
603 if (buffer_.size() < manifest_.signatures_size())
604 return true;
605 if (!ExtractSignatureMessage()) {
606 LOG(ERROR) << "Extract payload signature failed.";
607 *error = ErrorCode::kDownloadPayloadVerificationError;
608 return false;
609 }
610 DiscardBuffer(true, 0);
Alex Deymof25eb492016-02-26 00:20:08 -0800611 // Since we extracted the SignatureMessage we need to advance the
612 // checkpoint, otherwise we would reload the signature and try to extract
613 // it again.
Sen Jiang3a25dc22019-01-10 14:14:41 -0800614 // This is the last checkpoint for an update, force this checkpoint to be
615 // saved.
616 CheckpointUpdateProgress(true);
Sen Jiangf6813802015-11-03 21:27:29 -0800617 }
618
Don Garrette410e0f2011-11-10 15:39:01 -0800619 return true;
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700620}
621
David Zeuthen8f191b22013-08-06 12:27:50 -0700622bool DeltaPerformer::IsManifestValid() {
623 return manifest_valid_;
624}
625
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700626bool DeltaPerformer::ParseManifestPartitions(ErrorCode* error) {
Kelvin Zhang20982a52021-08-13 12:31:16 -0700627 partitions_.assign(manifest_.partitions().begin(),
628 manifest_.partitions().end());
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700629
Tianjied3865d12020-06-03 15:25:17 -0700630 // For VAB and partial updates, the partition preparation will copy the
631 // dynamic partitions metadata to the target metadata slot, and rename the
632 // slot suffix of the partitions in the metadata.
633 if (install_plan_->target_slot != BootControlInterface::kInvalidSlot) {
634 uint64_t required_size = 0;
635 if (!PreparePartitionsForUpdate(&required_size)) {
636 if (required_size > 0) {
637 *error = ErrorCode::kNotEnoughSpace;
638 } else {
639 *error = ErrorCode::kInstallDeviceOpenError;
640 }
641 return false;
642 }
643 }
644
Tianjie55abd3c2020-06-19 00:22:59 -0700645 // Partitions in manifest are no longer needed after preparing partitions.
Amin Hassani822d4852020-03-10 01:50:42 +0000646 manifest_.clear_partitions();
Tianjied3865d12020-06-03 15:25:17 -0700647 // TODO(xunchang) TBD: allow partial update only on devices with dynamic
648 // partition.
649 if (manifest_.partial_update()) {
650 std::set<std::string> touched_partitions;
651 for (const auto& partition_update : partitions_) {
652 touched_partitions.insert(partition_update.partition_name());
653 }
654
Tianjie99d570d2020-06-04 14:57:19 -0700655 auto generator = partition_update_generator::Create(boot_control_,
656 manifest_.block_size());
Tianjie24f96092020-06-30 12:26:25 -0700657 std::vector<PartitionUpdate> untouched_static_partitions;
Tianjied3865d12020-06-03 15:25:17 -0700658 TEST_AND_RETURN_FALSE(
659 generator->GenerateOperationsForPartitionsNotInPayload(
660 install_plan_->source_slot,
661 install_plan_->target_slot,
662 touched_partitions,
Tianjie24f96092020-06-30 12:26:25 -0700663 &untouched_static_partitions));
664 partitions_.insert(partitions_.end(),
665 untouched_static_partitions.begin(),
666 untouched_static_partitions.end());
667
668 // Save the untouched dynamic partitions in install plan.
669 std::vector<std::string> dynamic_partitions;
670 if (!boot_control_->GetDynamicPartitionControl()
671 ->ListDynamicPartitionsForSlot(install_plan_->source_slot,
Tianjie3a55fc22021-02-13 16:02:22 -0800672 boot_control_->GetCurrentSlot(),
Tianjie24f96092020-06-30 12:26:25 -0700673 &dynamic_partitions)) {
674 LOG(ERROR) << "Failed to load dynamic partitions from slot "
675 << install_plan_->source_slot;
676 return false;
677 }
678 install_plan_->untouched_dynamic_partitions.clear();
679 for (const auto& name : dynamic_partitions) {
680 if (touched_partitions.find(name) == touched_partitions.end()) {
681 install_plan_->untouched_dynamic_partitions.push_back(name);
682 }
683 }
Tianjied3865d12020-06-03 15:25:17 -0700684 }
685
Kelvin Zhang20982a52021-08-13 12:31:16 -0700686 if (!install_plan_->ParsePartitions(
687 partitions_, boot_control_, block_size_, error)) {
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700688 return false;
689 }
Kelvin Zhang20982a52021-08-13 12:31:16 -0700690
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700691 LogPartitionInfo(partitions_);
692 return true;
693}
694
Yifan Hongb9d63572020-01-09 17:50:46 -0800695bool DeltaPerformer::PreparePartitionsForUpdate(uint64_t* required_size) {
696 // Call static PreparePartitionsForUpdate with hash from
697 // kPrefsUpdateCheckResponseHash to ensure hash of payload that space is
698 // preallocated for is the same as the hash of payload being applied.
699 string update_check_response_hash;
700 ignore_result(prefs_->GetString(kPrefsUpdateCheckResponseHash,
701 &update_check_response_hash));
702 return PreparePartitionsForUpdate(prefs_,
703 boot_control_,
704 install_plan_->target_slot,
705 manifest_,
706 update_check_response_hash,
707 required_size);
708}
709
710bool DeltaPerformer::PreparePartitionsForUpdate(
711 PrefsInterface* prefs,
712 BootControlInterface* boot_control,
713 BootControlInterface::Slot target_slot,
714 const DeltaArchiveManifest& manifest,
715 const std::string& update_check_response_hash,
716 uint64_t* required_size) {
717 string last_hash;
718 ignore_result(
719 prefs->GetString(kPrefsDynamicPartitionMetadataUpdated, &last_hash));
720
721 bool is_resume = !update_check_response_hash.empty() &&
722 last_hash == update_check_response_hash;
723
724 if (is_resume) {
725 LOG(INFO) << "Using previously prepared partitions for update. hash = "
726 << last_hash;
727 } else {
728 LOG(INFO) << "Preparing partitions for new update. last hash = "
729 << last_hash << ", new hash = " << update_check_response_hash;
Kelvin Zhang51e08b92021-02-19 14:54:21 -0500730 ResetUpdateProgress(prefs, false);
Yifan Hongb9d63572020-01-09 17:50:46 -0800731 }
732
733 if (!boot_control->GetDynamicPartitionControl()->PreparePartitionsForUpdate(
734 boot_control->GetCurrentSlot(),
735 target_slot,
736 manifest,
737 !is_resume /* should update */,
738 required_size)) {
Yifan Hong9acd9cb2018-10-19 14:52:45 -0700739 LOG(ERROR) << "Unable to initialize partition metadata for slot "
Yifan Hongb9d63572020-01-09 17:50:46 -0800740 << BootControlInterface::SlotName(target_slot);
Yifan Hong9acd9cb2018-10-19 14:52:45 -0700741 return false;
742 }
Yifan Hongb9d63572020-01-09 17:50:46 -0800743
744 TEST_AND_RETURN_FALSE(prefs->SetString(kPrefsDynamicPartitionMetadataUpdated,
745 update_check_response_hash));
Yifan Hong13d41cb2019-09-16 13:18:22 -0700746 LOG(INFO) << "PreparePartitionsForUpdate done.";
Yifan Hong9acd9cb2018-10-19 14:52:45 -0700747
748 return true;
749}
750
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700751bool DeltaPerformer::CanPerformInstallOperation(
Alex Deymoa12ee112015-08-12 22:19:32 -0700752 const chromeos_update_engine::InstallOperation& operation) {
Alex Deymo0497d052016-03-23 09:16:59 -0700753 // If we don't have a data blob we can apply it right away.
754 if (!operation.has_data_offset() && !operation.has_data_length())
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700755 return true;
756
757 // See if we have the entire data blob in the buffer
758 if (operation.data_offset() < buffer_offset_) {
759 LOG(ERROR) << "we threw away data it seems?";
760 return false;
761 }
Darin Petkovd7061ab2010-10-06 14:37:09 -0700762
Gilad Arnoldfe133932014-01-14 12:25:50 -0800763 return (operation.data_offset() + operation.data_length() <=
764 buffer_offset_ + buffer_.size());
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700765}
766
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700767bool DeltaPerformer::PerformReplaceOperation(
768 const InstallOperation& operation) {
Alex Deymoa12ee112015-08-12 22:19:32 -0700769 CHECK(operation.type() == InstallOperation::REPLACE ||
Alex Deymo2d621a32015-10-01 11:09:01 -0700770 operation.type() == InstallOperation::REPLACE_BZ ||
771 operation.type() == InstallOperation::REPLACE_XZ);
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700772
773 // Since we delete data off the beginning of the buffer as we use it,
774 // the data we need should be exactly at the beginning of the buffer.
Darin Petkov9b230572010-10-08 10:20:09 -0700775 TEST_AND_RETURN_FALSE(buffer_.size() >= operation.data_length());
Darin Petkovd7061ab2010-10-06 14:37:09 -0700776
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400777 TEST_AND_RETURN_FALSE(partition_writer_->PerformReplaceOperation(
778 operation, buffer_.data(), buffer_.size()));
779 // Update buffer
780 DiscardBuffer(true, buffer_.size());
781 return true;
782}
783
Alex Deymo79715ad2015-10-02 14:27:53 -0700784bool DeltaPerformer::PerformZeroOrDiscardOperation(
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700785 const InstallOperation& operation) {
Alex Deymo79715ad2015-10-02 14:27:53 -0700786 CHECK(operation.type() == InstallOperation::DISCARD ||
787 operation.type() == InstallOperation::ZERO);
788
789 // These operations have no blob.
790 TEST_AND_RETURN_FALSE(!operation.has_data_offset());
791 TEST_AND_RETURN_FALSE(!operation.has_data_length());
Kelvin Zhang50bac652020-09-28 15:51:41 -0400792
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400793 return partition_writer_->PerformZeroOrDiscardOperation(operation);
794}
Alex Deymo79715ad2015-10-02 14:27:53 -0700795
Allie Wood9f6f0a52015-03-30 11:25:47 -0700796bool DeltaPerformer::PerformSourceCopyOperation(
Sen Jiangbe2c47b2016-06-15 14:09:27 -0700797 const InstallOperation& operation, ErrorCode* error) {
Allie Wood9f6f0a52015-03-30 11:25:47 -0700798 if (operation.has_src_length())
799 TEST_AND_RETURN_FALSE(operation.src_length() % block_size_ == 0);
800 if (operation.has_dst_length())
801 TEST_AND_RETURN_FALSE(operation.dst_length() % block_size_ == 0);
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400802 return partition_writer_->PerformSourceCopyOperation(operation, error);
803}
Allie Wood9f6f0a52015-03-30 11:25:47 -0700804
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700805bool DeltaPerformer::ExtentsToBsdiffPositionsString(
806 const RepeatedPtrField<Extent>& extents,
807 uint64_t block_size,
808 uint64_t full_length,
809 string* positions_string) {
810 string ret;
811 uint64_t length = 0;
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -0700812 for (const Extent& extent : extents) {
Allie Wood56873452015-03-27 17:48:40 -0700813 int64_t start = extent.start_block() * block_size;
Tamas Berghammer9d66d762016-07-15 14:19:04 +0100814 uint64_t this_length =
815 min(full_length - length,
816 static_cast<uint64_t>(extent.num_blocks()) * block_size);
Alex Vakulenko75039d72014-03-25 12:36:28 -0700817 ret += base::StringPrintf("%" PRIi64 ":%" PRIu64 ",", start, this_length);
Andrew de los Reyes09e56d62010-04-23 13:45:53 -0700818 length += this_length;
819 }
820 TEST_AND_RETURN_FALSE(length == full_length);
821 if (!ret.empty())
822 ret.resize(ret.size() - 1); // Strip trailing comma off
823 *positions_string = ret;
824 return true;
825}
826
Tianjie8e0090d2021-08-30 22:35:21 -0700827bool DeltaPerformer::PerformDiffOperation(const InstallOperation& operation,
828 ErrorCode* error) {
Allie Wood9f6f0a52015-03-30 11:25:47 -0700829 // Since we delete data off the beginning of the buffer as we use it,
830 // the data we need should be exactly at the beginning of the buffer.
831 TEST_AND_RETURN_FALSE(buffer_offset_ == operation.data_offset());
832 TEST_AND_RETURN_FALSE(buffer_.size() >= operation.data_length());
833 if (operation.has_src_length())
834 TEST_AND_RETURN_FALSE(operation.src_length() % block_size_ == 0);
835 if (operation.has_dst_length())
836 TEST_AND_RETURN_FALSE(operation.dst_length() % block_size_ == 0);
837
Tianjie8e0090d2021-08-30 22:35:21 -0700838 TEST_AND_RETURN_FALSE(partition_writer_->PerformDiffOperation(
Kelvin Zhang9bd519d2020-09-23 12:55:19 -0400839 operation, error, buffer_.data(), buffer_.size()));
840 DiscardBuffer(true, buffer_.size());
841 return true;
842}
Amin Hassani02855c22017-09-06 22:34:50 -0700843
Sen Jiangf6813802015-11-03 21:27:29 -0800844bool DeltaPerformer::ExtractSignatureMessage() {
Darin Petkovd7061ab2010-10-06 14:37:09 -0700845 TEST_AND_RETURN_FALSE(signatures_message_data_.empty());
846 TEST_AND_RETURN_FALSE(buffer_offset_ == manifest_.signatures_offset());
847 TEST_AND_RETURN_FALSE(buffer_.size() >= manifest_.signatures_size());
Darin Petkov4f0a07b2011-05-25 16:47:20 -0700848 signatures_message_data_.assign(
Amin Hassani008c4582019-01-13 16:22:47 -0800849 buffer_.begin(), buffer_.begin() + manifest_.signatures_size());
Darin Petkov4f0a07b2011-05-25 16:47:20 -0700850
Darin Petkovd7061ab2010-10-06 14:37:09 -0700851 LOG(INFO) << "Extracted signature data of size "
852 << manifest_.signatures_size() << " at "
853 << manifest_.signatures_offset();
854 return true;
855}
856
Sen Jiang08c6da12019-01-07 18:28:56 -0800857bool DeltaPerformer::GetPublicKey(string* out_public_key) {
858 out_public_key->clear();
David Zeuthene7f89172013-10-31 10:21:04 -0700859
Sen Jiang08c6da12019-01-07 18:28:56 -0800860 if (utils::FileExists(public_key_path_.c_str())) {
861 LOG(INFO) << "Verifying using public key: " << public_key_path_;
862 return utils::ReadFile(public_key_path_, out_public_key);
863 }
864
Kelvin Zhang50bac652020-09-28 15:51:41 -0400865 // If this is an official build then we are not allowed to use public key
866 // from Omaha response.
Sen Jiang08c6da12019-01-07 18:28:56 -0800867 if (!hardware_->IsOfficialBuild() && !install_plan_->public_key_rsa.empty()) {
868 LOG(INFO) << "Verifying using public key from Omaha response.";
869 return brillo::data_encoding::Base64Decode(install_plan_->public_key_rsa,
870 out_public_key);
871 }
Tianjie Xu7a78d632019-10-08 16:32:39 -0700872 LOG(INFO) << "No public keys found for verification.";
David Zeuthene7f89172013-10-31 10:21:04 -0700873 return true;
874}
875
Tianjie Xu7a78d632019-10-08 16:32:39 -0700876std::pair<std::unique_ptr<PayloadVerifier>, bool>
877DeltaPerformer::CreatePayloadVerifier() {
878 if (utils::FileExists(update_certificates_path_.c_str())) {
879 LOG(INFO) << "Verifying using certificates: " << update_certificates_path_;
880 return {
881 PayloadVerifier::CreateInstanceFromZipPath(update_certificates_path_),
882 true};
883 }
884
885 string public_key;
886 if (!GetPublicKey(&public_key)) {
887 LOG(ERROR) << "Failed to read public key";
888 return {nullptr, true};
889 }
890
891 // Skips the verification if the public key is empty.
892 if (public_key.empty()) {
893 return {nullptr, false};
894 }
895 return {PayloadVerifier::CreateInstance(public_key), true};
896}
897
Gilad Arnold21504f02013-05-24 08:51:22 -0700898ErrorCode DeltaPerformer::ValidateManifest() {
Saint Chou0a92a622020-07-29 14:25:35 +0000899 // Perform assorted checks to validation check the manifest, make sure it
Don Garrettb8dd1d92013-11-22 17:40:02 -0800900 // matches data from other sources, and that it is a supported version.
Amin Hassani822d4852020-03-10 01:50:42 +0000901 bool has_old_fields = std::any_of(manifest_.partitions().begin(),
902 manifest_.partitions().end(),
903 [](const PartitionUpdate& partition) {
904 return partition.has_old_partition_info();
905 });
Sen Jiangc8f6b7a2015-10-21 11:09:59 -0700906
Alex Deymo64d98782016-02-05 18:03:48 -0800907 // The presence of an old partition hash is the sole indicator for a delta
Tianjief5baff42020-07-17 21:43:22 -0700908 // update. Also, always treat the partial update as delta so that we can
909 // perform the minor version check correctly.
Alex Deymo64d98782016-02-05 18:03:48 -0800910 InstallPayloadType actual_payload_type =
Tianjief5baff42020-07-17 21:43:22 -0700911 (has_old_fields || manifest_.partial_update())
912 ? InstallPayloadType::kDelta
913 : InstallPayloadType::kFull;
Alex Deymo64d98782016-02-05 18:03:48 -0800914
Sen Jiangcdd52062017-05-18 15:33:10 -0700915 if (payload_->type == InstallPayloadType::kUnknown) {
Alex Deymo64d98782016-02-05 18:03:48 -0800916 LOG(INFO) << "Detected a '"
917 << InstallPayloadTypeToString(actual_payload_type)
918 << "' payload.";
Sen Jiangcdd52062017-05-18 15:33:10 -0700919 payload_->type = actual_payload_type;
920 } else if (payload_->type != actual_payload_type) {
Alex Deymo64d98782016-02-05 18:03:48 -0800921 LOG(ERROR) << "InstallPlan expected a '"
Sen Jiangcdd52062017-05-18 15:33:10 -0700922 << InstallPayloadTypeToString(payload_->type)
Alex Deymo64d98782016-02-05 18:03:48 -0800923 << "' payload but the downloaded manifest contains a '"
924 << InstallPayloadTypeToString(actual_payload_type)
925 << "' payload.";
926 return ErrorCode::kPayloadMismatchedType;
927 }
Alex Deymo64d98782016-02-05 18:03:48 -0800928 // Check that the minor version is compatible.
Tianjied3865d12020-06-03 15:25:17 -0700929 // TODO(xunchang) increment minor version & add check for partial update
Alex Deymo64d98782016-02-05 18:03:48 -0800930 if (actual_payload_type == InstallPayloadType::kFull) {
Don Garrettb8dd1d92013-11-22 17:40:02 -0800931 if (manifest_.minor_version() != kFullPayloadMinorVersion) {
932 LOG(ERROR) << "Manifest contains minor version "
933 << manifest_.minor_version()
934 << ", but all full payloads should have version "
935 << kFullPayloadMinorVersion << ".";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700936 return ErrorCode::kUnsupportedMinorPayloadVersion;
Don Garrettb8dd1d92013-11-22 17:40:02 -0800937 }
938 } else {
Sen Jiangf1236632018-05-11 16:03:23 -0700939 if (manifest_.minor_version() < kMinSupportedMinorPayloadVersion ||
940 manifest_.minor_version() > kMaxSupportedMinorPayloadVersion) {
Don Garrettb8dd1d92013-11-22 17:40:02 -0800941 LOG(ERROR) << "Manifest contains minor version "
942 << manifest_.minor_version()
Sen Jiangf1236632018-05-11 16:03:23 -0700943 << " not in the range of supported minor versions ["
944 << kMinSupportedMinorPayloadVersion << ", "
945 << kMaxSupportedMinorPayloadVersion << "].";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700946 return ErrorCode::kUnsupportedMinorPayloadVersion;
Don Garrettb8dd1d92013-11-22 17:40:02 -0800947 }
Gilad Arnold21504f02013-05-24 08:51:22 -0700948 }
949
Yifan Hong87029332020-09-01 17:20:08 -0700950 ErrorCode error_code = CheckTimestampError();
951 if (error_code != ErrorCode::kSuccess) {
952 if (error_code == ErrorCode::kPayloadTimestampError) {
953 if (!hardware_->AllowDowngrade()) {
954 return ErrorCode::kPayloadTimestampError;
955 }
956 LOG(INFO) << "The current OS build allows downgrade, continuing to apply"
957 " the payload with an older timestamp.";
958 } else {
959 LOG(ERROR) << "Timestamp check returned "
960 << utils::ErrorCodeToString(error_code);
961 return error_code;
Tianjie Xu4ad3af62019-10-30 11:59:45 -0700962 }
Sen Jiang8e768e92017-06-28 17:13:19 -0700963 }
964
Amin Hassani55c75412019-10-07 11:20:39 -0700965 // TODO(crbug.com/37661) we should be adding more and more manifest checks,
966 // such as partition boundaries, etc.
Gilad Arnold21504f02013-05-24 08:51:22 -0700967
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700968 return ErrorCode::kSuccess;
Gilad Arnold21504f02013-05-24 08:51:22 -0700969}
970
Yifan Hong87029332020-09-01 17:20:08 -0700971ErrorCode DeltaPerformer::CheckTimestampError() const {
Kelvin Zhangd7191032020-08-11 10:48:16 -0400972 bool is_partial_update =
973 manifest_.has_partial_update() && manifest_.partial_update();
974 const auto& partitions = manifest_.partitions();
Yifan Hong87029332020-09-01 17:20:08 -0700975
976 // Check version field for a given PartitionUpdate object. If an error
977 // is encountered, set |error_code| accordingly. If downgrade is detected,
Kelvin Zhang50bac652020-09-28 15:51:41 -0400978 // |downgrade_detected| is set. Return true if the program should continue
979 // to check the next partition or not, or false if it should exit early due
980 // to errors.
Yifan Hong87029332020-09-01 17:20:08 -0700981 auto&& timestamp_valid = [this](const PartitionUpdate& partition,
982 bool allow_empty_version,
983 bool* downgrade_detected) -> ErrorCode {
Tianjie19e55292020-10-19 21:49:37 -0700984 const auto& partition_name = partition.partition_name();
Yifan Hong87029332020-09-01 17:20:08 -0700985 if (!partition.has_version()) {
Tianjie19e55292020-10-19 21:49:37 -0700986 if (hardware_->GetVersionForLogging(partition_name).empty()) {
987 LOG(INFO) << partition_name << " does't have version, skipping "
988 << "downgrade check.";
989 return ErrorCode::kSuccess;
990 }
991
Yifan Hong87029332020-09-01 17:20:08 -0700992 if (allow_empty_version) {
993 return ErrorCode::kSuccess;
994 }
995 LOG(ERROR)
Tianjie19e55292020-10-19 21:49:37 -0700996 << "PartitionUpdate " << partition_name
997 << " doesn't have a version field. Not allowed in partial updates.";
Yifan Hong87029332020-09-01 17:20:08 -0700998 return ErrorCode::kDownloadManifestParseError;
999 }
1000
Tianjie19e55292020-10-19 21:49:37 -07001001 auto error_code =
1002 hardware_->IsPartitionUpdateValid(partition_name, partition.version());
Yifan Hong87029332020-09-01 17:20:08 -07001003 switch (error_code) {
1004 case ErrorCode::kSuccess:
1005 break;
1006 case ErrorCode::kPayloadTimestampError:
1007 *downgrade_detected = true;
Tianjie19e55292020-10-19 21:49:37 -07001008 LOG(WARNING) << "PartitionUpdate " << partition_name
Yifan Hong87029332020-09-01 17:20:08 -07001009 << " has an older version than partition on device.";
1010 break;
1011 default:
Tianjie19e55292020-10-19 21:49:37 -07001012 LOG(ERROR) << "IsPartitionUpdateValid(" << partition_name
Yifan Hong87029332020-09-01 17:20:08 -07001013 << ") returned" << utils::ErrorCodeToString(error_code);
1014 break;
1015 }
1016 return error_code;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001017 };
Yifan Hong87029332020-09-01 17:20:08 -07001018
1019 bool downgrade_detected = false;
1020
Kelvin Zhangd7191032020-08-11 10:48:16 -04001021 if (is_partial_update) {
1022 // for partial updates, all partition MUST have valid timestamps
1023 // But max_timestamp can be empty
1024 for (const auto& partition : partitions) {
Yifan Hong87029332020-09-01 17:20:08 -07001025 auto error_code = timestamp_valid(
1026 partition, false /* allow_empty_version */, &downgrade_detected);
1027 if (error_code != ErrorCode::kSuccess &&
1028 error_code != ErrorCode::kPayloadTimestampError) {
1029 return error_code;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001030 }
1031 }
Yifan Hong87029332020-09-01 17:20:08 -07001032 if (downgrade_detected) {
1033 return ErrorCode::kPayloadTimestampError;
1034 }
1035 return ErrorCode::kSuccess;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001036 }
Yifan Hong87029332020-09-01 17:20:08 -07001037
1038 // For non-partial updates, check max_timestamp first.
Kelvin Zhangd7191032020-08-11 10:48:16 -04001039 if (manifest_.max_timestamp() < hardware_->GetBuildTimestamp()) {
1040 LOG(ERROR) << "The current OS build timestamp ("
1041 << hardware_->GetBuildTimestamp()
1042 << ") is newer than the maximum timestamp in the manifest ("
1043 << manifest_.max_timestamp() << ")";
Yifan Hong87029332020-09-01 17:20:08 -07001044 return ErrorCode::kPayloadTimestampError;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001045 }
1046 // Otherwise... partitions can have empty timestamps.
1047 for (const auto& partition : partitions) {
Yifan Hong87029332020-09-01 17:20:08 -07001048 auto error_code = timestamp_valid(
1049 partition, true /* allow_empty_version */, &downgrade_detected);
1050 if (error_code != ErrorCode::kSuccess &&
1051 error_code != ErrorCode::kPayloadTimestampError) {
1052 return error_code;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001053 }
1054 }
Yifan Hong87029332020-09-01 17:20:08 -07001055 if (downgrade_detected) {
1056 return ErrorCode::kPayloadTimestampError;
1057 }
1058 return ErrorCode::kSuccess;
Kelvin Zhangd7191032020-08-11 10:48:16 -04001059}
1060
David Zeuthena99981f2013-04-29 13:42:47 -07001061ErrorCode DeltaPerformer::ValidateOperationHash(
Alex Deymoa12ee112015-08-12 22:19:32 -07001062 const InstallOperation& operation) {
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001063 if (!operation.data_sha256_hash().size()) {
1064 if (!operation.data_length()) {
Kelvin Zhang50bac652020-09-28 15:51:41 -04001065 // Operations that do not have any data blob won't have any operation
1066 // hash either. So, these operations are always considered validated
1067 // since the metadata that contains all the non-data-blob portions of
1068 // the operation has already been validated. This is true for both HTTP
1069 // and HTTPS cases.
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001070 return ErrorCode::kSuccess;
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001071 }
1072
Jay Srinivasan738fdf32012-12-07 17:40:54 -08001073 // No hash is present for an operation that has data blobs. This shouldn't
1074 // happen normally for any client that has this code, because the
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001075 // corresponding update should have been produced with the operation
Jay Srinivasan738fdf32012-12-07 17:40:54 -08001076 // hashes. So if it happens it means either we've turned operation hash
1077 // generation off in DeltaDiffGenerator or it's a regression of some sort.
Saint Chou0a92a622020-07-29 14:25:35 +00001078 // One caveat though: The last operation is a unused signature operation
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001079 // that doesn't have a hash at the time the manifest is created. So we
1080 // should not complaint about that operation. This operation can be
1081 // recognized by the fact that it's offset is mentioned in the manifest.
1082 if (manifest_.signatures_offset() &&
1083 manifest_.signatures_offset() == operation.data_offset()) {
1084 LOG(INFO) << "Skipping hash verification for signature operation "
1085 << next_operation_num_ + 1;
1086 } else {
Jay Srinivasan738fdf32012-12-07 17:40:54 -08001087 if (install_plan_->hash_checks_mandatory) {
1088 LOG(ERROR) << "Missing mandatory operation hash for operation "
1089 << next_operation_num_ + 1;
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001090 return ErrorCode::kDownloadOperationHashMissingError;
Jay Srinivasan738fdf32012-12-07 17:40:54 -08001091 }
1092
Jay Srinivasan738fdf32012-12-07 17:40:54 -08001093 LOG(WARNING) << "Cannot validate operation " << next_operation_num_ + 1
1094 << " as there's no operation hash in manifest";
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001095 }
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001096 return ErrorCode::kSuccess;
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001097 }
1098
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001099 brillo::Blob expected_op_hash;
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001100 expected_op_hash.assign(operation.data_sha256_hash().data(),
1101 (operation.data_sha256_hash().data() +
1102 operation.data_sha256_hash().size()));
1103
Sen Jiang2703ef42017-03-16 13:36:21 -07001104 brillo::Blob calculated_op_hash;
1105 if (!HashCalculator::RawHashOfBytes(
1106 buffer_.data(), operation.data_length(), &calculated_op_hash)) {
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001107 LOG(ERROR) << "Unable to compute actual hash of operation "
1108 << next_operation_num_;
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001109 return ErrorCode::kDownloadOperationHashVerificationError;
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001110 }
1111
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001112 if (calculated_op_hash != expected_op_hash) {
1113 LOG(ERROR) << "Hash verification failed for operation "
1114 << next_operation_num_ << ". Expected hash = ";
1115 utils::HexDumpVector(expected_op_hash);
1116 LOG(ERROR) << "Calculated hash over " << operation.data_length()
1117 << " bytes at offset: " << operation.data_offset() << " = ";
1118 utils::HexDumpVector(calculated_op_hash);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001119 return ErrorCode::kDownloadOperationHashMismatch;
Jay Srinivasan00f76b62012-09-17 18:48:36 -07001120 }
1121
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001122 return ErrorCode::kSuccess;
Jay Srinivasan51dcf262012-09-13 17:24:32 -07001123}
1124
Amin Hassani008c4582019-01-13 16:22:47 -08001125#define TEST_AND_RETURN_VAL(_retval, _condition) \
1126 do { \
1127 if (!(_condition)) { \
1128 LOG(ERROR) << "VerifyPayload failure: " << #_condition; \
1129 return _retval; \
1130 } \
Andrew de los Reyes771e1bd2011-08-30 14:47:23 -07001131 } while (0);
Andrew de los Reyesfb830ba2011-04-04 11:42:43 -07001132
David Zeuthena99981f2013-04-29 13:42:47 -07001133ErrorCode DeltaPerformer::VerifyPayload(
Sen Jiang2703ef42017-03-16 13:36:21 -07001134 const brillo::Blob& update_check_response_hash,
Andrew de los Reyes771e1bd2011-08-30 14:47:23 -07001135 const uint64_t update_check_response_size) {
Jay Srinivasan0d8fb402012-05-07 19:19:38 -07001136 // Verifies the download size.
Sen Jiang3a25dc22019-01-10 14:14:41 -08001137 if (update_check_response_size !=
1138 metadata_size_ + metadata_signature_size_ + buffer_offset_) {
1139 LOG(ERROR) << "update_check_response_size (" << update_check_response_size
1140 << ") doesn't match metadata_size (" << metadata_size_
1141 << ") + metadata_signature_size (" << metadata_signature_size_
1142 << ") + buffer_offset (" << buffer_offset_ << ").";
1143 return ErrorCode::kPayloadSizeMismatchError;
1144 }
Jay Srinivasan0d8fb402012-05-07 19:19:38 -07001145
Amin Hassanie331f5a2020-10-06 15:53:29 -07001146 // Verifies the payload hash.
1147 TEST_AND_RETURN_VAL(ErrorCode::kDownloadPayloadVerificationError,
1148 !payload_hash_calculator_.raw_hash().empty());
1149 TEST_AND_RETURN_VAL(
1150 ErrorCode::kPayloadHashMismatchError,
1151 payload_hash_calculator_.raw_hash() == update_check_response_hash);
1152
Amin Hassaniec7bc112020-10-29 16:47:58 -07001153 // NOLINTNEXTLINE(whitespace/braces)
Amin Hassanif624e112020-09-15 15:30:08 -07001154 auto [payload_verifier, perform_verification] = CreatePayloadVerifier();
1155 if (!perform_verification) {
1156 LOG(WARNING) << "Not verifying signed delta payload -- missing public key.";
1157 return ErrorCode::kSuccess;
1158 }
1159 if (!payload_verifier) {
1160 LOG(ERROR) << "Failed to create the payload verifier.";
1161 return ErrorCode::kDownloadPayloadPubKeyVerificationError;
1162 }
1163
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001164 TEST_AND_RETURN_VAL(ErrorCode::kSignedDeltaPayloadExpectedError,
Andrew de los Reyes771e1bd2011-08-30 14:47:23 -07001165 !signatures_message_data_.empty());
Sen Jiangf6813802015-11-03 21:27:29 -08001166 brillo::Blob hash_data = signed_hash_calculator_.raw_hash();
Alex Deymob552a682015-09-30 09:36:49 -07001167 TEST_AND_RETURN_VAL(ErrorCode::kDownloadPayloadPubKeyVerificationError,
xunchangcda3c032019-03-26 15:41:14 -07001168 hash_data.size() == kSHA256Size);
Alex Deymob552a682015-09-30 09:36:49 -07001169
Tianjie Xu6cf830b2019-09-30 11:31:49 -07001170 if (!payload_verifier->VerifySignature(signatures_message_data_, hash_data)) {
David Zeuthenbc27aac2013-11-26 11:17:48 -08001171 // The autoupdate_CatchBadSignatures test checks for this string
1172 // in log-files. Keep in sync.
Alex Deymob552a682015-09-30 09:36:49 -07001173 LOG(ERROR) << "Public key verification failed, thus update failed.";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001174 return ErrorCode::kDownloadPayloadPubKeyVerificationError;
Andrew de los Reyesfb830ba2011-04-04 11:42:43 -07001175 }
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -08001176
David Zeuthene7f89172013-10-31 10:21:04 -07001177 LOG(INFO) << "Payload hash matches value in payload.";
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001178 return ErrorCode::kSuccess;
Darin Petkovd7061ab2010-10-06 14:37:09 -07001179}
1180
Sen Jiangf6813802015-11-03 21:27:29 -08001181void DeltaPerformer::DiscardBuffer(bool do_advance_offset,
1182 size_t signed_hash_buffer_size) {
Gilad Arnoldfe133932014-01-14 12:25:50 -08001183 // Update the buffer offset.
Gilad Arnolddaa27402014-01-23 11:56:17 -08001184 if (do_advance_offset)
Gilad Arnoldfe133932014-01-14 12:25:50 -08001185 buffer_offset_ += buffer_.size();
1186
1187 // Hash the content.
Sen Jiangf6813802015-11-03 21:27:29 -08001188 payload_hash_calculator_.Update(buffer_.data(), buffer_.size());
1189 signed_hash_calculator_.Update(buffer_.data(), signed_hash_buffer_size);
Gilad Arnoldfe133932014-01-14 12:25:50 -08001190
1191 // Swap content with an empty vector to ensure that all memory is released.
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001192 brillo::Blob().swap(buffer_);
Darin Petkovd7061ab2010-10-06 14:37:09 -07001193}
1194
Darin Petkov0406e402010-10-06 21:33:11 -07001195bool DeltaPerformer::CanResumeUpdate(PrefsInterface* prefs,
Chih-Hung Hsieh5c6bb1d2016-07-27 13:33:15 -07001196 const string& update_check_response_hash) {
Darin Petkov0406e402010-10-06 21:33:11 -07001197 int64_t next_operation = kUpdateStateOperationInvalid;
Alex Deymo3310b222015-03-30 15:59:07 -07001198 if (!(prefs->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) &&
Amin Hassani008c4582019-01-13 16:22:47 -08001199 next_operation != kUpdateStateOperationInvalid && next_operation > 0))
Alex Deymo3310b222015-03-30 15:59:07 -07001200 return false;
Darin Petkov0406e402010-10-06 21:33:11 -07001201
1202 string interrupted_hash;
Alex Deymo3310b222015-03-30 15:59:07 -07001203 if (!(prefs->GetString(kPrefsUpdateCheckResponseHash, &interrupted_hash) &&
1204 !interrupted_hash.empty() &&
1205 interrupted_hash == update_check_response_hash))
1206 return false;
Darin Petkov0406e402010-10-06 21:33:11 -07001207
Darin Petkov61426142010-10-08 11:04:55 -07001208 int64_t resumed_update_failures;
Kelvin Zhang50bac652020-09-28 15:51:41 -04001209 // Note that storing this value is optional, but if it is there it should
1210 // not be more than the limit.
Alex Deymof25eb492016-02-26 00:20:08 -08001211 if (prefs->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures) &&
1212 resumed_update_failures > kMaxResumedUpdateFailures)
Alex Deymo3310b222015-03-30 15:59:07 -07001213 return false;
Darin Petkov61426142010-10-08 11:04:55 -07001214
Saint Chou0a92a622020-07-29 14:25:35 +00001215 // Validation check the rest.
Darin Petkov0406e402010-10-06 21:33:11 -07001216 int64_t next_data_offset = -1;
Alex Deymo3310b222015-03-30 15:59:07 -07001217 if (!(prefs->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset) &&
1218 next_data_offset >= 0))
1219 return false;
Darin Petkov0406e402010-10-06 21:33:11 -07001220
Darin Petkov437adc42010-10-07 13:12:24 -07001221 string sha256_context;
Alex Deymo3310b222015-03-30 15:59:07 -07001222 if (!(prefs->GetString(kPrefsUpdateStateSHA256Context, &sha256_context) &&
1223 !sha256_context.empty()))
1224 return false;
Darin Petkov0406e402010-10-06 21:33:11 -07001225
1226 int64_t manifest_metadata_size = 0;
Alex Deymo3310b222015-03-30 15:59:07 -07001227 if (!(prefs->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size) &&
1228 manifest_metadata_size > 0))
1229 return false;
Darin Petkov0406e402010-10-06 21:33:11 -07001230
Alex Deymof25eb492016-02-26 00:20:08 -08001231 int64_t manifest_signature_size = 0;
1232 if (!(prefs->GetInt64(kPrefsManifestSignatureSize,
1233 &manifest_signature_size) &&
1234 manifest_signature_size >= 0))
1235 return false;
1236
Darin Petkov0406e402010-10-06 21:33:11 -07001237 return true;
1238}
1239
Yifan Hong55c2bfe2020-01-13 17:01:19 -08001240bool DeltaPerformer::ResetUpdateProgress(
1241 PrefsInterface* prefs,
1242 bool quick,
1243 bool skip_dynamic_partititon_metadata_updated) {
Darin Petkov0406e402010-10-06 21:33:11 -07001244 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation,
1245 kUpdateStateOperationInvalid));
Darin Petkov9b230572010-10-08 10:20:09 -07001246 if (!quick) {
Darin Petkov9b230572010-10-08 10:20:09 -07001247 prefs->SetInt64(kPrefsUpdateStateNextDataOffset, -1);
David Zeuthen41996ad2013-09-24 15:43:24 -07001248 prefs->SetInt64(kPrefsUpdateStateNextDataLength, 0);
Darin Petkov9b230572010-10-08 10:20:09 -07001249 prefs->SetString(kPrefsUpdateStateSHA256Context, "");
1250 prefs->SetString(kPrefsUpdateStateSignedSHA256Context, "");
Darin Petkov4f0a07b2011-05-25 16:47:20 -07001251 prefs->SetString(kPrefsUpdateStateSignatureBlob, "");
Darin Petkov9b230572010-10-08 10:20:09 -07001252 prefs->SetInt64(kPrefsManifestMetadataSize, -1);
Alex Deymof25eb492016-02-26 00:20:08 -08001253 prefs->SetInt64(kPrefsManifestSignatureSize, -1);
Darin Petkov61426142010-10-08 11:04:55 -07001254 prefs->SetInt64(kPrefsResumedUpdateFailures, 0);
Sen Jiangfe522822017-10-31 15:14:11 -07001255 prefs->Delete(kPrefsPostInstallSucceeded);
Sen Jiang3eeaf7d2018-10-11 13:55:32 -07001256 prefs->Delete(kPrefsVerityWritten);
Yifan Hong55c2bfe2020-01-13 17:01:19 -08001257
1258 if (!skip_dynamic_partititon_metadata_updated) {
1259 LOG(INFO) << "Resetting recorded hash for prepared partitions.";
1260 prefs->Delete(kPrefsDynamicPartitionMetadataUpdated);
1261 }
Darin Petkov9b230572010-10-08 10:20:09 -07001262 }
Darin Petkov73058b42010-10-06 16:32:19 -07001263 return true;
1264}
1265
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001266bool DeltaPerformer::ShouldCheckpoint() {
Sen Jiang53c2ec52019-01-10 15:27:59 -08001267 base::TimeTicks curr_time = base::TimeTicks::Now();
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001268 if (curr_time > update_checkpoint_time_) {
Colin Howes0e452c92018-11-02 13:18:44 -07001269 update_checkpoint_time_ = curr_time + update_checkpoint_wait_;
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001270 return true;
1271 }
1272 return false;
1273}
1274
1275bool DeltaPerformer::CheckpointUpdateProgress(bool force) {
1276 if (!force && !ShouldCheckpoint()) {
Colin Howes0e452c92018-11-02 13:18:44 -07001277 return false;
1278 }
Darin Petkov9c0baf82010-10-07 13:44:48 -07001279 Terminator::set_exit_blocked(true);
Kelvin Zhang3265b312020-12-16 15:51:30 -05001280 if (last_updated_operation_num_ != next_operation_num_ || force) {
Darin Petkov9c0baf82010-10-07 13:44:48 -07001281 // Resets the progress in case we die in the middle of the state update.
Darin Petkov9b230572010-10-08 10:20:09 -07001282 ResetUpdateProgress(prefs_, true);
Kelvin Zhangbb8e9992020-12-28 10:28:48 -05001283 if (!signatures_message_data_.empty()) {
1284 // Save the signature blob because if the update is interrupted after the
1285 // download phase we don't go through this path anymore. Some alternatives
1286 // to consider:
1287 //
1288 // 1. On resume, re-download the signature blob from the server and
1289 // re-verify it.
1290 //
1291 // 2. Verify the signature as soon as it's received and don't checkpoint
1292 // the blob and the signed sha-256 context.
1293 LOG_IF(WARNING,
1294 !prefs_->SetString(kPrefsUpdateStateSignatureBlob,
1295 signatures_message_data_))
1296 << "Unable to store the signature blob.";
1297 }
Amin Hassani008c4582019-01-13 16:22:47 -08001298 TEST_AND_RETURN_FALSE(prefs_->SetString(
1299 kPrefsUpdateStateSHA256Context, payload_hash_calculator_.GetContext()));
Sen Jiangf6813802015-11-03 21:27:29 -08001300 TEST_AND_RETURN_FALSE(
1301 prefs_->SetString(kPrefsUpdateStateSignedSHA256Context,
1302 signed_hash_calculator_.GetContext()));
Amin Hassani008c4582019-01-13 16:22:47 -08001303 TEST_AND_RETURN_FALSE(
1304 prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, buffer_offset_));
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001305 last_updated_operation_num_ = next_operation_num_;
David Zeuthen41996ad2013-09-24 15:43:24 -07001306
1307 if (next_operation_num_ < num_total_operations_) {
Alex Deymoe5e5fe92015-10-05 09:28:19 -07001308 size_t partition_index = current_partition_;
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001309 while (next_operation_num_ >= acc_num_operations_[partition_index]) {
Alex Deymoe5e5fe92015-10-05 09:28:19 -07001310 partition_index++;
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001311 }
Amin Hassani008c4582019-01-13 16:22:47 -08001312 const size_t partition_operation_num =
1313 next_operation_num_ -
1314 (partition_index ? acc_num_operations_[partition_index - 1] : 0);
Alex Deymoa12ee112015-08-12 22:19:32 -07001315 const InstallOperation& op =
Alex Deymoe5e5fe92015-10-05 09:28:19 -07001316 partitions_[partition_index].operations(partition_operation_num);
Amin Hassani008c4582019-01-13 16:22:47 -08001317 TEST_AND_RETURN_FALSE(
1318 prefs_->SetInt64(kPrefsUpdateStateNextDataLength, op.data_length()));
David Zeuthen41996ad2013-09-24 15:43:24 -07001319 } else {
Amin Hassani008c4582019-01-13 16:22:47 -08001320 TEST_AND_RETURN_FALSE(
1321 prefs_->SetInt64(kPrefsUpdateStateNextDataLength, 0));
David Zeuthen41996ad2013-09-24 15:43:24 -07001322 }
Kelvin Zhange4235b02020-11-23 13:57:51 -05001323 if (partition_writer_) {
1324 partition_writer_->CheckpointUpdateProgress(GetPartitionOperationNum());
1325 } else {
1326 CHECK_EQ(next_operation_num_, num_total_operations_)
1327 << "Partition writer is null, we are expected to finish all "
1328 "operations: "
1329 << next_operation_num_ << "/" << num_total_operations_;
1330 }
Darin Petkov0406e402010-10-06 21:33:11 -07001331 }
Amin Hassani008c4582019-01-13 16:22:47 -08001332 TEST_AND_RETURN_FALSE(
1333 prefs_->SetInt64(kPrefsUpdateStateNextOperation, next_operation_num_));
Darin Petkov73058b42010-10-06 16:32:19 -07001334 return true;
1335}
1336
Darin Petkov9b230572010-10-08 10:20:09 -07001337bool DeltaPerformer::PrimeUpdateState() {
1338 CHECK(manifest_valid_);
Darin Petkov9b230572010-10-08 10:20:09 -07001339
1340 int64_t next_operation = kUpdateStateOperationInvalid;
1341 if (!prefs_->GetInt64(kPrefsUpdateStateNextOperation, &next_operation) ||
Amin Hassani008c4582019-01-13 16:22:47 -08001342 next_operation == kUpdateStateOperationInvalid || next_operation <= 0) {
Darin Petkov9b230572010-10-08 10:20:09 -07001343 // Initiating a new update, no more state needs to be initialized.
1344 return true;
1345 }
1346 next_operation_num_ = next_operation;
1347
1348 // Resuming an update -- load the rest of the update state.
1349 int64_t next_data_offset = -1;
Amin Hassani008c4582019-01-13 16:22:47 -08001350 TEST_AND_RETURN_FALSE(
1351 prefs_->GetInt64(kPrefsUpdateStateNextDataOffset, &next_data_offset) &&
1352 next_data_offset >= 0);
Darin Petkov9b230572010-10-08 10:20:09 -07001353 buffer_offset_ = next_data_offset;
1354
Darin Petkov4f0a07b2011-05-25 16:47:20 -07001355 // The signed hash context and the signature blob may be empty if the
1356 // interrupted update didn't reach the signature.
Sen Jiangf6813802015-11-03 21:27:29 -08001357 string signed_hash_context;
1358 if (prefs_->GetString(kPrefsUpdateStateSignedSHA256Context,
1359 &signed_hash_context)) {
1360 TEST_AND_RETURN_FALSE(
1361 signed_hash_calculator_.SetContext(signed_hash_context));
1362 }
1363
Sen Jiang9b2f1782019-01-24 14:27:50 -08001364 prefs_->GetString(kPrefsUpdateStateSignatureBlob, &signatures_message_data_);
Darin Petkov9b230572010-10-08 10:20:09 -07001365
1366 string hash_context;
Amin Hassani008c4582019-01-13 16:22:47 -08001367 TEST_AND_RETURN_FALSE(
1368 prefs_->GetString(kPrefsUpdateStateSHA256Context, &hash_context) &&
1369 payload_hash_calculator_.SetContext(hash_context));
Darin Petkov9b230572010-10-08 10:20:09 -07001370
1371 int64_t manifest_metadata_size = 0;
Amin Hassani008c4582019-01-13 16:22:47 -08001372 TEST_AND_RETURN_FALSE(
1373 prefs_->GetInt64(kPrefsManifestMetadataSize, &manifest_metadata_size) &&
1374 manifest_metadata_size > 0);
Gilad Arnoldfe133932014-01-14 12:25:50 -08001375 metadata_size_ = manifest_metadata_size;
Darin Petkov9b230572010-10-08 10:20:09 -07001376
Alex Deymof25eb492016-02-26 00:20:08 -08001377 int64_t manifest_signature_size = 0;
1378 TEST_AND_RETURN_FALSE(
1379 prefs_->GetInt64(kPrefsManifestSignatureSize, &manifest_signature_size) &&
1380 manifest_signature_size >= 0);
1381 metadata_signature_size_ = manifest_signature_size;
1382
Gilad Arnold8a86fa52013-01-15 12:35:05 -08001383 // Advance the download progress to reflect what doesn't need to be
1384 // re-downloaded.
1385 total_bytes_received_ += buffer_offset_;
1386
Darin Petkov61426142010-10-08 11:04:55 -07001387 // Speculatively count the resume as a failure.
1388 int64_t resumed_update_failures;
1389 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) {
1390 resumed_update_failures++;
1391 } else {
1392 resumed_update_failures = 1;
1393 }
1394 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures);
Darin Petkov9b230572010-10-08 10:20:09 -07001395 return true;
1396}
1397
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001398bool DeltaPerformer::IsDynamicPartition(const std::string& part_name,
1399 uint32_t slot) {
Tianjie3a55fc22021-02-13 16:02:22 -08001400 return boot_control_->GetDynamicPartitionControl()->IsDynamicPartition(
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001401 part_name, slot);
Kelvin Zhang94f51cc2020-09-25 11:34:49 -04001402}
1403
Kelvin Zhange52b6cd2021-02-09 15:28:40 -05001404std::unique_ptr<PartitionWriterInterface> DeltaPerformer::CreatePartitionWriter(
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001405 const PartitionUpdate& partition_update,
1406 const InstallPlan::Partition& install_part,
1407 DynamicPartitionControlInterface* dynamic_control,
1408 size_t block_size,
1409 bool is_interactive,
1410 bool is_dynamic_partition) {
1411 return partition_writer::CreatePartitionWriter(
1412 partition_update,
1413 install_part,
1414 dynamic_control,
1415 block_size_,
1416 interactive_,
Kelvin Zhangebd115e2021-03-08 16:10:25 -05001417 IsDynamicPartition(install_part.name, install_plan_->target_slot));
Kelvin Zhangcfe694f2020-11-13 13:10:42 -05001418}
1419
Andrew de los Reyes09e56d62010-04-23 13:45:53 -07001420} // namespace chromeos_update_engine