Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [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 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/aosp/hardware_android.h" |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 18 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 21 | #include <memory> |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <string_view> |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 24 | |
Yifan Hong | 126d13e | 2020-09-21 19:50:06 -0700 | [diff] [blame] | 25 | #include <android/sysprop/GkiProperties.sysprop.h> |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 26 | #include <android-base/properties.h> |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 27 | #include <base/files/file_util.h> |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 28 | #include <base/strings/string_number_conversions.h> |
| 29 | #include <base/strings/string_util.h> |
Tao Bao | 304680c | 2018-03-31 10:36:52 -0700 | [diff] [blame] | 30 | #include <bootloader_message/bootloader_message.h> |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 31 | #include <fstab/fstab.h> |
| 32 | #include <libavb/libavb.h> |
| 33 | #include <libavb_user/avb_ops_user.h> |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 34 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 35 | #include "update_engine/common/error_code_utils.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 36 | #include "update_engine/common/hardware.h" |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 37 | #include "update_engine/common/platform_constants.h" |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 38 | #include "update_engine/common/utils.h" |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 39 | |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 40 | #ifndef __ANDROID_RECOVERY__ |
| 41 | #include <android/sysprop/OtaProperties.sysprop.h> |
| 42 | #endif |
| 43 | |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 44 | using android::base::GetBoolProperty; |
| 45 | using android::base::GetIntProperty; |
| 46 | using android::base::GetProperty; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 47 | using std::string; |
| 48 | |
| 49 | namespace chromeos_update_engine { |
| 50 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 51 | namespace { |
| 52 | |
Alex Deymo | ebf6e12 | 2017-03-10 16:12:01 -0800 | [diff] [blame] | 53 | // Android properties that identify the hardware and potentially non-updatable |
| 54 | // parts of the bootloader (such as the bootloader version and the baseband |
| 55 | // version). |
Alex Deymo | ebf6e12 | 2017-03-10 16:12:01 -0800 | [diff] [blame] | 56 | const char kPropProductManufacturer[] = "ro.product.manufacturer"; |
| 57 | const char kPropBootHardwareSKU[] = "ro.boot.hardware.sku"; |
| 58 | const char kPropBootRevision[] = "ro.boot.revision"; |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 59 | const char kPropBuildDateUTC[] = "ro.build.date.utc"; |
Alex Deymo | ebf6e12 | 2017-03-10 16:12:01 -0800 | [diff] [blame] | 60 | |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 61 | string GetPartitionBuildDate(const string& partition_name) { |
| 62 | return android::base::GetProperty("ro." + partition_name + ".build.date.utc", |
| 63 | ""); |
| 64 | } |
| 65 | |
Yifan Hong | 70ba92e | 2020-09-22 23:56:00 +0000 | [diff] [blame] | 66 | ErrorCode IsTimestampNewerLogged(const std::string& partition_name, |
| 67 | const std::string& old_version, |
| 68 | const std::string& new_version) { |
| 69 | auto error_code = utils::IsTimestampNewer(old_version, new_version); |
| 70 | if (error_code != ErrorCode::kSuccess) { |
| 71 | LOG(WARNING) << "Timestamp check failed with " |
| 72 | << utils::ErrorCodeToString(error_code) << ": " |
| 73 | << partition_name << " Partition timestamp: " << old_version |
| 74 | << " Update timestamp: " << new_version; |
| 75 | } |
| 76 | return error_code; |
| 77 | } |
| 78 | |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 79 | void SetVbmetaDigestProp(const std::string& value) { |
| 80 | #ifndef __ANDROID_RECOVERY__ |
| 81 | if (!android::sysprop::OtaProperties::other_vbmeta_digest(value)) { |
| 82 | LOG(WARNING) << "Failed to set other vbmeta digest to " << value; |
| 83 | } |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | std::string CalculateVbmetaDigestForInactiveSlot() { |
Kelvin Zhang | 5b00dc5 | 2023-05-23 12:25:56 -0700 | [diff] [blame] | 88 | AvbSlotVerifyData* avb_slot_data{}; |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 89 | |
| 90 | auto suffix = fs_mgr_get_other_slot_suffix(); |
| 91 | const char* requested_partitions[] = {nullptr}; |
| 92 | auto avb_ops = avb_ops_user_new(); |
| 93 | auto verify_result = avb_slot_verify(avb_ops, |
| 94 | requested_partitions, |
| 95 | suffix.c_str(), |
| 96 | AVB_SLOT_VERIFY_FLAGS_NONE, |
| 97 | AVB_HASHTREE_ERROR_MODE_EIO, |
| 98 | &avb_slot_data); |
| 99 | if (verify_result != AVB_SLOT_VERIFY_RESULT_OK) { |
| 100 | LOG(WARNING) << "Failed to verify avb slot data: " << verify_result; |
| 101 | return ""; |
| 102 | } |
| 103 | |
| 104 | uint8_t vbmeta_digest[AVB_SHA256_DIGEST_SIZE]; |
| 105 | avb_slot_verify_data_calculate_vbmeta_digest( |
| 106 | avb_slot_data, AVB_DIGEST_TYPE_SHA256, vbmeta_digest); |
| 107 | |
Kelvin Zhang | 5b00dc5 | 2023-05-23 12:25:56 -0700 | [diff] [blame] | 108 | const std::string encoded_digest = |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 109 | base::HexEncode(vbmeta_digest, AVB_SHA256_DIGEST_SIZE); |
Kelvin Zhang | 5b00dc5 | 2023-05-23 12:25:56 -0700 | [diff] [blame] | 110 | LOG(INFO) << "vbmeta digest for target slot: " << encoded_digest; |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 111 | return base::ToLowerASCII(encoded_digest); |
| 112 | } |
| 113 | |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 114 | } // namespace |
| 115 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 116 | namespace hardware { |
| 117 | |
| 118 | // Factory defined in hardware.h. |
| 119 | std::unique_ptr<HardwareInterface> CreateHardware() { |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 120 | return std::make_unique<HardwareAndroid>(); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } // namespace hardware |
| 124 | |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 125 | // In Android there are normally three kinds of builds: eng, userdebug and user. |
| 126 | // These builds target respectively a developer build, a debuggable version of |
| 127 | // the final product and the pristine final product the end user will run. |
| 128 | // Apart from the ro.build.type property name, they differ in the following |
| 129 | // properties that characterize the builds: |
| 130 | // * eng builds: ro.secure=0 and ro.debuggable=1 |
| 131 | // * userdebug builds: ro.secure=1 and ro.debuggable=1 |
| 132 | // * user builds: ro.secure=1 and ro.debuggable=0 |
| 133 | // |
| 134 | // See IsOfficialBuild() and IsNormalMode() for the meaning of these options in |
| 135 | // Android. |
| 136 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 137 | bool HardwareAndroid::IsOfficialBuild() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 138 | // We run an official build iff ro.secure == 1, because we expect the build to |
| 139 | // behave like the end user product and check for updates. Note that while |
| 140 | // developers are able to build "official builds" by just running "make user", |
| 141 | // that will only result in a more restrictive environment. The important part |
| 142 | // is that we don't produce and push "non-official" builds to the end user. |
| 143 | // |
| 144 | // In case of a non-bool value, we take the most restrictive option and |
| 145 | // assume we are in an official-build. |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 146 | return GetBoolProperty("ro.secure", true); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | bool HardwareAndroid::IsNormalBootMode() const { |
Alex Deymo | 1c4e84a | 2015-09-22 16:58:10 -0700 | [diff] [blame] | 150 | // We are running in "dev-mode" iff ro.debuggable == 1. In dev-mode the |
| 151 | // update_engine will allow extra developers options, such as providing a |
| 152 | // different update URL. In case of error, we assume the build is in |
| 153 | // normal-mode. |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 154 | return !GetBoolProperty("ro.debuggable", false); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 157 | bool HardwareAndroid::AreDevFeaturesEnabled() const { |
| 158 | return !IsNormalBootMode(); |
| 159 | } |
| 160 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 161 | bool HardwareAndroid::IsOOBEEnabled() const { |
| 162 | // No OOBE flow blocking updates for Android-based boards. |
| 163 | return false; |
| 164 | } |
| 165 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 166 | bool HardwareAndroid::IsOOBEComplete(base::Time* out_time_of_oobe) const { |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 167 | LOG(WARNING) << "OOBE is not enabled but IsOOBEComplete() called."; |
Alex Deymo | 4d2990d | 2015-09-15 12:11:26 -0700 | [diff] [blame] | 168 | if (out_time_of_oobe) |
| 169 | *out_time_of_oobe = base::Time(); |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | |
| 173 | string HardwareAndroid::GetHardwareClass() const { |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 174 | auto manufacturer = GetProperty(kPropProductManufacturer, ""); |
| 175 | auto sku = GetProperty(kPropBootHardwareSKU, ""); |
| 176 | auto revision = GetProperty(kPropBootRevision, ""); |
Alex Deymo | ebf6e12 | 2017-03-10 16:12:01 -0800 | [diff] [blame] | 177 | |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 178 | return manufacturer + ":" + sku + ":" + revision; |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Matt Ziegelbaum | aa8e1a4 | 2019-05-09 21:41:58 -0400 | [diff] [blame] | 181 | string HardwareAndroid::GetDeviceRequisition() const { |
| 182 | LOG(WARNING) << "STUB: Getting requisition is not supported."; |
| 183 | return ""; |
| 184 | } |
| 185 | |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 186 | int HardwareAndroid::GetMinKernelKeyVersion() const { |
| 187 | LOG(WARNING) << "STUB: No Kernel key version is available."; |
| 188 | return -1; |
| 189 | } |
| 190 | |
Marton Hunyady | 99ced78 | 2018-05-08 12:59:50 +0200 | [diff] [blame] | 191 | int HardwareAndroid::GetMinFirmwareKeyVersion() const { |
| 192 | LOG(WARNING) << "STUB: No Firmware key version is available."; |
| 193 | return -1; |
| 194 | } |
| 195 | |
Zentaro Kavanagh | 8f6f243 | 2018-05-16 13:48:12 -0700 | [diff] [blame] | 196 | int HardwareAndroid::GetMaxFirmwareKeyRollforward() const { |
| 197 | LOG(WARNING) << "STUB: Getting firmware_max_rollforward is not supported."; |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | bool HardwareAndroid::SetMaxFirmwareKeyRollforward( |
| 202 | int firmware_max_rollforward) { |
| 203 | LOG(WARNING) << "STUB: Setting firmware_max_rollforward is not supported."; |
| 204 | return false; |
| 205 | } |
| 206 | |
Zentaro Kavanagh | 5d95615 | 2018-05-15 09:40:33 -0700 | [diff] [blame] | 207 | bool HardwareAndroid::SetMaxKernelKeyRollforward(int kernel_max_rollforward) { |
| 208 | LOG(WARNING) << "STUB: Setting kernel_max_rollforward is not supported."; |
Zentaro Kavanagh | baacb98 | 2018-02-20 17:48:39 -0800 | [diff] [blame] | 209 | return false; |
| 210 | } |
| 211 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 212 | int HardwareAndroid::GetPowerwashCount() const { |
| 213 | LOG(WARNING) << "STUB: Assuming no factory reset was performed."; |
| 214 | return 0; |
| 215 | } |
| 216 | |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 217 | bool HardwareAndroid::SchedulePowerwash(bool save_rollback_data) { |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 218 | LOG(INFO) << "Scheduling a powerwash to BCB."; |
Zentaro Kavanagh | 28def4f | 2019-01-15 17:15:01 -0800 | [diff] [blame] | 219 | LOG_IF(WARNING, save_rollback_data) << "save_rollback_data was true but " |
| 220 | << "isn't supported."; |
Sen Jiang | d944faa | 2018-08-22 18:46:39 -0700 | [diff] [blame] | 221 | string err; |
| 222 | if (!update_bootloader_message({"--wipe_data", "--reason=wipe_data_from_ota"}, |
| 223 | &err)) { |
| 224 | LOG(ERROR) << "Failed to update bootloader message: " << err; |
| 225 | return false; |
| 226 | } |
| 227 | return true; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | bool HardwareAndroid::CancelPowerwash() { |
Sen Jiang | d944faa | 2018-08-22 18:46:39 -0700 | [diff] [blame] | 231 | string err; |
| 232 | if (!clear_bootloader_message(&err)) { |
| 233 | LOG(ERROR) << "Failed to clear bootloader message: " << err; |
| 234 | return false; |
| 235 | } |
| 236 | return true; |
Alex Deymo | fb905d9 | 2016-06-03 19:26:58 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 239 | bool HardwareAndroid::GetNonVolatileDirectory(base::FilePath* path) const { |
Sen Jiang | 9c12346 | 2015-11-19 13:16:23 -0800 | [diff] [blame] | 240 | base::FilePath local_path(constants::kNonVolatileDirectory); |
Kelvin Zhang | d282252 | 2020-07-07 17:20:58 -0400 | [diff] [blame] | 241 | if (!base::DirectoryExists(local_path)) { |
Alex Deymo | dd132f3 | 2015-09-14 19:12:07 -0700 | [diff] [blame] | 242 | LOG(ERROR) << "Non-volatile directory not found: " << local_path.value(); |
| 243 | return false; |
| 244 | } |
| 245 | *path = local_path; |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | bool HardwareAndroid::GetPowerwashSafeDirectory(base::FilePath* path) const { |
| 250 | // On Android, we don't have a directory persisted across powerwash. |
| 251 | return false; |
| 252 | } |
| 253 | |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 254 | int64_t HardwareAndroid::GetBuildTimestamp() const { |
Tom Cherry | fadd03c | 2017-10-10 14:45:09 -0700 | [diff] [blame] | 255 | return GetIntProperty<int64_t>(kPropBuildDateUTC, 0); |
Sen Jiang | 5011df6 | 2017-06-28 17:13:19 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Tianjie Xu | 4ad3af6 | 2019-10-30 11:59:45 -0700 | [diff] [blame] | 258 | // Returns true if the device runs an userdebug build, and explicitly allows OTA |
| 259 | // downgrade. |
| 260 | bool HardwareAndroid::AllowDowngrade() const { |
| 261 | return GetBoolProperty("ro.ota.allow_downgrade", false) && |
| 262 | GetBoolProperty("ro.debuggable", false); |
| 263 | } |
| 264 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 265 | bool HardwareAndroid::GetFirstActiveOmahaPingSent() const { |
| 266 | LOG(WARNING) << "STUB: Assuming first active omaha was never set."; |
| 267 | return false; |
| 268 | } |
| 269 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 270 | bool HardwareAndroid::SetFirstActiveOmahaPingSent() { |
| 271 | LOG(WARNING) << "STUB: Assuming first active omaha is set."; |
| 272 | // We will set it true, so its failure doesn't cause escalation. |
| 273 | return true; |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Tianjie Xu | d6aa91f | 2019-11-14 11:55:10 -0800 | [diff] [blame] | 276 | void HardwareAndroid::SetWarmReset(bool warm_reset) { |
Kelvin Zhang | a22ef55 | 2020-10-12 19:03:52 -0400 | [diff] [blame] | 277 | if constexpr (!constants::kIsRecovery) { |
| 278 | constexpr char warm_reset_prop[] = "ota.warm_reset"; |
| 279 | if (!android::base::SetProperty(warm_reset_prop, warm_reset ? "1" : "0")) { |
| 280 | LOG(WARNING) << "Failed to set prop " << warm_reset_prop; |
| 281 | } |
Tianjie Xu | d6aa91f | 2019-11-14 11:55:10 -0800 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Tianjie | 838793d | 2021-01-14 22:05:13 -0800 | [diff] [blame] | 285 | void HardwareAndroid::SetVbmetaDigestForInactiveSlot(bool reset) { |
| 286 | if constexpr (constants::kIsRecovery) { |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | if (android::base::GetProperty("ro.boot.avb_version", "").empty() && |
| 291 | android::base::GetProperty("ro.boot.vbmeta.avb_version", "").empty()) { |
| 292 | LOG(INFO) << "Device doesn't use avb, skipping setting vbmeta digest"; |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | if (reset) { |
| 297 | SetVbmetaDigestProp(""); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | std::string digest = CalculateVbmetaDigestForInactiveSlot(); |
| 302 | if (digest.empty()) { |
| 303 | LOG(WARNING) << "Failed to calculate the vbmeta digest for the other slot"; |
| 304 | return; |
| 305 | } |
| 306 | SetVbmetaDigestProp(digest); |
| 307 | } |
| 308 | |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 309 | string HardwareAndroid::GetVersionForLogging( |
| 310 | const string& partition_name) const { |
| 311 | if (partition_name == "boot") { |
Yifan Hong | 70ba92e | 2020-09-22 23:56:00 +0000 | [diff] [blame] | 312 | // ro.bootimage.build.date.utc |
| 313 | return GetPartitionBuildDate("bootimage"); |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 314 | } |
| 315 | return GetPartitionBuildDate(partition_name); |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 318 | ErrorCode HardwareAndroid::IsPartitionUpdateValid( |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 319 | const string& partition_name, const string& new_version) const { |
| 320 | if (partition_name == "boot") { |
Yifan Hong | 70ba92e | 2020-09-22 23:56:00 +0000 | [diff] [blame] | 321 | const auto old_version = GetPartitionBuildDate("bootimage"); |
| 322 | auto error_code = |
| 323 | IsTimestampNewerLogged(partition_name, old_version, new_version); |
| 324 | if (error_code == ErrorCode::kPayloadTimestampError) { |
| 325 | bool prevent_downgrade = |
| 326 | android::sysprop::GkiProperties::prevent_downgrade_version().value_or( |
| 327 | false); |
| 328 | if (!prevent_downgrade) { |
| 329 | LOG(WARNING) << "Downgrade of boot image is detected, but permitting " |
| 330 | "update because device does not prevent boot image " |
| 331 | "downgrade"; |
| 332 | // If prevent_downgrade_version sysprop is not explicitly set, permit |
| 333 | // downgrade in boot image version. |
| 334 | // Even though error_code is overridden here, always call |
| 335 | // IsTimestampNewerLogged to produce log messages. |
| 336 | error_code = ErrorCode::kSuccess; |
| 337 | } |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 338 | } |
Yifan Hong | 70ba92e | 2020-09-22 23:56:00 +0000 | [diff] [blame] | 339 | return error_code; |
Yifan Hong | fd6640f | 2020-08-27 19:13:17 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | const auto old_version = GetPartitionBuildDate(partition_name); |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 343 | // TODO(zhangkelvin) for some partitions, missing a current timestamp should |
| 344 | // be an error, e.g. system, vendor, product etc. |
Yifan Hong | 70ba92e | 2020-09-22 23:56:00 +0000 | [diff] [blame] | 345 | auto error_code = |
| 346 | IsTimestampNewerLogged(partition_name, old_version, new_version); |
Yifan Hong | 8702933 | 2020-09-01 17:20:08 -0700 | [diff] [blame] | 347 | return error_code; |
Kelvin Zhang | d719103 | 2020-08-11 10:48:16 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Alex Light | 7361d27 | 2021-03-12 09:05:55 -0800 | [diff] [blame] | 350 | // Mount options for non-system partitions. This option causes selinux treat |
| 351 | // every file in the mounted filesystem as having the 'postinstall_file' |
| 352 | // context, regardless of what the filesystem itself records. See "SELinux |
| 353 | // User's and Administrator's Guide" for more information on this option. |
| 354 | constexpr const char* kDefaultPostinstallMountOptions = |
| 355 | "context=u:object_r:postinstall_file:s0"; |
| 356 | |
| 357 | // Mount options for system partitions. This option causes selinux to use the |
| 358 | // 'postinstall_file' context as a fallback if there are no other selinux |
| 359 | // contexts associated with the file in the mounted partition. See "SELinux |
| 360 | // User's and Administrator's Guide" for more information on this option. |
| 361 | constexpr const char* kSystemPostinstallMountOptions = |
| 362 | "defcontext=u:object_r:postinstall_file:s0"; |
| 363 | |
| 364 | // Name of the system-partition |
| 365 | constexpr std::string_view kSystemPartitionName = "system"; |
| 366 | |
| 367 | const char* HardwareAndroid::GetPartitionMountOptions( |
| 368 | const std::string& partition_name) const { |
| 369 | if (partition_name == kSystemPartitionName) { |
| 370 | return kSystemPostinstallMountOptions; |
| 371 | } else { |
| 372 | return kDefaultPostinstallMountOptions; |
| 373 | } |
| 374 | } |
| 375 | |
Alex Deymo | 40d86b2 | 2015-09-03 22:27:10 -0700 | [diff] [blame] | 376 | } // namespace chromeos_update_engine |