From 7e32611f0ed4ad8b786fe9530f16209511ef0ae0 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Sun, 20 Sep 2020 02:07:36 +0200 Subject: [PATCH] ANDROID: Fix mismerge of f2fs into android-4.14-q Change I83ba9fcf313ad7b08ed6d8f79411c72f9471523c on AOSP for kernel/common mismerged the patch `f2fs: use EINVAL for superblock with invalid magic` An error in validating the superblock checksum would return 1 but later be checked with IS_ERR(). To fix, correctly return -EFSCORRUPTED if the validation fails. Also move the check for header magic at the top, as it was intended. Change-Id: I3c048b299f87f74021dfe7ac382902fbff785611 Signed-off-by: Alessandro Astone --- fs/f2fs/super.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index b15432236739..03ec11746feb 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2430,6 +2430,13 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, size_t crc_offset = 0; __u32 crc = 0; + if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) { + f2fs_msg(sb, KERN_INFO, + "Magic Mismatch, valid(0x%x) - read(0x%x)", + F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); + return -EINVAL; + } + /* Check checksum_offset and crc in superblock */ if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) { crc_offset = le32_to_cpu(raw_super->checksum_offset); @@ -2438,23 +2445,16 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, f2fs_msg(sb, KERN_INFO, "Invalid SB checksum offset: %zu", crc_offset); - return 1; + return -EFSCORRUPTED; } crc = le32_to_cpu(raw_super->crc); if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { f2fs_msg(sb, KERN_INFO, "Invalid SB checksum value: %u", crc); - return 1; + return -EFSCORRUPTED; } } - if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) { - f2fs_msg(sb, KERN_INFO, - "Magic Mismatch, valid(0x%x) - read(0x%x)", - F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); - return -EINVAL; - } - /* Currently, support only 4KB page cache size */ if (F2FS_BLKSIZE != PAGE_SIZE) { f2fs_msg(sb, KERN_INFO, -- 2.20.1