Loading fs_mgr/libfs_avb/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ cc_library_static { static_libs: [ "libavb", "libdm", "libgsi", "libfstab", ], export_static_lib_headers: [ Loading fs_mgr/libfs_avb/fs_avb.cpp +22 −9 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <android-base/strings.h> #include <libavb/libavb.h> #include <libdm/dm.h> #include <libgsi/libgsi.h> #include "avb_ops.h" #include "avb_util.h" Loading Loading @@ -266,6 +267,18 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta( return avb_handle; } static bool IsAvbPermissive() { if (IsDeviceUnlocked()) { // Manually putting a file under metadata partition can enforce AVB verification. if (!access(DSU_METADATA_PREFIX "avb_enforce", F_OK)) { LINFO << "Enforcing AVB verification when the device is unlocked"; return false; } return true; } return false; } AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, const std::vector<std::string>& preload_avb_key_blobs) { // At least one of the following should be provided for public key matching. Loading @@ -275,7 +288,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, } // Binds allow_verification_error and rollback_protection to device unlock state. bool allow_verification_error = IsDeviceUnlocked(); bool allow_verification_error = IsAvbPermissive(); bool rollback_protection = !allow_verification_error; std::string public_key_data; Loading Loading @@ -364,7 +377,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta() { return LoadAndVerifyVbmeta("vbmeta", fs_mgr_get_slot_suffix(), fs_mgr_get_other_slot_suffix(), {} /* expected_public_key, already checked by bootloader */, HashAlgorithm::kSHA256, IsDeviceUnlocked(), /* allow_verification_error */ IsAvbPermissive(), /* allow_verification_error */ true, /* load_chained_vbmeta */ false, /* rollback_protection, already checked by bootloader */ nullptr /* custom_device_path */); Loading @@ -372,7 +385,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta() { // TODO(b/128807537): removes this function. AvbUniquePtr AvbHandle::Open() { bool is_device_unlocked = IsDeviceUnlocked(); bool allow_verification_error = IsAvbPermissive(); AvbUniquePtr avb_handle(new AvbHandle()); if (!avb_handle) { Loading @@ -381,7 +394,8 @@ AvbUniquePtr AvbHandle::Open() { } FsManagerAvbOps avb_ops; AvbSlotVerifyFlags flags = is_device_unlocked ? AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR AvbSlotVerifyFlags flags = allow_verification_error ? AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR : AVB_SLOT_VERIFY_FLAGS_NONE; AvbSlotVerifyResult verify_result = avb_ops.AvbSlotVerify(fs_mgr_get_slot_suffix(), flags, &avb_handle->vbmeta_images_); Loading @@ -405,9 +419,8 @@ AvbUniquePtr AvbHandle::Open() { break; case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION: case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED: if (!is_device_unlocked) { LERROR << "ERROR_VERIFICATION / PUBLIC_KEY_REJECTED isn't allowed " << "if the device is LOCKED"; if (!allow_verification_error) { LERROR << "ERROR_VERIFICATION / PUBLIC_KEY_REJECTED isn't allowed "; return nullptr; } avb_handle->status_ = AvbHandleStatus::kVerificationError; Loading Loading
fs_mgr/libfs_avb/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ cc_library_static { static_libs: [ "libavb", "libdm", "libgsi", "libfstab", ], export_static_lib_headers: [ Loading
fs_mgr/libfs_avb/fs_avb.cpp +22 −9 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <android-base/strings.h> #include <libavb/libavb.h> #include <libdm/dm.h> #include <libgsi/libgsi.h> #include "avb_ops.h" #include "avb_util.h" Loading Loading @@ -266,6 +267,18 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta( return avb_handle; } static bool IsAvbPermissive() { if (IsDeviceUnlocked()) { // Manually putting a file under metadata partition can enforce AVB verification. if (!access(DSU_METADATA_PREFIX "avb_enforce", F_OK)) { LINFO << "Enforcing AVB verification when the device is unlocked"; return false; } return true; } return false; } AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, const std::vector<std::string>& preload_avb_key_blobs) { // At least one of the following should be provided for public key matching. Loading @@ -275,7 +288,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta(const FstabEntry& fstab_entry, } // Binds allow_verification_error and rollback_protection to device unlock state. bool allow_verification_error = IsDeviceUnlocked(); bool allow_verification_error = IsAvbPermissive(); bool rollback_protection = !allow_verification_error; std::string public_key_data; Loading Loading @@ -364,7 +377,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta() { return LoadAndVerifyVbmeta("vbmeta", fs_mgr_get_slot_suffix(), fs_mgr_get_other_slot_suffix(), {} /* expected_public_key, already checked by bootloader */, HashAlgorithm::kSHA256, IsDeviceUnlocked(), /* allow_verification_error */ IsAvbPermissive(), /* allow_verification_error */ true, /* load_chained_vbmeta */ false, /* rollback_protection, already checked by bootloader */ nullptr /* custom_device_path */); Loading @@ -372,7 +385,7 @@ AvbUniquePtr AvbHandle::LoadAndVerifyVbmeta() { // TODO(b/128807537): removes this function. AvbUniquePtr AvbHandle::Open() { bool is_device_unlocked = IsDeviceUnlocked(); bool allow_verification_error = IsAvbPermissive(); AvbUniquePtr avb_handle(new AvbHandle()); if (!avb_handle) { Loading @@ -381,7 +394,8 @@ AvbUniquePtr AvbHandle::Open() { } FsManagerAvbOps avb_ops; AvbSlotVerifyFlags flags = is_device_unlocked ? AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR AvbSlotVerifyFlags flags = allow_verification_error ? AVB_SLOT_VERIFY_FLAGS_ALLOW_VERIFICATION_ERROR : AVB_SLOT_VERIFY_FLAGS_NONE; AvbSlotVerifyResult verify_result = avb_ops.AvbSlotVerify(fs_mgr_get_slot_suffix(), flags, &avb_handle->vbmeta_images_); Loading @@ -405,9 +419,8 @@ AvbUniquePtr AvbHandle::Open() { break; case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION: case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED: if (!is_device_unlocked) { LERROR << "ERROR_VERIFICATION / PUBLIC_KEY_REJECTED isn't allowed " << "if the device is LOCKED"; if (!allow_verification_error) { LERROR << "ERROR_VERIFICATION / PUBLIC_KEY_REJECTED isn't allowed "; return nullptr; } avb_handle->status_ = AvbHandleStatus::kVerificationError; Loading