init: fix first stage mount failure when two fstab entries have verity_loc

The previous check is incorrect because it compares the basename of
previous verity_loc with the full path of current verity_loc.

Changes it to compare the full device file path instead of just the basename
of verity_loc. This can catch the case of two different verity_loc
values with the same basename, e.g.,

  - verify=/dev/block/platform/SOC.0/by-name/metadata
  - verify=/dev/block/platform/SOC.1/by-name/metadata

Bug: 37413399
Bug: 37619597
Test: first stage mount /system and /vendor with the following fs_mgr_flags on bullhead
        - wait,verify=/dev/block/platform/soc.0/f9824900.sdhci/by-name/metadataa
Test: first stage mount /system and /vendor with different verity_loc values
      on bullhead, checks it bails out
Change-Id: I017c8bd9f0790d45e08e57df9a2878e4f62c5f9c
This commit is contained in:
Bowgo Tsai 2017-04-25 13:09:47 +08:00
parent 41346e553b
commit 71881fffd6

View file

@ -232,7 +232,7 @@ bool FirstStageMount::MountPartitions() {
bool FirstStageMountVBootV1::GetRequiredDevices(std::set<std::string>* out_devices_partition_names,
bool* out_need_dm_verity) {
std::string meta_partition;
std::string verity_loc_device;
*out_need_dm_verity = false;
for (auto fstab_rec : mount_fstab_recs_) {
@ -245,29 +245,28 @@ bool FirstStageMountVBootV1::GetRequiredDevices(std::set<std::string>* out_devic
if (fs_mgr_is_verified(fstab_rec)) {
*out_need_dm_verity = true;
}
// Checks if verity metadata is on a separate partition and get partition
// name from the end of the ->verity_loc path. Verity state is not partition
// specific, so there must be only one additional partition that carries
// verity state.
// Checks if verity metadata is on a separate partition. Note that it is
// not partition specific, so there must be only one additional partition
// that carries verity state.
if (fstab_rec->verity_loc) {
if (meta_partition.empty()) {
meta_partition = basename(fstab_rec->verity_loc);
} else if (meta_partition != fstab_rec->verity_loc) {
LOG(ERROR) << "More than one meta partition found: " << meta_partition << ", "
<< basename(fstab_rec->verity_loc);
if (verity_loc_device.empty()) {
verity_loc_device = fstab_rec->verity_loc;
} else if (verity_loc_device != fstab_rec->verity_loc) {
LOG(ERROR) << "More than one verity_loc found: " << verity_loc_device << ", "
<< fstab_rec->verity_loc;
return false;
}
}
}
// Includes those fstab partitions and meta_partition (if any).
// Includes the partition names of fstab records and verity_loc_device (if any).
// Notes that fstab_rec->blk_device has A/B suffix updated by fs_mgr when A/B is used.
for (auto fstab_rec : mount_fstab_recs_) {
out_devices_partition_names->emplace(basename(fstab_rec->blk_device));
}
if (!meta_partition.empty()) {
out_devices_partition_names->emplace(std::move(meta_partition));
if (!verity_loc_device.empty()) {
out_devices_partition_names->emplace(basename(verity_loc_device.c_str()));
}
return true;