Loading fs_mgr/fs_mgr_fstab.cpp +14 −7 Original line number Diff line number Diff line Loading @@ -754,10 +754,11 @@ bool ReadFstabFromDt(Fstab* fstab, bool verbose) { } #ifdef NO_SKIP_MOUNT bool SkipMountingPartitions(Fstab*, bool) { return true; } static constexpr bool kNoSkipMount = true; #else static constexpr bool kNoSkipMount = false; #endif // For GSI to skip mounting /product and /system_ext, until there are well-defined interfaces // between them and /system. Otherwise, the GSI flashed on /system might not be able to work with // device-specific /product and /system_ext. skip_mount.cfg belongs to system_ext partition because Loading @@ -765,17 +766,24 @@ bool SkipMountingPartitions(Fstab*, bool) { // /system/system_ext because GSI is a single system.img that includes the contents of system_ext // partition and product partition under /system/system_ext and /system/product, respectively. bool SkipMountingPartitions(Fstab* fstab, bool verbose) { if (kNoSkipMount) { return true; } static constexpr char kSkipMountConfig[] = "/system/system_ext/etc/init/config/skip_mount.cfg"; std::string skip_config; std::string skip_mount_config; auto save_errno = errno; if (!ReadFileToString(kSkipMountConfig, &skip_config)) { if (!ReadFileToString(kSkipMountConfig, &skip_mount_config)) { errno = save_errno; // missing file is expected return true; } return SkipMountWithConfig(skip_mount_config, fstab, verbose); } bool SkipMountWithConfig(const std::string& skip_mount_config, Fstab* fstab, bool verbose) { std::vector<std::string> skip_mount_patterns; for (const auto& line : Split(skip_config, "\n")) { for (const auto& line : Split(skip_mount_config, "\n")) { if (line.empty() || StartsWith(line, "#")) { continue; } Loading @@ -801,7 +809,6 @@ bool SkipMountingPartitions(Fstab* fstab, bool verbose) { fstab->erase(remove_from, fstab->end()); return true; } #endif // Loads the fstab file and combines with fstab entries passed in from device tree. bool ReadDefaultFstab(Fstab* fstab) { Loading fs_mgr/fuzz/fs_mgr_fstab_fuzzer.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -14,13 +14,27 @@ // limitations under the License. // #include <cstdio> #include <string> #include <vector> #include <fstab/fstab.h> #include <fuzzer/FuzzedDataProvider.h> extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { std::string make_fstab_str(reinterpret_cast<const char*>(data), size); FuzzedDataProvider fdp(data, size); std::string make_fstab_str = fdp.ConsumeRandomLengthString(); std::string dsu_slot = fdp.ConsumeRandomLengthString(30); std::vector<std::string> dsu_partitions = { fdp.ConsumeRandomLengthString(30), fdp.ConsumeRandomLengthString(30), }; std::string skip_mount_config = fdp.ConsumeRemainingBytesAsString(); android::fs_mgr::Fstab fstab; android::fs_mgr::ParseFstabFromString(make_fstab_str, /* proc_mounts = */ false, &fstab); android::fs_mgr::TransformFstabForDsu(&fstab, dsu_slot, dsu_partitions); android::fs_mgr::SkipMountWithConfig(skip_mount_config, &fstab, /* verbose = */ false); return 0; } fs_mgr/include_fstab/fstab/fstab.h +2 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,8 @@ using Fstab = std::vector<FstabEntry>; bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out); // Exported for testability. Regular users should use ReadDefaultFstab(). std::string GetFstabPath(); // Exported for testability. bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose); bool ReadFstabFromFile(const std::string& path, Fstab* fstab); bool ReadFstabFromDt(Fstab* fstab, bool verbose = true); Loading Loading
fs_mgr/fs_mgr_fstab.cpp +14 −7 Original line number Diff line number Diff line Loading @@ -754,10 +754,11 @@ bool ReadFstabFromDt(Fstab* fstab, bool verbose) { } #ifdef NO_SKIP_MOUNT bool SkipMountingPartitions(Fstab*, bool) { return true; } static constexpr bool kNoSkipMount = true; #else static constexpr bool kNoSkipMount = false; #endif // For GSI to skip mounting /product and /system_ext, until there are well-defined interfaces // between them and /system. Otherwise, the GSI flashed on /system might not be able to work with // device-specific /product and /system_ext. skip_mount.cfg belongs to system_ext partition because Loading @@ -765,17 +766,24 @@ bool SkipMountingPartitions(Fstab*, bool) { // /system/system_ext because GSI is a single system.img that includes the contents of system_ext // partition and product partition under /system/system_ext and /system/product, respectively. bool SkipMountingPartitions(Fstab* fstab, bool verbose) { if (kNoSkipMount) { return true; } static constexpr char kSkipMountConfig[] = "/system/system_ext/etc/init/config/skip_mount.cfg"; std::string skip_config; std::string skip_mount_config; auto save_errno = errno; if (!ReadFileToString(kSkipMountConfig, &skip_config)) { if (!ReadFileToString(kSkipMountConfig, &skip_mount_config)) { errno = save_errno; // missing file is expected return true; } return SkipMountWithConfig(skip_mount_config, fstab, verbose); } bool SkipMountWithConfig(const std::string& skip_mount_config, Fstab* fstab, bool verbose) { std::vector<std::string> skip_mount_patterns; for (const auto& line : Split(skip_config, "\n")) { for (const auto& line : Split(skip_mount_config, "\n")) { if (line.empty() || StartsWith(line, "#")) { continue; } Loading @@ -801,7 +809,6 @@ bool SkipMountingPartitions(Fstab* fstab, bool verbose) { fstab->erase(remove_from, fstab->end()); return true; } #endif // Loads the fstab file and combines with fstab entries passed in from device tree. bool ReadDefaultFstab(Fstab* fstab) { Loading
fs_mgr/fuzz/fs_mgr_fstab_fuzzer.cpp +16 −2 Original line number Diff line number Diff line Loading @@ -14,13 +14,27 @@ // limitations under the License. // #include <cstdio> #include <string> #include <vector> #include <fstab/fstab.h> #include <fuzzer/FuzzedDataProvider.h> extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { std::string make_fstab_str(reinterpret_cast<const char*>(data), size); FuzzedDataProvider fdp(data, size); std::string make_fstab_str = fdp.ConsumeRandomLengthString(); std::string dsu_slot = fdp.ConsumeRandomLengthString(30); std::vector<std::string> dsu_partitions = { fdp.ConsumeRandomLengthString(30), fdp.ConsumeRandomLengthString(30), }; std::string skip_mount_config = fdp.ConsumeRemainingBytesAsString(); android::fs_mgr::Fstab fstab; android::fs_mgr::ParseFstabFromString(make_fstab_str, /* proc_mounts = */ false, &fstab); android::fs_mgr::TransformFstabForDsu(&fstab, dsu_slot, dsu_partitions); android::fs_mgr::SkipMountWithConfig(skip_mount_config, &fstab, /* verbose = */ false); return 0; }
fs_mgr/include_fstab/fstab/fstab.h +2 −0 Original line number Diff line number Diff line Loading @@ -97,6 +97,8 @@ using Fstab = std::vector<FstabEntry>; bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out); // Exported for testability. Regular users should use ReadDefaultFstab(). std::string GetFstabPath(); // Exported for testability. bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose); bool ReadFstabFromFile(const std::string& path, Fstab* fstab); bool ReadFstabFromDt(Fstab* fstab, bool verbose = true); Loading