Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7245ab6a authored by Thierry Strudel's avatar Thierry Strudel Committed by Gerrit Code Review
Browse files

Merge "fs_mgr_avb: allow verification error when the device is unlocked"

parents 1dcd257a 11409548
Loading
Loading
Loading
Loading
+41 −29
Original line number Diff line number Diff line
@@ -483,25 +483,41 @@ FsManagerAvbUniquePtr FsManagerAvbHandle::Open(const std::string& device_file_by
    // Only allow two verify results:
    //   - AVB_SLOT_VERIFY_RESULT_OK.
    //   - AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION (for UNLOCKED state).
    if (verify_result == AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) {
    //     If the device is UNLOCKED, i.e., |allow_verification_error| is true for
    //     AvbSlotVerify(), then the following return values are all non-fatal:
    //       * AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION
    //       * AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED
    //       * AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX
    //     The latter two results were checked by bootloader prior to start fs_mgr so
    //     we just need to handle the first result here. See *dummy* operations in
    //     FsManagerAvbOps and the comments in external/avb/libavb/avb_slot_verify.h
    //     for more details.
    switch (verify_result) {
        case AVB_SLOT_VERIFY_RESULT_OK:
            avb_handle->status_ = kFsManagerAvbHandleSuccess;
            break;
        case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION:
            if (!avb_verifier->IsDeviceUnlocked()) {
            LERROR << "ERROR_VERIFICATION isn't allowed";
                LERROR << "ERROR_VERIFICATION isn't allowed when the device is LOCKED";
                return nullptr;
            }
    } else if (verify_result != AVB_SLOT_VERIFY_RESULT_OK) {
            avb_handle->status_ = kFsManagerAvbHandleErrorVerification;
            break;
        default:
            LERROR << "avb_slot_verify failed, result: " << verify_result;
            return nullptr;
    }

    // Sets the MAJOR.MINOR for init to set it into "ro.boot.avb_version".
    avb_handle->avb_version_ =
        android::base::StringPrintf("%d.%d", AVB_VERSION_MAJOR, AVB_VERSION_MINOR);

    // Verifies vbmeta images against the digest passed from bootloader.
    if (!avb_verifier->VerifyVbmetaImages(*avb_handle->avb_slot_data_)) {
        LERROR << "VerifyVbmetaImages failed";
        return nullptr;
    } else {
    }

    // Sets the MAJOR.MINOR for init to set it into "ro.boot.avb_version".
    avb_handle->avb_version_ =
        android::base::StringPrintf("%d.%d", AVB_VERSION_MAJOR, AVB_VERSION_MINOR);

    // Checks whether FLAGS_HASHTREE_DISABLED is set.
    AvbVBMetaImageHeader vbmeta_header;
    avb_vbmeta_image_header_to_host_byte_order(
@@ -512,27 +528,23 @@ FsManagerAvbUniquePtr FsManagerAvbHandle::Open(const std::string& device_file_by
        ((AvbVBMetaImageFlags)vbmeta_header.flags & AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED);
    if (hashtree_disabled) {
        avb_handle->status_ = kFsManagerAvbHandleHashtreeDisabled;
            return avb_handle;
        }
    }

    if (verify_result == AVB_SLOT_VERIFY_RESULT_OK) {
        avb_handle->status_ = kFsManagerAvbHandleSuccess;
    LINFO << "Returning avb_handle with status: " << avb_handle->status_;
    return avb_handle;
}
    return nullptr;
}

bool FsManagerAvbHandle::SetUpAvb(struct fstab_rec* fstab_entry, bool wait_for_verity_dev) {
    if (!fstab_entry) return false;
    if (!avb_slot_data_ || avb_slot_data_->num_vbmeta_images < 1) {
        return false;
    }

    if (status_ == kFsManagerAvbHandleUninitialized) return false;
    if (status_ == kFsManagerAvbHandleHashtreeDisabled) {
        LINFO << "AVB HASHTREE disabled on:" << fstab_entry->mount_point;
        return true;
    }
    if (status_ != kFsManagerAvbHandleSuccess) return false;

    std::string partition_name(basename(fstab_entry->mount_point));
    if (!avb_validate_utf8((const uint8_t*)partition_name.c_str(), partition_name.length())) {
+3 −2
Original line number Diff line number Diff line
@@ -25,9 +25,10 @@
#include "fs_mgr.h"

enum FsManagerAvbHandleStatus {
    kFsManagerAvbHandleUninitialized = -1,
    kFsManagerAvbHandleSuccess = 0,
    kFsManagerAvbHandleHashtreeDisabled = 1,
    kFsManagerAvbHandleFail = 2,
    kFsManagerAvbHandleErrorVerification = 2,
};

class FsManagerAvbHandle;
@@ -88,7 +89,7 @@ class FsManagerAvbHandle {
    };

  protected:
    FsManagerAvbHandle() : avb_slot_data_(nullptr), status_(kFsManagerAvbHandleFail) {}
    FsManagerAvbHandle() : avb_slot_data_(nullptr), status_(kFsManagerAvbHandleUninitialized) {}

  private:
    AvbSlotVerifyData* avb_slot_data_;