Loading fs_mgr/fs_mgr_fstab.c +1 −0 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,7 @@ static struct flag_list fs_mgr_flags[] = { { "swapprio=", MF_SWAPPRIO }, { "swapprio=", MF_SWAPPRIO }, { "zramsize=", MF_ZRAMSIZE }, { "zramsize=", MF_ZRAMSIZE }, { "max_comp_streams=", MF_MAX_COMP_STREAMS }, { "max_comp_streams=", MF_MAX_COMP_STREAMS }, { "verifyatboot", MF_VERIFYATBOOT }, { "verify", MF_VERIFY }, { "verify", MF_VERIFY }, { "noemulatedsd", MF_NOEMULATEDSD }, { "noemulatedsd", MF_NOEMULATEDSD }, { "notrim", MF_NOTRIM }, { "notrim", MF_NOTRIM }, Loading fs_mgr/fs_mgr_priv.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,7 @@ __BEGIN_DECLS #define MF_FORCEFDEORFBE 0x10000 #define MF_FORCEFDEORFBE 0x10000 #define MF_LATEMOUNT 0x20000 #define MF_LATEMOUNT 0x20000 #define MF_NOFAIL 0x40000 #define MF_NOFAIL 0x40000 #define MF_VERIFYATBOOT 0x80000 #define MF_MAX_COMP_STREAMS 0x100000 #define MF_MAX_COMP_STREAMS 0x100000 #define MF_RESERVEDSIZE 0x200000 #define MF_RESERVEDSIZE 0x200000 Loading fs_mgr/fs_mgr_verity.cpp +57 −3 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/strings.h> #include <android-base/strings.h> #include <crypto_utils/android_pubkey.h> #include <crypto_utils/android_pubkey.h> #include <android-base/unique_fd.h> #include <cutils/properties.h> #include <cutils/properties.h> #include <logwrap/logwrap.h> #include <logwrap/logwrap.h> #include <openssl/obj_mac.h> #include <openssl/obj_mac.h> Loading Loading @@ -73,6 +74,8 @@ #define VERITY_KMSG_RESTART "dm-verity device corrupted" #define VERITY_KMSG_RESTART "dm-verity device corrupted" #define VERITY_KMSG_BUFSIZE 1024 #define VERITY_KMSG_BUFSIZE 1024 #define READ_BUF_SIZE 4096 #define __STRINGIFY(x) #x #define __STRINGIFY(x) #x #define STRINGIFY(x) __STRINGIFY(x) #define STRINGIFY(x) __STRINGIFY(x) Loading Loading @@ -205,6 +208,16 @@ static int create_verity_device(struct dm_ioctl *io, char *name, int fd) return 0; return 0; } } static int destroy_verity_device(struct dm_ioctl *io, char *name, int fd) { verity_ioctl_init(io, name, 0); if (ioctl(fd, DM_DEV_REMOVE, io)) { ERROR("Error removing device mapping (%s)", strerror(errno)); return -1; } return 0; } static int get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name) static int get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name) { { verity_ioctl_init(io, name, 0); verity_ioctl_init(io, name, 0); Loading Loading @@ -606,6 +619,30 @@ out: return rc; return rc; } } static int read_partition(const char *path, uint64_t size) { char buf[READ_BUF_SIZE]; ssize_t size_read; android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))); if (fd == -1) { ERROR("Failed to open %s: %s\n", path, strerror(errno)); return -errno; } while (size) { size_read = TEMP_FAILURE_RETRY(read(fd, buf, READ_BUF_SIZE)); if (size_read == -1) { ERROR("Error in reading partition %s: %s\n", path, strerror(errno)); return -errno; } size -= size_read; } return 0; } static int compare_last_signature(struct fstab_rec *fstab, int *match) static int compare_last_signature(struct fstab_rec *fstab, int *match) { { char tag[METADATA_TAG_MAX_LENGTH + 1]; char tag[METADATA_TAG_MAX_LENGTH + 1]; Loading Loading @@ -904,6 +941,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; struct dm_ioctl *io = (struct dm_ioctl *) buffer; struct dm_ioctl *io = (struct dm_ioctl *) buffer; char *mount_point = basename(fstab->mount_point); char *mount_point = basename(fstab->mount_point); bool verified_at_boot = false; if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, FEC_DEFAULT_ROOTS) < 0) { FEC_DEFAULT_ROOTS) < 0) { Loading Loading @@ -1037,10 +1075,26 @@ loaded: // mark the underlying block device as read-only // mark the underlying block device as read-only fs_mgr_set_blk_ro(fstab->blk_device); fs_mgr_set_blk_ro(fstab->blk_device); // Verify the entire partition in one go // If there is an error, allow it to mount as a normal verity partition. if (fstab->fs_mgr_flags & MF_VERIFYATBOOT) { INFO("Verifying partition %s at boot\n", fstab->blk_device); int err = read_partition(verity_blk_name, verity.data_size); if (!err) { INFO("Verified verity partition %s at boot\n", fstab->blk_device); verified_at_boot = true; } } // assign the new verity block device as the block device // assign the new verity block device as the block device if (!verified_at_boot) { free(fstab->blk_device); free(fstab->blk_device); fstab->blk_device = verity_blk_name; fstab->blk_device = verity_blk_name; verity_blk_name = 0; verity_blk_name = 0; } else if (destroy_verity_device(io, mount_point, fd) < 0) { ERROR("Failed to remove verity device %s\n", mount_point); goto out; } // make sure we've set everything up properly // make sure we've set everything up properly if (test_access(fstab->blk_device) < 0) { if (test_access(fstab->blk_device) < 0) { Loading Loading
fs_mgr/fs_mgr_fstab.c +1 −0 Original line number Original line Diff line number Diff line Loading @@ -75,6 +75,7 @@ static struct flag_list fs_mgr_flags[] = { { "swapprio=", MF_SWAPPRIO }, { "swapprio=", MF_SWAPPRIO }, { "zramsize=", MF_ZRAMSIZE }, { "zramsize=", MF_ZRAMSIZE }, { "max_comp_streams=", MF_MAX_COMP_STREAMS }, { "max_comp_streams=", MF_MAX_COMP_STREAMS }, { "verifyatboot", MF_VERIFYATBOOT }, { "verify", MF_VERIFY }, { "verify", MF_VERIFY }, { "noemulatedsd", MF_NOEMULATEDSD }, { "noemulatedsd", MF_NOEMULATEDSD }, { "notrim", MF_NOTRIM }, { "notrim", MF_NOTRIM }, Loading
fs_mgr/fs_mgr_priv.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,7 @@ __BEGIN_DECLS #define MF_FORCEFDEORFBE 0x10000 #define MF_FORCEFDEORFBE 0x10000 #define MF_LATEMOUNT 0x20000 #define MF_LATEMOUNT 0x20000 #define MF_NOFAIL 0x40000 #define MF_NOFAIL 0x40000 #define MF_VERIFYATBOOT 0x80000 #define MF_MAX_COMP_STREAMS 0x100000 #define MF_MAX_COMP_STREAMS 0x100000 #define MF_RESERVEDSIZE 0x200000 #define MF_RESERVEDSIZE 0x200000 Loading
fs_mgr/fs_mgr_verity.cpp +57 −3 Original line number Original line Diff line number Diff line Loading @@ -32,6 +32,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/strings.h> #include <android-base/strings.h> #include <crypto_utils/android_pubkey.h> #include <crypto_utils/android_pubkey.h> #include <android-base/unique_fd.h> #include <cutils/properties.h> #include <cutils/properties.h> #include <logwrap/logwrap.h> #include <logwrap/logwrap.h> #include <openssl/obj_mac.h> #include <openssl/obj_mac.h> Loading Loading @@ -73,6 +74,8 @@ #define VERITY_KMSG_RESTART "dm-verity device corrupted" #define VERITY_KMSG_RESTART "dm-verity device corrupted" #define VERITY_KMSG_BUFSIZE 1024 #define VERITY_KMSG_BUFSIZE 1024 #define READ_BUF_SIZE 4096 #define __STRINGIFY(x) #x #define __STRINGIFY(x) #x #define STRINGIFY(x) __STRINGIFY(x) #define STRINGIFY(x) __STRINGIFY(x) Loading Loading @@ -205,6 +208,16 @@ static int create_verity_device(struct dm_ioctl *io, char *name, int fd) return 0; return 0; } } static int destroy_verity_device(struct dm_ioctl *io, char *name, int fd) { verity_ioctl_init(io, name, 0); if (ioctl(fd, DM_DEV_REMOVE, io)) { ERROR("Error removing device mapping (%s)", strerror(errno)); return -1; } return 0; } static int get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name) static int get_verity_device_name(struct dm_ioctl *io, char *name, int fd, char **dev_name) { { verity_ioctl_init(io, name, 0); verity_ioctl_init(io, name, 0); Loading Loading @@ -606,6 +619,30 @@ out: return rc; return rc; } } static int read_partition(const char *path, uint64_t size) { char buf[READ_BUF_SIZE]; ssize_t size_read; android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))); if (fd == -1) { ERROR("Failed to open %s: %s\n", path, strerror(errno)); return -errno; } while (size) { size_read = TEMP_FAILURE_RETRY(read(fd, buf, READ_BUF_SIZE)); if (size_read == -1) { ERROR("Error in reading partition %s: %s\n", path, strerror(errno)); return -errno; } size -= size_read; } return 0; } static int compare_last_signature(struct fstab_rec *fstab, int *match) static int compare_last_signature(struct fstab_rec *fstab, int *match) { { char tag[METADATA_TAG_MAX_LENGTH + 1]; char tag[METADATA_TAG_MAX_LENGTH + 1]; Loading Loading @@ -904,6 +941,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; alignas(dm_ioctl) char buffer[DM_BUF_SIZE]; struct dm_ioctl *io = (struct dm_ioctl *) buffer; struct dm_ioctl *io = (struct dm_ioctl *) buffer; char *mount_point = basename(fstab->mount_point); char *mount_point = basename(fstab->mount_point); bool verified_at_boot = false; if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, FEC_DEFAULT_ROOTS) < 0) { FEC_DEFAULT_ROOTS) < 0) { Loading Loading @@ -1037,10 +1075,26 @@ loaded: // mark the underlying block device as read-only // mark the underlying block device as read-only fs_mgr_set_blk_ro(fstab->blk_device); fs_mgr_set_blk_ro(fstab->blk_device); // Verify the entire partition in one go // If there is an error, allow it to mount as a normal verity partition. if (fstab->fs_mgr_flags & MF_VERIFYATBOOT) { INFO("Verifying partition %s at boot\n", fstab->blk_device); int err = read_partition(verity_blk_name, verity.data_size); if (!err) { INFO("Verified verity partition %s at boot\n", fstab->blk_device); verified_at_boot = true; } } // assign the new verity block device as the block device // assign the new verity block device as the block device if (!verified_at_boot) { free(fstab->blk_device); free(fstab->blk_device); fstab->blk_device = verity_blk_name; fstab->blk_device = verity_blk_name; verity_blk_name = 0; verity_blk_name = 0; } else if (destroy_verity_device(io, mount_point, fd) < 0) { ERROR("Failed to remove verity device %s\n", mount_point); goto out; } // make sure we've set everything up properly // make sure we've set everything up properly if (test_access(fstab->blk_device) < 0) { if (test_access(fstab->blk_device) < 0) { Loading