fs_mgr:Add filter condition to make sure that the super block is correct.
Because full disk encryption make surper block is not except contents. Only judge the magic number can prevent most of encrypted surper block. In particular, magic number plaintext may be equal ciphertext. In order to avoid this situation, we add the judgment of adaptive situation of the s_rev_level, s_log_block_size and EXT4_INODE_SIZE. Test: 1. Config fstab,userdata add flags: forceencrypt=footer,reservedsize=128M 2. build a new target files, and flash all image. 3. Config encrypt userdata surperblock,set magic number is 0xEF53 4. reboot system and check log of fs_mgr. Change-Id: I925584d58f17afabbb3aa91f8be2302518172bb2 Signed-off-by: katao <katao@xiaomi.com>
This commit is contained in:
parent
e3d470b81d
commit
4e8d73fa0c
|
@ -249,6 +249,13 @@ static ext4_fsblk_t ext4_r_blocks_count(const struct ext4_super_block* es) {
|
|||
le32_to_cpu(es->s_r_blocks_count_lo);
|
||||
}
|
||||
|
||||
static bool is_ext4_superblock_valid(const struct ext4_super_block* es) {
|
||||
if (es->s_magic != EXT4_SUPER_MAGIC) return false;
|
||||
if (es->s_rev_level != EXT4_DYNAMIC_REV && es->s_rev_level != EXT4_GOOD_OLD_REV) return false;
|
||||
if (EXT4_INODES_PER_GROUP(es) == 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read the primary superblock from an ext4 filesystem. On failure return
|
||||
// false. If it's not an ext4 filesystem, also set FS_STAT_EXT4_INVALID_MAGIC.
|
||||
static bool read_ext4_superblock(const char* blk_device, struct ext4_super_block* sb, int* fs_stat) {
|
||||
|
@ -264,9 +271,8 @@ static bool read_ext4_superblock(const char* blk_device, struct ext4_super_block
|
|||
return false;
|
||||
}
|
||||
|
||||
if (sb->s_magic != EXT4_SUPER_MAGIC) {
|
||||
LINFO << "Invalid ext4 magic:0x" << std::hex << sb->s_magic << " "
|
||||
<< "on '" << blk_device << "'";
|
||||
if (!is_ext4_superblock_valid(sb)) {
|
||||
LINFO << "Invalid ext4 superblock on '" << blk_device << "'";
|
||||
// not a valid fs, tune2fs, fsck, and mount will all fail.
|
||||
*fs_stat |= FS_STAT_EXT4_INVALID_MAGIC;
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue