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

Commit b058c18e authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic" am:...

Merge "libfstab_fuzzer: fuzz TransformFstabForDsu() and skip mount logic" am: 882c1681 am: 624df169 am: 90eab02f

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2264892



Change-Id: Ibfb4dc92bd6298a4992b525b6b3aff8cf36da647
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 20e253b4 90eab02f
Loading
Loading
Loading
Loading
+14 −7
Original line number Original line Diff line number Diff line
@@ -754,10 +754,11 @@ bool ReadFstabFromDt(Fstab* fstab, bool verbose) {
}
}


#ifdef NO_SKIP_MOUNT
#ifdef NO_SKIP_MOUNT
bool SkipMountingPartitions(Fstab*, bool) {
static constexpr bool kNoSkipMount = true;
    return true;
}
#else
#else
static constexpr bool kNoSkipMount = false;
#endif

// For GSI to skip mounting /product and /system_ext, until there are well-defined interfaces
// 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
// 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
// device-specific /product and /system_ext. skip_mount.cfg belongs to system_ext partition because
@@ -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
// /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.
// partition and product partition under /system/system_ext and /system/product, respectively.
bool SkipMountingPartitions(Fstab* fstab, bool verbose) {
bool SkipMountingPartitions(Fstab* fstab, bool verbose) {
    if (kNoSkipMount) {
        return true;
    }

    static constexpr char kSkipMountConfig[] = "/system/system_ext/etc/init/config/skip_mount.cfg";
    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;
    auto save_errno = errno;
    if (!ReadFileToString(kSkipMountConfig, &skip_config)) {
    if (!ReadFileToString(kSkipMountConfig, &skip_mount_config)) {
        errno = save_errno;  // missing file is expected
        errno = save_errno;  // missing file is expected
        return true;
        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;
    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, "#")) {
        if (line.empty() || StartsWith(line, "#")) {
            continue;
            continue;
        }
        }
@@ -801,7 +809,6 @@ bool SkipMountingPartitions(Fstab* fstab, bool verbose) {
    fstab->erase(remove_from, fstab->end());
    fstab->erase(remove_from, fstab->end());
    return true;
    return true;
}
}
#endif


// Loads the fstab file and combines with fstab entries passed in from device tree.
// Loads the fstab file and combines with fstab entries passed in from device tree.
bool ReadDefaultFstab(Fstab* fstab) {
bool ReadDefaultFstab(Fstab* fstab) {
+16 −2
Original line number Original line Diff line number Diff line
@@ -14,13 +14,27 @@
// limitations under the License.
// limitations under the License.
//
//


#include <cstdio>
#include <string>
#include <vector>


#include <fstab/fstab.h>
#include <fstab/fstab.h>
#include <fuzzer/FuzzedDataProvider.h>


extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
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::Fstab fstab;
    android::fs_mgr::ParseFstabFromString(make_fstab_str, /* proc_mounts = */ false, &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;
    return 0;
}
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -97,6 +97,8 @@ using Fstab = std::vector<FstabEntry>;
bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out);
bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out);
// Exported for testability. Regular users should use ReadDefaultFstab().
// Exported for testability. Regular users should use ReadDefaultFstab().
std::string GetFstabPath();
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 ReadFstabFromFile(const std::string& path, Fstab* fstab);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);