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

Commit 5ec1865b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set block size in dm-bow" into rvc-dev

parents 8f4bb45a 39e4a710
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -1120,8 +1120,28 @@ class CheckpointManager {
                }

                android::dm::DmTable table;
                if (!table.AddTarget(std::make_unique<android::dm::DmTargetBow>(
                            0, size, entry->blk_device))) {
                auto bowTarget =
                        std::make_unique<android::dm::DmTargetBow>(0, size, entry->blk_device);

                // dm-bow uses the first block as a log record, and relocates the real first block
                // elsewhere. For metadata encrypted devices, dm-bow sits below dm-default-key, and
                // for post Android Q devices dm-default-key uses a block size of 4096 always.
                // So if dm-bow's block size, which by default is the block size of the underlying
                // hardware, is less than dm-default-key's, blocks will get broken up and I/O will
                // fail as it won't be data_unit_size aligned.
                // However, since it is possible there is an already shipping non
                // metadata-encrypted device with smaller blocks, we must not change this for
                // devices shipped with Q or earlier unless they explicitly selected dm-default-key
                // v2
                constexpr unsigned int pre_gki_level = __ANDROID_API_Q__;
                unsigned int options_format_version = android::base::GetUintProperty<unsigned int>(
                        "ro.crypto.dm_default_key.options_format.version",
                        (android::fscrypt::GetFirstApiLevel() <= pre_gki_level ? 1 : 2));
                if (options_format_version > 1) {
                    bowTarget->SetBlockSize(4096);
                }

                if (!table.AddTarget(std::move(bowTarget))) {
                    LERROR << "Failed to add bow target";
                    return false;
                }
+5 −0
Original line number Diff line number Diff line
@@ -120,6 +120,11 @@ std::string DmTargetAndroidVerity::GetParameterString() const {
    return keyid_ + " " + block_device_;
}

std::string DmTargetBow::GetParameterString() const {
    if (!block_size_) return target_string_;
    return target_string_ + " 1 block_size:" + std::to_string(block_size_);
}

std::string DmTargetSnapshot::name() const {
    if (mode_ == SnapshotStorageMode::Merge) {
        return "snapshot-merge";
+4 −1
Original line number Diff line number Diff line
@@ -175,11 +175,14 @@ class DmTargetBow final : public DmTarget {
    DmTargetBow(uint64_t start, uint64_t length, const std::string& target_string)
        : DmTarget(start, length), target_string_(target_string) {}

    void SetBlockSize(uint32_t block_size) { block_size_ = block_size; }

    std::string name() const override { return "bow"; }
    std::string GetParameterString() const override { return target_string_; }
    std::string GetParameterString() const override;

  private:
    std::string target_string_;
    uint32_t block_size_ = 0;
};

enum class SnapshotStorageMode {