Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | */ |
| 16 | |
| 17 | /* |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 18 | * update_verifier verifies the integrity of the partitions after an A/B OTA update. It gets invoked |
| 19 | * by init, and will only perform the verification if it's the first boot post an A/B OTA update |
| 20 | * (https://source.android.com/devices/tech/ota/ab/#after_reboot). |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 21 | * |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 22 | * update_verifier relies on device-mapper-verity (dm-verity) to capture any corruption on the |
| 23 | * partitions being verified (https://source.android.com/security/verifiedboot). The verification |
| 24 | * will be skipped, if dm-verity is not enabled on the device. |
| 25 | * |
| 26 | * Upon detecting verification failures, the device will be rebooted, although the trigger of the |
| 27 | * reboot depends on the dm-verity mode. |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 28 | * enforcing mode: dm-verity reboots the device |
| 29 | * eio mode: dm-verity fails the read and update_verifier reboots the device |
| 30 | * other mode: not supported and update_verifier reboots the device |
| 31 | * |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 32 | * All these reboots prevent the device from booting into a known corrupt state. If the device |
| 33 | * continuously fails to boot into the new slot, the bootloader should mark the slot as unbootable |
| 34 | * and trigger a fallback to the old slot. |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 35 | * |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 36 | * The current slot will be marked as having booted successfully if the verifier reaches the end |
| 37 | * after the verification. |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 38 | */ |
| 39 | |
Tao Bao | 83b0780 | 2017-04-26 14:30:56 -0700 | [diff] [blame] | 40 | #include "update_verifier/update_verifier.h" |
| 41 | |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 42 | #include <dirent.h> |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 43 | #include <errno.h> |
| 44 | #include <fcntl.h> |
| 45 | #include <stdio.h> |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 46 | #include <string.h> |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 47 | #include <unistd.h> |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 48 | |
Tianjie Xu | 8fa8f0b | 2017-04-27 11:47:35 -0700 | [diff] [blame] | 49 | #include <algorithm> |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 50 | #include <future> |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 51 | #include <string> |
| 52 | #include <vector> |
| 53 | |
| 54 | #include <android-base/file.h> |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 55 | #include <android-base/logging.h> |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 56 | #include <android-base/parseint.h> |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 57 | #include <android-base/properties.h> |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 58 | #include <android-base/strings.h> |
| 59 | #include <android-base/unique_fd.h> |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 60 | #include <android/hardware/boot/1.0/IBootControl.h> |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 61 | #include <cutils/android_reboot.h> |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 62 | |
Tianjie Xu | 4d9e62d | 2018-05-11 10:41:44 -0700 | [diff] [blame] | 63 | #include "care_map.pb.h" |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 64 | #include "otautil/rangeset.h" |
| 65 | |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 66 | using android::sp; |
| 67 | using android::hardware::boot::V1_0::IBootControl; |
| 68 | using android::hardware::boot::V1_0::BoolResult; |
| 69 | using android::hardware::boot::V1_0::CommandResult; |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 70 | |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 71 | // Find directories in format of "/sys/block/dm-X". |
| 72 | static int dm_name_filter(const dirent* de) { |
| 73 | if (android::base::StartsWith(de->d_name, "dm-")) { |
| 74 | return 1; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 79 | static bool read_blocks(const std::string& partition, const std::string& range_str) { |
Tao Bao | ec2e8c6 | 2018-03-22 16:07:00 -0700 | [diff] [blame] | 80 | if (partition != "system" && partition != "vendor" && partition != "product") { |
| 81 | LOG(ERROR) << "Invalid partition name \"" << partition << "\""; |
Tianjie Xu | 5a176c0 | 2017-03-31 16:36:12 -0700 | [diff] [blame] | 82 | return false; |
| 83 | } |
Tao Bao | ec2e8c6 | 2018-03-22 16:07:00 -0700 | [diff] [blame] | 84 | // Iterate the content of "/sys/block/dm-X/dm/name". If it matches one of "system", "vendor" or |
| 85 | // "product", then dm-X is a dm-wrapped device for that target. We will later read all the |
| 86 | // ("cared") blocks from "/dev/block/dm-X" to ensure the target partition's integrity. |
Tao Bao | 83b0780 | 2017-04-26 14:30:56 -0700 | [diff] [blame] | 87 | static constexpr auto DM_PATH_PREFIX = "/sys/block/"; |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 88 | dirent** namelist; |
| 89 | int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort); |
| 90 | if (n == -1) { |
| 91 | PLOG(ERROR) << "Failed to scan dir " << DM_PATH_PREFIX; |
| 92 | return false; |
| 93 | } |
| 94 | if (n == 0) { |
| 95 | LOG(ERROR) << "dm block device not found for " << partition; |
| 96 | return false; |
| 97 | } |
| 98 | |
Tao Bao | 83b0780 | 2017-04-26 14:30:56 -0700 | [diff] [blame] | 99 | static constexpr auto DM_PATH_SUFFIX = "/dm/name"; |
| 100 | static constexpr auto DEV_PATH = "/dev/block/"; |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 101 | std::string dm_block_device; |
| 102 | while (n--) { |
| 103 | std::string path = DM_PATH_PREFIX + std::string(namelist[n]->d_name) + DM_PATH_SUFFIX; |
| 104 | std::string content; |
| 105 | if (!android::base::ReadFileToString(path, &content)) { |
| 106 | PLOG(WARNING) << "Failed to read " << path; |
David Zeuthen | 8ed9738 | 2017-05-08 13:41:28 -0400 | [diff] [blame] | 107 | } else { |
| 108 | std::string dm_block_name = android::base::Trim(content); |
David Zeuthen | 8ed9738 | 2017-05-08 13:41:28 -0400 | [diff] [blame] | 109 | // AVB is using 'vroot' for the root block device but we're expecting 'system'. |
| 110 | if (dm_block_name == "vroot") { |
| 111 | dm_block_name = "system"; |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 112 | } |
David Zeuthen | 8ed9738 | 2017-05-08 13:41:28 -0400 | [diff] [blame] | 113 | if (dm_block_name == partition) { |
| 114 | dm_block_device = DEV_PATH + std::string(namelist[n]->d_name); |
| 115 | while (n--) { |
| 116 | free(namelist[n]); |
| 117 | } |
| 118 | break; |
| 119 | } |
Tianjie Xu | b0ac872 | 2017-01-18 18:41:53 -0800 | [diff] [blame] | 120 | } |
| 121 | free(namelist[n]); |
| 122 | } |
| 123 | free(namelist); |
| 124 | |
| 125 | if (dm_block_device.empty()) { |
| 126 | LOG(ERROR) << "Failed to find dm block device for " << partition; |
| 127 | return false; |
| 128 | } |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 129 | |
| 130 | // For block range string, first integer 'count' equals 2 * total number of valid ranges, |
| 131 | // followed by 'count' number comma separated integers. Every two integers reprensent a |
| 132 | // block range with the first number included in range but second number not included. |
| 133 | // For example '4,64536,65343,74149,74150' represents: [64536,65343) and [74149,74150). |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 134 | RangeSet ranges = RangeSet::Parse(range_str); |
| 135 | if (!ranges) { |
| 136 | LOG(ERROR) << "Error parsing RangeSet string " << range_str; |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 137 | return false; |
| 138 | } |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 139 | |
| 140 | // RangeSet::Split() splits the ranges into multiple groups with same number of blocks (except for |
| 141 | // the last group). |
| 142 | size_t thread_num = std::thread::hardware_concurrency() ?: 4; |
| 143 | std::vector<RangeSet> groups = ranges.Split(thread_num); |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 144 | |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 145 | std::vector<std::future<bool>> threads; |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 146 | for (const auto& group : groups) { |
| 147 | auto thread_func = [&group, &dm_block_device, &partition]() { |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 148 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY))); |
| 149 | if (fd.get() == -1) { |
| 150 | PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition; |
Tianjie Xu | 8fa8f0b | 2017-04-27 11:47:35 -0700 | [diff] [blame] | 151 | return false; |
| 152 | } |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 153 | |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 154 | static constexpr size_t kBlockSize = 4096; |
| 155 | std::vector<uint8_t> buf(1024 * kBlockSize); |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 156 | |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 157 | size_t block_count = 0; |
| 158 | for (const auto& range : group) { |
| 159 | size_t range_start = range.first; |
| 160 | size_t range_end = range.second; |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 161 | if (lseek64(fd.get(), static_cast<off64_t>(range_start) * kBlockSize, SEEK_SET) == -1) { |
| 162 | PLOG(ERROR) << "lseek to " << range_start << " failed"; |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | size_t remain = (range_end - range_start) * kBlockSize; |
| 167 | while (remain > 0) { |
| 168 | size_t to_read = std::min(remain, 1024 * kBlockSize); |
| 169 | if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) { |
| 170 | PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; |
| 171 | return false; |
| 172 | } |
| 173 | remain -= to_read; |
| 174 | } |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 175 | block_count += (range_end - range_start); |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 176 | } |
Tao Bao | 160514b | 2017-11-04 00:08:08 -0700 | [diff] [blame] | 177 | LOG(INFO) << "Finished reading " << block_count << " blocks on " << dm_block_device; |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 178 | return true; |
| 179 | }; |
| 180 | |
| 181 | threads.emplace_back(std::async(std::launch::async, thread_func)); |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 182 | } |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 183 | |
Wei Wang | 5226f47 | 2017-08-02 10:27:31 -0700 | [diff] [blame] | 184 | bool ret = true; |
| 185 | for (auto& t : threads) { |
| 186 | ret = t.get() && ret; |
| 187 | } |
| 188 | LOG(INFO) << "Finished reading blocks on " << dm_block_device << " with " << thread_num |
| 189 | << " threads."; |
| 190 | return ret; |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Tianjie Xu | 4d9e62d | 2018-05-11 10:41:44 -0700 | [diff] [blame] | 193 | static bool process_care_map_plain_text(const std::string& care_map_contents) { |
Tao Bao | ec2e8c6 | 2018-03-22 16:07:00 -0700 | [diff] [blame] | 194 | // care_map file has up to six lines, where every two lines make a pair. Within each pair, the |
| 195 | // first line has the partition name (e.g. "system"), while the second line holds the ranges of |
| 196 | // all the blocks to verify. |
Tianjie Xu | 4d9e62d | 2018-05-11 10:41:44 -0700 | [diff] [blame] | 197 | std::vector<std::string> lines = |
| 198 | android::base::Split(android::base::Trim(care_map_contents), "\n"); |
Tao Bao | ec2e8c6 | 2018-03-22 16:07:00 -0700 | [diff] [blame] | 199 | if (lines.size() != 2 && lines.size() != 4 && lines.size() != 6) { |
Tao Bao | 5a1dee0 | 2017-07-21 15:15:31 -0700 | [diff] [blame] | 200 | LOG(ERROR) << "Invalid lines in care_map: found " << lines.size() |
Tao Bao | ec2e8c6 | 2018-03-22 16:07:00 -0700 | [diff] [blame] | 201 | << " lines, expecting 2 or 4 or 6 lines."; |
Tao Bao | 5a1dee0 | 2017-07-21 15:15:31 -0700 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | |
| 205 | for (size_t i = 0; i < lines.size(); i += 2) { |
| 206 | // We're seeing an N care_map.txt. Skip the verification since it's not compatible with O |
| 207 | // update_verifier (the last few metadata blocks can't be read via device mapper). |
| 208 | if (android::base::StartsWith(lines[i], "/dev/block/")) { |
| 209 | LOG(WARNING) << "Found legacy care_map.txt; skipped."; |
| 210 | return true; |
| 211 | } |
| 212 | if (!read_blocks(lines[i], lines[i+1])) { |
| 213 | return false; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return true; |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Tianjie Xu | 4d9e62d | 2018-05-11 10:41:44 -0700 | [diff] [blame] | 220 | bool verify_image(const std::string& care_map_name) { |
| 221 | android::base::unique_fd care_map_fd(TEMP_FAILURE_RETRY(open(care_map_name.c_str(), O_RDONLY))); |
| 222 | // If the device is flashed before the current boot, it may not have care_map.txt in |
| 223 | // /data/ota_package. To allow the device to continue booting in this situation, we should |
| 224 | // print a warning and skip the block verification. |
| 225 | if (care_map_fd.get() == -1) { |
| 226 | PLOG(WARNING) << "Failed to open " << care_map_name; |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | std::string file_content; |
| 231 | if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) { |
| 232 | PLOG(ERROR) << "Failed to read " << care_map_name; |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | if (file_content.empty()) { |
| 237 | LOG(ERROR) << "Unexpected empty care map"; |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | UpdateVerifier::CareMap care_map; |
| 242 | // Falls back to use the plain text version if we cannot parse the file as protobuf message. |
| 243 | if (!care_map.ParseFromString(file_content)) { |
| 244 | return process_care_map_plain_text(file_content); |
| 245 | } |
| 246 | |
| 247 | for (const auto& partition : care_map.partitions()) { |
| 248 | if (partition.name().empty()) { |
| 249 | LOG(ERROR) << "Unexpected empty partition name."; |
| 250 | return false; |
| 251 | } |
| 252 | if (partition.ranges().empty()) { |
| 253 | LOG(ERROR) << "Unexpected block ranges for partition " << partition.name(); |
| 254 | return false; |
| 255 | } |
| 256 | if (!read_blocks(partition.name(), partition.ranges())) { |
| 257 | return false; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | return true; |
| 262 | } |
| 263 | |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 264 | static int reboot_device() { |
| 265 | if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) { |
| 266 | LOG(ERROR) << "Failed to reboot."; |
| 267 | return -1; |
| 268 | } |
| 269 | while (true) pause(); |
| 270 | } |
| 271 | |
Tao Bao | 83b0780 | 2017-04-26 14:30:56 -0700 | [diff] [blame] | 272 | int update_verifier(int argc, char** argv) { |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 273 | for (int i = 1; i < argc; i++) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 274 | LOG(INFO) << "Started with arg " << i << ": " << argv[i]; |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Chris Phoenix | 0157c78 | 2017-01-20 11:34:00 -0800 | [diff] [blame] | 277 | sp<IBootControl> module = IBootControl::getService(); |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 278 | if (module == nullptr) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 279 | LOG(ERROR) << "Error getting bootctrl module."; |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 280 | return reboot_device(); |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 283 | uint32_t current_slot = module->getCurrentSlot(); |
| 284 | BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot); |
| 285 | LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" |
| 286 | << static_cast<int32_t>(is_successful); |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 287 | |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 288 | if (is_successful == BoolResult::FALSE) { |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 289 | // The current slot has not booted successfully. |
Tao Bao | db57f0d | 2017-03-10 14:21:25 -0800 | [diff] [blame] | 290 | |
David Zeuthen | 1a0929c | 2017-08-07 18:47:27 -0400 | [diff] [blame] | 291 | bool skip_verification = false; |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 292 | std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", ""); |
| 293 | if (verity_mode.empty()) { |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 294 | // Skip the verification if ro.boot.veritymode property is not set. This could be a result |
| 295 | // that device doesn't support dm-verity, or has disabled that. |
| 296 | LOG(WARNING) << "dm-verity not enabled; marking without verification."; |
David Zeuthen | 1a0929c | 2017-08-07 18:47:27 -0400 | [diff] [blame] | 297 | skip_verification = true; |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 298 | } else if (android::base::EqualsIgnoreCase(verity_mode, "eio")) { |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 299 | // We shouldn't see verity in EIO mode if the current slot hasn't booted successfully before. |
| 300 | // Continue the verification until we fail to read some blocks. |
| 301 | LOG(WARNING) << "Found dm-verity in EIO mode."; |
David Zeuthen | 1a0929c | 2017-08-07 18:47:27 -0400 | [diff] [blame] | 302 | } else if (android::base::EqualsIgnoreCase(verity_mode, "disabled")) { |
| 303 | LOG(WARNING) << "dm-verity in disabled mode; marking without verification."; |
| 304 | skip_verification = true; |
Tao Bao | 4f8d217 | 2017-01-13 15:36:32 -0800 | [diff] [blame] | 305 | } else if (verity_mode != "enforcing") { |
Tao Bao | 1cc0351 | 2018-04-18 17:10:49 -0700 | [diff] [blame] | 306 | LOG(ERROR) << "Unexpected dm-verity mode: " << verity_mode << ", expecting enforcing."; |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 307 | return reboot_device(); |
| 308 | } |
| 309 | |
David Zeuthen | 1a0929c | 2017-08-07 18:47:27 -0400 | [diff] [blame] | 310 | if (!skip_verification) { |
| 311 | static constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt"; |
| 312 | if (!verify_image(CARE_MAP_FILE)) { |
| 313 | LOG(ERROR) << "Failed to verify all blocks in care map file."; |
| 314 | return reboot_device(); |
| 315 | } |
Tianjie Xu | d007cf2 | 2016-02-29 16:08:06 -0800 | [diff] [blame] | 316 | } |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 317 | |
Connor O'Brien | ad43d2d | 2016-11-21 12:47:33 -0800 | [diff] [blame] | 318 | CommandResult cr; |
| 319 | module->markBootSuccessful([&cr](CommandResult result) { cr = result; }); |
| 320 | if (!cr.success) { |
| 321 | LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg; |
Tianjie Xu | 3958a95 | 2017-03-01 15:31:25 -0800 | [diff] [blame] | 322 | return reboot_device(); |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 323 | } |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 324 | LOG(INFO) << "Marked slot " << current_slot << " as booted successfully."; |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 327 | LOG(INFO) << "Leaving update_verifier."; |
Tao Bao | 7197ee0 | 2015-12-05 21:21:27 -0800 | [diff] [blame] | 328 | return 0; |
| 329 | } |