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

Commit 93a0c2a7 authored by Dan Pasanen's avatar Dan Pasanen Committed by Steve Kondik
Browse files

fs_mgr: Skip filesystem check unless fs_type matches

* Prevent accidentally destroying a partition of the wrong type.
* Don't skip iterations of the internal mount_all loop, otherwise
  encryptability may not be properly handled.

Change-Id: I8f3ddc396a5fb85f4ae0a0a11dd61fb4d6462d6d
parent 4e41dec5
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -12,8 +12,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \
    external/openssl/include
    external/openssl/include


LOCAL_MODULE:= libfs_mgr
LOCAL_MODULE:= libfs_mgr
LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libsquashfs_utils
LOCAL_STATIC_LIBRARIES := liblogwrap libmincrypt libext4_utils_static libsquashfs_utils libext2_blkid libext2_uuid
LOCAL_C_INCLUDES += system/extras/ext4_utils system/extras/squashfs_utils
LOCAL_C_INCLUDES += system/extras/ext4_utils system/extras/squashfs_utils external/e2fsprogs/lib
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_CFLAGS := -Werror
LOCAL_CFLAGS := -Werror


@@ -38,7 +38,7 @@ LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)/sbin
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)


LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libsquashfs_utils
LOCAL_STATIC_LIBRARIES := libfs_mgr liblogwrap libcutils liblog libc libmincrypt libext4_utils_static libsquashfs_utils libext2_blkid libext2_uuid
LOCAL_STATIC_LIBRARIES += libsparse_static libz libselinux
LOCAL_STATIC_LIBRARIES += libsparse_static libz libselinux
LOCAL_CXX_STL := libc++_static
LOCAL_CXX_STL := libc++_static


+13 −2
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@
#include <cutils/partition_utils.h>
#include <cutils/partition_utils.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <logwrap/logwrap.h>
#include <logwrap/logwrap.h>
#include <blkid/blkid.h>


#include "mincrypt/rsa.h"
#include "mincrypt/rsa.h"
#include "mincrypt/sha.h"
#include "mincrypt/sha.h"
@@ -304,6 +305,8 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
    int i;
    int i;
    int mount_errno = 0;
    int mount_errno = 0;
    int mounted = 0;
    int mounted = 0;
    int cmp_len;
    char *detected_fs_type;


    if (!end_idx || !attempted_idx || start_idx >= fstab->num_entries) {
    if (!end_idx || !attempted_idx || start_idx >= fstab->num_entries) {
      errno = EINVAL;
      errno = EINVAL;
@@ -329,9 +332,17 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
            }
            }


            if (fstab->recs[i].fs_mgr_flags & MF_CHECK) {
            if (fstab->recs[i].fs_mgr_flags & MF_CHECK) {
                /* Skip file system check unless we are sure we are the right type */
                detected_fs_type = blkid_get_tag_value(NULL, "TYPE", fstab->recs[i].blk_device);
                if (detected_fs_type) {
                    cmp_len = (!strncmp(detected_fs_type, "ext", 3) &&
                            strlen(detected_fs_type) == 4) ? 3 : strlen(detected_fs_type);
                    if (!strncmp(fstab->recs[i].fs_type, detected_fs_type, cmp_len)) {
                        check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type,
                        check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type,
                                 fstab->recs[i].mount_point);
                                 fstab->recs[i].mount_point);
                    }
                    }
                }
            }
            if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) {
            if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) {
                *attempted_idx = i;
                *attempted_idx = i;
                mounted = 1;
                mounted = 1;
+3 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,9 @@ LOCAL_STATIC_LIBRARIES := \
    libc \
    libc \
    libselinux \
    libselinux \
    libmincrypt \
    libmincrypt \
    libext4_utils_static \
    libext2_blkid \
    libext2_uuid \
    libc++_static \
    libc++_static \
    libdl \
    libdl \
    libsparse_static \
    libsparse_static \