From 80cb505f64780dde5b30f027040488643bf99a59 Mon Sep 17 00:00:00 2001 From: Bowgo Tsai Date: Fri, 15 Jul 2022 14:04:05 +0800 Subject: [PATCH] vts_fs_test: checks AVB 1.0 isn't used AVB 1.0 support in fs_mgr has been removed in commit Ibfb46aa6c2f761dbb3a9b5f0b16336e510417620. Adding a VTS test case to ensure the legacy 'verify' fs_mgr flag isn't used anymore. Also converting GetFstabPath() to a public API in the fstab.h, so the test case can read then parse the fstab file. Bug: 204948957 Test: atest vts_fs_test Change-Id: Ib6ed7cb8b6ad719b19cd876acf10f4312ecb51b6 --- fs_mgr/fs_mgr_fstab.cpp | 56 +++++++++++++++--------------- fs_mgr/include_fstab/fstab/fstab.h | 2 ++ fs_mgr/tests/vts_fs_test.cpp | 30 ++++++++++++++++ 3 files changed, 60 insertions(+), 28 deletions(-) diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index f1071b008..16713dd59 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -439,34 +439,6 @@ std::string ReadFstabFromDt() { return fstab_result; } -// Return the path to the fstab file. There may be multiple fstab files; the -// one that is returned will be the first that exists of fstab., -// fstab., and fstab.. The fstab is searched for -// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in -// the first stage ramdisk during early boot. Previously, the first stage -// ramdisk's copy of the fstab had to be located in the root directory, but now -// the system/etc directory is supported too and is the preferred location. -std::string GetFstabPath() { - for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) { - std::string suffix; - - if (!fs_mgr_get_boot_config(prop, &suffix)) continue; - - for (const char* prefix : {// late-boot/post-boot locations - "/odm/etc/fstab.", "/vendor/etc/fstab.", - // early boot locations - "/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.", - "/fstab.", "/first_stage_ramdisk/fstab."}) { - std::string fstab_path = prefix + suffix; - if (access(fstab_path.c_str(), F_OK) == 0) { - return fstab_path; - } - } - } - - return ""; -} - /* Extracts s from the by-name symlinks specified in a fstab: * /dev/block///by-name/ * @@ -526,6 +498,34 @@ std::vector GetEntriesByPred(Fstab* fstab, const Pred& pred) { } // namespace +// Return the path to the fstab file. There may be multiple fstab files; the +// one that is returned will be the first that exists of fstab., +// fstab., and fstab.. The fstab is searched for +// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in +// the first stage ramdisk during early boot. Previously, the first stage +// ramdisk's copy of the fstab had to be located in the root directory, but now +// the system/etc directory is supported too and is the preferred location. +std::string GetFstabPath() { + for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) { + std::string suffix; + + if (!fs_mgr_get_boot_config(prop, &suffix)) continue; + + for (const char* prefix : {// late-boot/post-boot locations + "/odm/etc/fstab.", "/vendor/etc/fstab.", + // early boot locations + "/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.", + "/fstab.", "/first_stage_ramdisk/fstab."}) { + std::string fstab_path = prefix + suffix; + if (access(fstab_path.c_str(), F_OK) == 0) { + return fstab_path; + } + } + } + + return ""; +} + bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out) { const int expected_fields = proc_mounts ? 4 : 5; diff --git a/fs_mgr/include_fstab/fstab/fstab.h b/fs_mgr/include_fstab/fstab/fstab.h index 8f200a819..689d18b1c 100644 --- a/fs_mgr/include_fstab/fstab/fstab.h +++ b/fs_mgr/include_fstab/fstab/fstab.h @@ -95,6 +95,8 @@ using Fstab = std::vector; // Exported for testability. Regular users should use ReadFstabFromFile(). bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out); +// Exported for testability. Regular users should use ReadDefaultFstab(). +std::string GetFstabPath(); bool ReadFstabFromFile(const std::string& path, Fstab* fstab); bool ReadFstabFromDt(Fstab* fstab, bool verbose = true); diff --git a/fs_mgr/tests/vts_fs_test.cpp b/fs_mgr/tests/vts_fs_test.cpp index ae8e45992..b8b34e294 100644 --- a/fs_mgr/tests/vts_fs_test.cpp +++ b/fs_mgr/tests/vts_fs_test.cpp @@ -23,6 +23,9 @@ #include #include +using testing::Contains; +using testing::Not; + static int GetVsrLevel() { return android::base::GetIntProperty("ro.vendor.api_level", -1); } @@ -117,3 +120,30 @@ TEST(fs, NoDtFstab) { android::fs_mgr::Fstab fstab; EXPECT_FALSE(android::fs_mgr::ReadFstabFromDt(&fstab, false)); } + +TEST(fs, NoLegacyVerifiedBoot) { + if (GetVsrLevel() < __ANDROID_API_T__) { + GTEST_SKIP(); + } + + const auto& default_fstab_path = android::fs_mgr::GetFstabPath(); + EXPECT_FALSE(default_fstab_path.empty()); + + std::string fstab_str; + EXPECT_TRUE(android::base::ReadFileToString(default_fstab_path, &fstab_str, + /* follow_symlinks = */ true)); + + for (const auto& line : android::base::Split(fstab_str, "\n")) { + auto fields = android::base::Tokenize(line, " \t"); + // Ignores empty lines and comments. + if (fields.empty() || android::base::StartsWith(fields.front(), '#')) { + continue; + } + // Each line in a fstab should have at least five entries. + // + ASSERT_GE(fields.size(), 5); + EXPECT_THAT(android::base::Split(fields[4], ","), Not(Contains("verify"))) + << "AVB 1.0 isn't supported now, but the 'verify' flag is found:\n" + << " " << line; + } +}