bool ViolatesSPLDowngrade(const build::tools::releasetools::OtaMetadata& metadata,
std::string_view current_spl) { constauto& post_spl = metadata.postcondition().security_patch_level(); if (current_spl.empty()) {
LOG(WARNING) << "Failed to get device's current security patch level. Target SPL is "
<< post_spl << " permitting OTA install"; returnfalse;
} // SPL(security patch level) is expected to be in format yyyy-mm-dd, e.g. 2018-05-29. Given this // specific format, comparing two SPL can be done by just regular string comparison. If the format // must lay out year/month/date in the exact order, and must properly prepend dates with 0(for // example, 05 for May). Otherwise this comparison doesn't work. We don't expect SPL date formats // to change, leave this as is. if (post_spl < current_spl) {
LOG(ERROR) << "Current SPL: " << current_spl << " Target SPL: " << post_spl
<< " this is considered a downgrade"; if (metadata.spl_downgrade() || metadata.downgrade()) {
LOG(WARNING)
<< "SPL downgrade detected, but OTA package explicitly permitts this(OtaMetadata has " "spl_downgrade / downgrade bit set).Permitting update anyway.Installing a SPL " "downgrade OTA can cause /data fail to decrypt and device fails to boot."; returnfalse;
} returntrue;
} else {
LOG(INFO) << "old spl: " << current_spl << " new spl: " << post_spl << " CHECK passes";
} returnfalse;
}
bool ViolatesSPLDowngrade(ZipArchiveHandle zip, std::string_view current_spl) { static constexpr auto&& OTA_OTA_METADATA = "META-INF/com/android/metadata.pb";
ZipEntry64 metadata_entry; if (FindEntry(zip, OTA_OTA_METADATA, &metadata_entry) != 0) {
LOG(WARNING) << "Failed to find " << OTA_OTA_METADATA
<< " treating this as non-spl-downgrade, permit OTA install. If device bricks " "after installing, check kernel log to see if /data failed to decrypt"; returnfalse;
} constauto metadata_entry_length = metadata_entry.uncompressed_length; if (metadata_entry_length > std::numeric_limits<size_t>::max()) {
LOG(ERROR) << "Failed to extract " << OTA_OTA_METADATA
<< " because's uncompressed size exceeds size of address space. "
<< metadata_entry_length; returnfalse;
}
std::vector<uint8_t> ota_metadata(metadata_entry_length);
int32_t err = ExtractToMemory(zip, &metadata_entry, ota_metadata.data(), metadata_entry_length); if (err != 0) {
LOG(ERROR) << "Failed to extract " << OTA_OTA_METADATA << ": " << ErrorCodeString(err); returnfalse;
} using build::tools::releasetools::OtaMetadata;
OtaMetadata metadata; if (!metadata.ParseFromArray(ota_metadata.data(), ota_metadata.size())) {
LOG(ERROR) << "Failed to parse ota_medata"; returnfalse;
} return ViolatesSPLDowngrade(metadata, current_spl);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-07-01)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.